Need to control zoom factor in ZoomInFixed and ZoomOutFixed. .NET C# WPF.

317
3
12-06-2019 07:20 AM
JonathanQuick
New Contributor

Zooming in and out programmatically in C# works very well but ZoomInFixed and ZoomOutFixed don't allow you to to zoom to an exact scale as you apparently can't change the zoom factor - is there a property hidden away somewhere to control this?

0 Kudos
3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can make an add-in with buttons for your own zoom functionality.  Here is the sample button code to step down the scale:

protected override void OnClick()
{
    // get the active mapview
    MapView activeMapView = MapView.Active;
    if (activeMapView == null) return;

    // note that MapView.ZoomIn must be called on the MCT
    QueuedTask.Run(() =>
    {
        // get the original camera position 
        var camera = activeMapView.Camera;
        // lower the scale 
        var scale = camera.Scale - 1.0;
        var sScale = $@"{scale:0}";
        sScale = sScale.Substring(0, 1).PadRight(sScale.Length).Replace(' ', '0');
        var nextLowerScale = double.Parse(sScale);
        camera.Scale = nextLowerScale;
        // zoom in
        activeMapView.ZoomTo(camera);
    });
}

Please note that working with scale(s) in only relevant in 2D maps.

0 Kudos
JonathanQuick
New Contributor

Have you succeeded in making this work? It was one of the first alternatives I tried and didn't work for me. My code looked pretty much like yours.

I guess the answer to my original question is that there is no way of setting the zoom factor for ZoomInFixed and ZoomOutFixed?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

i copied the code snippet above from a working sample, so yes it does work on 2D maps (scale is not relevant in 3D). i don't know any way to change the behavior of the built-in ZoomInFixed/ZoomOutFixed buttons.

0 Kudos