Select to view content in your preferred language

What's the easiest way to put zoom in and zoom out buttons on my map

1882
3
Jump to solution
07-01-2021 01:12 PM
rodsan724
Occasional Contributor

Given:  

Visual Studio 2019 Pro  

ArcGIS Tutorial - Display a map

 

What's the easiest way to put zoom in and zoom out buttons on the map? I know you can use a scroll wheel but I need the zoom buttons to show as well.

 

0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor

I'm assuming you're using XAML, so add two <Button /> controls to your view, and in their click handlers, call one of the SetViewpoint* operations. For example:

mapView.SetViewpointScaleAsync(mapView.MapScale / 2); // Zoom in
mapView.SetViewpointScaleAsync(mapView.MapScale * 2); // Zoom out

View solution in original post

3 Replies
dotMorten_esri
Esri Notable Contributor

I'm assuming you're using XAML, so add two <Button /> controls to your view, and in their click handlers, call one of the SetViewpoint* operations. For example:

mapView.SetViewpointScaleAsync(mapView.MapScale / 2); // Zoom in
mapView.SetViewpointScaleAsync(mapView.MapScale * 2); // Zoom out

RonakPatel2
Emerging Contributor

This works for me!

await mapView.SetViewpointScaleAsync(mapView.GetCurrentViewpoint(ViewpointType.CenterAndScale).TargetScale / 2);  // Zoom In

await mapView.SetViewpointScaleAsync(mapView.GetCurrentViewpoint(ViewpointType.CenterAndScale).TargetScale * 2); // Zoom Out

0 Kudos
dotMorten_esri
Esri Notable Contributor

@RonakPatel That code is equivalent to what I wrote above, but it's a more round-about way requiring a lot more calls.

0 Kudos