Swift IOS - Camera focus view

332
9
2 weeks ago
Labels (1)
JyoshnaRani
New Contributor II

Camera focused using map extent (4 co ordinates min – max X and min – max Y).

My Code:

self.map.maxExtent = Envelope(xMin: self.xMin!, yMin: self.yMin!, xMax: self.xMax!, yMax: self.yMax!, spatialReference: .wgs84)

self.map.initialViewpoint = Viewpoint(boundingGeometry: self.map.maxExtent!.center, camera: Camera(lookingAt: self.map.maxExtent!.center, distance: 5500, heading: 150, pitch: 20, roll: 0))

 

But its not working.  That means Camera is not focusing on view map.

 

0 Kudos
9 Replies
Ting
by Esri Contributor
Esri Contributor

See this sample https://github.com/Esri/arcgis-runtime-samples-ios/blob/main/arcgis-ios-sdk-samples/Maps/Set%20initi...

Let me know if it helps or you have more questions.

0 Kudos
JyoshnaRani
New Contributor II

Hello Ting,

Thank you for your answer. But I'm looking for swift UI View.

Like : 

struct GisMapView: View {
var map = Map(basemapStyle: .arcGISTopographic)

func loadMap(){
self.map.maxExtent = Envelope(xMin: self.xMin!, yMin: self.yMin!, xMax: self.xMax!, yMax: self.yMax!, spatialReference: .wgs84)
self.map.initialViewpoint = Viewpoint(boundingGeometry: self.map.maxExtent!.center, camera: Camera(lookingAt: self.map.maxExtent!.center, distance: 5500, heading: 150, pitch: 20, roll: 0))
}

var body: some View {
MapView(map: map)
}
}

 This is the code I wrote but it's not reflecting on map. Map is loading but not in particular camera location.

Hope this way I explained my query. 

0 Kudos
Ting
by Esri Contributor
Esri Contributor

There are multiple issues with your snippet

  1. Please note the difference between a Map and a Scene in ArcGIS context. In other mapping frameworks, they may call a Scene something like "3D map" or "Globe mode", etc. In ArcGIS, 3D mapping is specifically represented as a scene. Therefore, in order to set a camera angle, you'll need a 3D scene so it allows the 3D perspectives.
  2. Currently we only support "global scenes" in the Swift API, while local scene is under development. See this article for the difference between these two. In short, global is a globe, local is a plane.
  3. It is a common mistake to pass in out of range values to a certain spatial reference. For example, WGS 84 allows -89 ~ +89 latitude, -180 ~ +180 longitude. If the values to create an Envelope is greater than those ranges, the geometry would be invalid. I'm assuming you understand the difference there.
  4. For a 3D scene, setting the camera will override the bounding geometry. That is, no matter what bounding geometry you pass in for a 3D scene, if there is a camera, it will use the camera first.
  5. Please note the importance of using State property wrapper in SwiftUI. By marking a geomodel as a state, it retains the source-of-truth-ness of it. Read this article to get a better understanding.

 

With all these said, check out this sample to get an idea: https://github.com/Esri/arcgis-maps-sdk-swift-samples/blob/main/Shared/Samples/Display%20scene/Displ... 

 

Let me know if you have more questions.

0 Kudos
JyoshnaRani
New Contributor II

Hello Ting,

In my previous reply I tried to tell that - I am using 'View' in swift SDK for ArcGIS. That is just a sample code where I can show you - I am not using "UIViewController " as you provided in a solution - "See this sample https://github.com/Esri/arcgis-runtime-samples-ios/blob/main/arcgis-ios-sdk-samples/Maps/Set%20initi..."  

 

So I am looking a class example of ArcGIS which is extended with View not  UIViewController, and I am using ArcGIS SDK for Swift not ArcGIS SDK for IOS.

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Maybe you missed the latest reply. Did you see the one above your post?

I moved your thread to the right sub forum.

0 Kudos
JyoshnaRani
New Contributor II

Hello Ting,

Can you share the details - "I moved your thread to the right sub forum."

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Sure. When posting on Esri Community, we have Runtime SDK for iOS Questions and Swift Maps SDK Questions sub forums.

The former is for the 100.x version ArcGIS Runtime API for iOS, which is for UIKit + Swift/ObjC development and currently in long term support (retired), while 200.x ArcGIS Maps SDK for Swift is for SwiftUI + Swift development.

When you first posted this question, it was moved by an Esri colleague to the iOS sub forum, so I moved this thread to the Swift sub forum as you are asking about SwiftUI.

JyoshnaRani
New Contributor II

Thank you @Ting for this clarity.

Hoping to hear from SwiftUI + Swift development team soon.

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Just want to double check that you've seen my reply at https://community.esri.com/t5/swift-maps-sdk-questions/swift-ios-camera-focus-view/m-p/1419487/highl... Let me know if you have more questions.

0 Kudos