Calculating map scale

768
1
08-06-2020 07:24 AM
DerekVince
New Contributor

Hi all

I have a geometry (an Envelope) defined by 2 lat/lon points.  I'm having trouble wrapping my head around the concept of the camera scale (in 2D) needed to exactly encapsulate that envelope.  I know that if I zoom the current view to the envelope then I will get the scale I'm looking for.  However, this also changes the actual view in the scene.  I'm looking to determine the Scale in a way that does not affect the users view.

MapView view= MapView.Active;
await QueuedTask.Run(() =>
{
   // This works, but changes the user's view. Not good!
   view.ZoomTo(envelope);
   Debug.WriteLine("Scale: " + view.Camera.Scale);
});

Is there a way to manually calculate that scale value, or, to determine it somehow without affecting the view for the user?

Thanks

Tags (2)
0 Kudos
1 Reply
Amadeus111
Occasional Contributor II

It is an old post but maybe it would help someone. You might need to insert the last line in another QueuedTask

 

await QueuedTask.Run(() =>
{
   //1st get the current envelope, so you can go back to it later after calc
   Envelope currentExtent = MapView.Active.Extent;
   currentExtGeometry = currentExtent.Clone();
   
   // Get your scale for the envelope
   view.ZoomTo(envelope);
   Debug.WriteLine("Scale: " + view.Camera.Scale);
   
   //Goback to previous extent
   MapView.Active.ZoomTo(currentExtGeometry);
});

 

0 Kudos