Approved
Last Updated: 05 Aug 2019 12:03 by ADMIN
Ken
Created on: 04 Aug 2019 22:01
Category: Map
Type: Bug Report
1
RadMap: Don't allow the Map to wrap around
Is there a way to not allow the map to WrapAround? 
1 comment
ADMIN
Dess | Tech Support Engineer, Sr.
Posted on: 05 Aug 2019 12:03
Hello, Ken, 

The wrap around feature allows infinite panning of the map. Currently, there is no API to restrict the pan operation in particular region. Setting the MapElement.Wraparound property to false should disable the wraparound functionality. However, you are still allowed to perform infinite panning. 

I have logged it in our feedback portal by making this thread public. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use the following custom MapInputBehavior

public RadForm1()
{
    InitializeComponent();
    string cacheFolder = @"..\..\cache";
    OpenStreetMapProvider osmProvider = new OpenStreetMapProvider();
    LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
    osmProvider.CacheProvider = cache;
    this.radMap1.MapElement.Providers.Add(osmProvider);
 
    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 = 0;
            }
            else if (x < -mapSize + this.MapElement.ViewportInPixels.Width)
            {
                x = -mapSize + this.MapElement.ViewportInPixels.Width;
            }
 
            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;
            }
 
            this.MapElement.PanOffset = new SizeL(x, y);
 
            this.lastMouseLocation = e.Location;
 
        }
    }
 
    public override void OnMouseUp(MouseEventArgs e)
    {
        base.OnMouseUp(e);
 
        this.lastMouseLocation = Point.Empty;
    }
}

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.