MapViewAutomationPeer zoom based on rectangle size?

1023
6
11-28-2019 07:52 PM
PrashantKirpan
Occasional Contributor

Hi All,

I am trying to build basic navigation control on map.On button click I want to draw rectangle and perform zoom in/out operation.

I found MapViewAutomationPeer clss to control map zoom but it doesn't work as expected. 

ZoomInAnimated/ZoomOutAnimated only zoom to center point. No option for scale.

What is the best approach to zoom using rectangle size? i.e. if the rectangle is bigger than zoom to less scale else on higher side.

I am using WPF 100.6

Any help would be appreciated.

Regards,

Prashant 

0 Kudos
6 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

Using the Shift key in conjunction with the mouse provides the ability to draw a box and zoom in. To zoom out, use the Shift+Control keys and the mouse.

Regards

Mike

0 Kudos
PrashantKirpan
Occasional Contributor

Thanks Michael for reply,

I am migrating my app esri runtime 10.7 to 100.6 and would like to keep consistent behavior. Application is mainly used for data capturing and hosted on windows motion tablet so I am looking for both options. 

Out of the box navigation is working fine but just wanted to know is it not possible to zoom in/out using mouse + drawing rectangle without shift key? 

Regards,

Prashant Kirpan

0 Kudos
dotMorten_esri
Esri Notable Contributor

If you want to use based on a rectangle, convert the rectangle to an Envelope in map units ( MapView.LocationToScreen(...) ), and use the SetViewpointGeometryAsync(Envelope).

You could also use the sketch editor to draw that rectangle, and then just pass it straight to the setviewpoint method

0 Kudos
PrashantKirpan
Occasional Contributor

Hi Morten,

Yes, this is working in case of zoom-In but how to implement zoom-Out?

I tried to below code for zoom out but not sure how to determine zoom level i.e. for small rectangle zoom out to lowest zoom level. 

Geometry geometry = await MpView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);


var point = MpView.LocationToScreen(geometry.Extent.GetCenter());
Esri.ArcGISRuntime.UI.Controls.MapViewAutomationPeer peer = Esri.ArcGISRuntime.UI.Controls.MapViewAutomationPeer.FromElement(MpView) as Esri.ArcGISRuntime.UI.Controls.MapViewAutomationPeer;
peer.ZoomOutAnimated(point);

Working zoom in code as you suggested:

  Geometry geometry = await MpView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);

   await MpView.SetViewpointGeometryAsync(geometry.Extent);

Regards,

Prashant 

0 Kudos
dotMorten_esri
Esri Notable Contributor

For zoom-out you'd have to calculate the 'opposite' rectangle, which granted isn't straight-forward. Typically you'd expand around a location inside the rectangle by a certain amount relative to the size of the rectangle (a smaller rectangle would typically mean zoom out more). It's a bit of math, but not horrible, so play with a few values and see what works for you. The simplest would be just to take the current map-scale, and multiple it by the relative width between the view size and the rectangle size, and then zoom to that.

0 Kudos
PrashantKirpan
Occasional Contributor

Hi Morten,

I tried to calculate values to zoom out rectangle but not working as expected. Is it possible for you to provide any sample formula for below solution.

The simplest would be just to take the current map-scale, and multiple it by the relative width between the view size and the rectangle size, and then zoom to that.

Any help would be appreciated,

Regards,

Prashant

0 Kudos