Set map rotation to orient north

111
5
a week ago
Highlighted
New Contributor

Hello,

I am using the most recent version of Runtime SDK and having a hard time understanding what the point of 

setViewpointRotation is if it does not orient north, at any coordinate. How do I achieve the desired result of orienting the map the way Google Maps does- always north? 

 

Thank you!

Reply
0 Kudos
5 Replies
Highlighted
Esri Regular Contributor

Hi @NaomiSchettini

The method allows you to specify any rotation (for example, if you are following a route, you may want the map to always point in the direction you are moving). If you want to reset it to north, just pass in 0.

However, if you want to prevent the user rotating the map at all, you can look at the interactionOptions property on AGSMapView. This is an AGSMapViewInteractionOptions object, and you can set the rotateEnabled property to false.

Hope this helps.

Reply
0 Kudos
Highlighted
New Contributor

I am using the rotateEnabled property and setViewpointRotation(0, completion: nil) and the result is a default offline map of San Francisco which requires downloading the entire world map. If I remove, setViewpointRotation(0, completion: nil), the downloading of the entire world map disappears but then rotateEnabled = false does not seem to work. I am not sure if it's timing sensitive or something, but I just need to tackle the two issues: not downloading the entire world map but also facing north by default. Do you have suggestions

IMG_0622.PNG

Reply
0 Kudos
Highlighted
Esri Regular Contributor

I am using the rotateEnabled property and setViewpointRotation(0, completion: nil) and the result is a default offline map of San Francisco which requires downloading the entire world map.

Can you provide more context please? Is this an application you have built from scratch or is it based off a sample or example app?

I am not sure what the screenshot is that you provided (it doesn't look like San Francisco).

Reply
0 Kudos
Highlighted
New Contributor

It's an app I did not build from scratch. It just uses the ArcGIS Runtime SDK.

This is the code for generating the map where I think it sets the default offline map to SF East Bay (Alameda, etc):

 

 let portal = AGSPortal.arcGISOnline(withLoginRequired: false)
        portal.credential = Configuration.shared.ArcGISServiceUserCredentials
        // portal item for web map
        let portalItem = AGSPortalItem(portal: portal, itemID: Configuration.shared.ArcGISPortalItemId)
        viewModel = ECOCreateProjectAreaViewModel(projectUID: projectUID)
        self.portalItem = portalItem
        let map = AGSMap(item: portalItem)
        map.basemap = .imageryWithLabels()​

 



I just tested this again and confirm that it is this specific line which causes the Alameda map to show and when "Download Area" is tapped, an entire world map is downloaded: ```  mapView.setViewpointRotation(0, completion: nil) ```

The reason this occurs, I presume is because the default basemap (the Alameda map) does not have an existing mapScale so it is defaulting to 200000.0 which is why the whole world map gets downloaded. Let me know if this information is sufficient to understand my problem. The portal id is: 0e2e4f11d4ce4c14a9f93d37dc089e92

 

 

 

Reply
0 Kudos
Highlighted
Esri Regular Contributor

I'm afraid that doesn't really give us anything to work with.

The code you provide is accessing a web map, and changing the basemap to be the standard Imagery With Labels basemap.

setViewpointRotation() will only affect the AGSMapView rotation and will not change the scale.

When you take a map offline, you use an AGSOfflineMapTask. From that you create default parameters for a geographic area you want to take offline. You then create an AGSGenerateOfflineMapJob and start it. You should check the code that's setting the parameters to see what, if anything, is happening to the geometry that's being passed in. If you're getting the whole world downloaded, it could be that the geometry isn't being set, so is there some way that setting the viewpoint rotation to 0 is clearing out some geometry property that is being used to track what to download?

Reply
0 Kudos