Select to view content in your preferred language

Convert scale to level of detail

919
3
Jump to solution
08-30-2019 08:47 AM
JonShuler
Emerging Contributor

We are working on an app where we persist the current viewport (x, y, scale) for the map.  When the app is restarted we were going to call SetViewpoint().  The problem we encountered is that you cannot call SetViewpoint() until the map has been loaded or will an exception will be thrown.

There is a constructor for the map class that allows you to set the initial viewpoint but it takes level of detail not scale:

public Map(BasemapType basemapType, double latitude, double longitude, int levelOfDetail);

Yes we can subscribe to the Load event on the MapView and not call SetViewpoint() until then but it would be easier if we could use the Map constructor that accept the initial viewpoint. We get the current viewpoint by call GetCurrentViewpoint() which has the scale but not the level of detail.

 

Is there a way to get the current level of detail or convert the scale to level of detail?

If Esri is reading this how about adding constructor  to map that also accepts scale.

0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor

...btw you should be able to call SetViewpoint prior to the mapview loading, but make sure you do it _after_ assigning the map to the mapview -Any pending set-viewpoint operations will be cleared if you replace the map. If that doesn't work for you, I'd like to see an example that reproduces this, so we can fix it.

Typically I'd recommend using the InitialViewpoint instead in those cases, as it'll skip loading things at full extent, and also give you slightly faster startup time (the map can start rendering layers sooner if it knows where to start rather than having to try and figure it out by waiting for all layers to load).

View solution in original post

3 Replies
dotMorten_esri
Esri Notable Contributor

The InitialViewpoint property is settable. So you can just set map.InitialViewpoint = myNewViewpoint - just make sure you do it prior to assigning the map to the mapview (or before the mapview loads).

The level of detail is nothing but a helper that tries to match a lot of the other mapping framework that only deal with LODs instead of scale. There are other overloads you could use. For example:

  var map = new Map(Basemap.CreateImagery()) { InitialViewpoint = new Viewpoint(mapCenter, scale) };

0 Kudos
dotMorten_esri
Esri Notable Contributor

...btw you should be able to call SetViewpoint prior to the mapview loading, but make sure you do it _after_ assigning the map to the mapview -Any pending set-viewpoint operations will be cleared if you replace the map. If that doesn't work for you, I'd like to see an example that reproduces this, so we can fix it.

Typically I'd recommend using the InitialViewpoint instead in those cases, as it'll skip loading things at full extent, and also give you slightly faster startup time (the map can start rendering layers sooner if it knows where to start rather than having to try and figure it out by waiting for all layers to load).

JonShuler
Emerging Contributor

Thanks, setting the InitialViewpoint worked. I misread the exception I was getting calling SetViewpoint(), it was because I forgot to set the spatial reference for the point.

0 Kudos