This project is read-only.

Disable animation for zoom and pan

Aug 12, 2010 at 10:21 AM

How do I disable the animation in the map?

I need to set the initial bounds of the view in code when the map is loaded (I have done this already), but I want to avoid the animation.

Once the initial location of the map has been set, I would want to re-enable the animation.

Any ideas? Surely this has been done before, or does everyone always start with a view of the whole world?

Thanks

-Mark

Aug 12, 2010 at 3:31 PM
MyMap.Events.EnableKeyboard = false;
MyMap.Events.EnableMapZoom = false;
etc...
you can also goto the events class and add in code to stop "panning"
Aug 12, 2010 at 3:41 PM

Thanks for your reply. I have just realised that there is a lot of stuff on the non released source code (Like the functions you mentioned). Are you guys planning a release soon? Jan 2009 is quite far back!

I have just downloaded the latest source code to compile and use.

Anyway, I made a Helper class that does what I require with the Jan 2009 release version in the mean time. It also includes a method of setting the GeoBounds where the Zoom is not rounded off:

public class MapHelper
{
    private readonly Map _map;

    public MapHelper(Map map)
    {
        _map = map;
    }

    public bool UseAnimation
    {
        get
        {
            return MSI == null || MSI.UseSprings;
        }
        set
        {
            if (MSI != null) MSI.UseSprings = value;
        }
    }

    public void SetGeoBounds(Rect value)
    {
        if (MSI != null && _map.BaseLayer.Source != null)
        {
            Point pixelBoxOrigin = CoordHelper.GeoToPixel(new Point(value.Left, value.Top));
            Point pixelBoxExtent = CoordHelper.GeoToPixel(new Point(value.Right, value.Bottom));
            var pixelBox = new Rect(pixelBoxOrigin, pixelBoxExtent);
            SetPixelBounds(pixelBox);
        }
    }

    private MultiScaleImage MSI
    {
        get { return _map.BaseLayer.Children[0] as MultiScaleImage; }
    }

    private CoordTransform CoordHelper
    {
        get { return _map.CoordHelper; }
    }

    private Size MapViewPixelSize
    {
        get { return _map.MapViewPixelSize; }
    }

    private void SetPixelBounds(Rect pixelBox)
    {
        //Check to make sure this wasn't a simple click by checking the distance moved by mouse
        double area = pixelBox.Width * pixelBox.Height;

        if (area > 100)
        {
            var pixelCenter = new Point();
            pixelCenter.X = pixelBox.X + pixelBox.Width / 2;
            pixelCenter.Y = pixelBox.Y + pixelBox.Height / 2;

            //Get the minimum of the bounding box proprotions to the actual screen.
            double percWidth = pixelBox.Width / MapViewPixelSize.Width;
            double percHeight = pixelBox.Height / MapViewPixelSize.Height;
            double maxPerc = Math.Max(percWidth, percHeight);

            double targetWidth = MSI.ViewportWidth * maxPerc;
            double targetZoom = CoordHelper.LogicalViewToZoomLevel(new Size(targetWidth, targetWidth));

            //Try to round the zoom level and redo the size off the new value;
            //var roundZoom = (int)Math.Round(targetZoom, 0);
            var roundZoom = targetZoom;
            Size roundedView = CoordHelper.ZoomLevelToLogicalView(roundZoom);

            var logicalOrigin = new Point();
            Point logicalCenter = CoordHelper.PixelToLogical(pixelCenter);
            logicalOrigin.X = logicalCenter.X - (roundedView.Width / 2);
            logicalOrigin.Y = logicalCenter.Y - (roundedView.Height / 2);
            MSI.ViewportOrigin = logicalOrigin;
            MSI.ViewportWidth = roundedView.Width;
        }
    }

}

Hope this helps somebody.

-Mark

Aug 12, 2010 at 5:23 PM

Ok, I updated to the latest source code version (48968) and made all the necessary changes to my project.

The properties you mentioned on the Events class didn't disable the animations, but the method I had found previously (setting the BaseLayer.Msi.UseSprings ) was perfect, so I am still using my helper class.

Here is the updated helper class:

public class MapHelper
{
    private readonly Map _map;

    public MapHelper(Map map)
    {
        _map = map;
    }

    public bool UseAnimation
    {
        get
        {
            return _map.BaseLayer.Msi == null || _map.BaseLayer.Msi.UseSprings;
        }
        set
        {
            if (_map.BaseLayer.Msi != null) _map.BaseLayer.Msi.UseSprings = value;
        }
    }
        
}

It is pretty simple to use, just initialise the helper and then set the UseAnimation property.

This could just as easily be done with methods, but I think this looks cleaner. Also, it will be pretty easy to put back into the code base of Map like this :)

Aug 12, 2010 at 10:43 PM
sorry i was thinking you were wanting to stop the map panning