Select to view content in your preferred language

Programmatically activate zoombox

1210
5
11-23-2016 08:46 AM
HuyHo
by
Frequent Contributor

In 10.2.x, you can activate the zoombox by holding down the SHIFT key while dragging your mouse.  This requires a two hand operation so it's a bit tricky when you try to operate a device (without multi-touch) inside a vehicle.  Is there a way to programmatically enable/disable this dragging zoom box mode?

0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor

You can enable/disable zoom (including zoom box) using MyMapView.InteractionOptions = new MapViewInteractionOptions() { IsZoomEnabled = false }. If you want to programmatically zoom to a location, you can use MyMapView.SetViewpointCenterAsync(center, scale).

0 Kudos
HuyHo
by
Frequent Contributor

Thanks Jennifer.  What we are looking for is to enable the zoom box mode (so that the user do not have to hold down the shift key)..  For example, we'lll have a button on the toolbar, the click this button to enable the mode, then the would use the mouse to draw the box to zoom in, then after the map finishes zooming, we disable the mode.  What we are looking for is a way to draw a box to zoom, but doing it with the mouse only -- imagine if you only have one hand.  Hope that clears up what we are trying to do.

0 Kudos
JenniferNery
Esri Regular Contributor

I see you can use SketchEditor to draw the zoom box and use the resulting geometry's extent to zoom into its center. When you draw the shape, it would be mouse down and drag to desired size, when you let go you will get a polygon of rectangle shape.

For example on a button click:

var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false); // Boolean indicates it will complete when geometry is drawn and no need to go to edit mode.

await MyMapView.SetViewpointCenterAsync(geometry.Extent.GetCenter(), MyMapView.MapScale/2); // or whatever zoom factor you choose.

0 Kudos
JenniferNery
Esri Regular Contributor

Actually you can also use extent height and width to calculate zoom factor.

var currentMapExtent = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry.Extent;

var zoomFactor = Math.Min(currentMapExtent.Width/geometry.Extent.Width, currentMapExtent.Height/geometry.Extent.Height);

await MyMapView.SetViewpointCenterAsync(geometry.Extent.GetCenter(), MyMapView.MapScale/zoomFactor);

0 Kudos
HuyHo
by
Frequent Contributor

Thanks Jennifer.  I thought of having to do something like that, but I was hoping there was some other way so that we do not need to re-invent the wheel.

0 Kudos