This is a migrated thread and some comments may be shown as answers.

What does RadMap.MapElement.Wraparound do?

1 Answer 91 Views
Map
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 19 Dec 2017, 11:48 PM

Hello,

I've just started working with RadMap and am trying to figure out what Wraparound does.  My goal is to show a graphic in the tile layer and when the user pans all the way to the left side of the graphic, I'd like the pan to stop.  Same goes for the right hand side of the graphic.  All of your samples seem to wrap around.  For example, with Bing maps, I'm centered on Europe -> hold down the pan left button, the map goes all the way around the world and pans to Europe again (and again...).  What I'd like to have happen is that the user can pan no further left than Europe, and no further right than say, the Atlantic Ocean.  I'm not tied to the BingMapProvider, and am ultimately going to write my own IMapProvider.

Additionally, when I set the Wraparound property in the designer, it doesn't persist.

Thank you.

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 20 Dec 2017, 03:15 PM
Hello Bob,

Thank you for writing.

The wrap around feature allows infinite panning of the map. Currently, there is no API to restrict the pan operation in particular region. The mouse behavior is handled by a special input class which you can substitute with your own. Then you can override the MouseMove method and restrict the pan to a certain area: 
this.radMap1.InputBehavior = new MyMapInputBehavior();

public class MyMapInputBehavior : MapInputBehavior
{
    Point lastMouseLocation = Point.Empty;
 
    public override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        this.lastMouseLocation = e.Location;
    }
 
    public override void OnMouseMove(MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left && this.lastMouseLocation != Point.Empty && !this.MapElement.IsAnimationActive)
        {
            var panOffset = new SizeL(this.MapElement.PanOffset.Width + (e.X - this.lastMouseLocation.X), this.MapElement.PanOffset.Height + (e.Y - this.lastMouseLocation.Y));
            long mapSize = MapTileSystemHelper.MapSize(this.MapElement.ZoomLevel);
            long x = panOffset.Width;
            long y = panOffset.Height;
 
            if (x > 0)
            {
                x = -mapSize + x;
            }
            else if (x < -mapSize)
            {
                x %= mapSize;
            }
 
            if (mapSize < this.MapElement.ViewportInPixels.Height)
            {
                y = (this.MapElement.ViewportInPixels.Height - mapSize) / 2;
            }
            else if (y > 0)
            {
                y = 0;
            }
            else if (y < this.MapElement.ViewportInPixels.Height - mapSize)
            {
                y = this.MapElement.ViewportInPixels.Height - mapSize;
            }
 
            var viewportInPixels = new RectangleL(new PointL(-x, -y), this.MapElement.ViewportInPixels.Size);
            var centerPixel = new PointL(this.MapElement.ViewportInPixels.X + this.MapElement.ViewportInPixels.Width / 2L, this.MapElement.ViewportInPixels.Y + this.MapElement.ViewportInPixels.Height / 2L);
            var center = MapTileSystemHelper.PixelXYToLatLong(this.MapElement.CenterPixel, this.MapElement.ZoomLevel);
            PointG topLeft = MapTileSystemHelper.PixelXYToLatLong(-x, -y, this.MapElement.ZoomLevel);
            PointG bottomRight = MapTileSystemHelper.PixelXYToLatLong(this.MapElement.ViewportInPixels.Right, this.MapElement.ViewportInPixels.Bottom, this.MapElement.ZoomLevel);
            if ((topLeft.Longitude < -10 || bottomRight.Longitude > 30) ||
                topLeft.Latitude > 70 || bottomRight.Latitude < 30)
            {
                this.MapElement.ViewportInPixels = new RectangleL(-x, -y, this.MapElement.ViewportInPixels.Width - 1, this.MapElement.ViewportInPixels.Height - 1);
                this.MapElement.Invalidate();
                return;
            }
 
            this.lastMouseLocation = e.Location;
        }
 
 
        base.OnMouseMove(e);
    }
}

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Map
Asked by
Bob
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or