This project has moved. For the latest updates, please go here.

Restrict to one world only

Apr 1, 2014 at 9:21 AM
Hi,

I really like your control, nicely done and clear coding. However, I was wondering if it is possible, like with Bing Maps, to restrict the view to one world only (stop the world from repeating indefinitely).
If the control does not support this functionality, would you be able to point me to the area of the code that could be modified to that purpose, please?

Thanks and keep up the good work :)

Cécile.
Coordinator
Apr 1, 2014 at 10:16 AM
The control is actually designed to always extend the map across the W/E 180° boundary. If it wouldn't do that, it could only show either the left or right edge of the "single" world near that boundary, even if you zoomed in. You may play around and experience this strange behaviour, if you just add the following two lines of code in TileLayer.cs, line 129:
var tileSize = 1 << (zoomLevel - z);
var x1 = (int)Math.Floor((double)grid.X / tileSize); // may be negative
var x2 = (grid.X + grid.Width - 1) / tileSize;
var y1 = Math.Max(grid.Y / tileSize, 0);
var y2 = Math.Min((grid.Y + grid.Height - 1) / tileSize, (1 << z) - 1);

// add these two lines
x1 = Math.Max(x1, 0);
x2 = Math.Min(x2, (1 << z) - 1);

for (var y = y1; y <= y2; y++)
...
In order to avoid the visual effect of repeated worlds, I'd recommend to restrict the minimum zoom level to some sensible value, like 2 or 3.
Marked as answer by PtiteSerra on 4/1/2014 at 5:57 AM
Apr 1, 2014 at 12:56 PM
Thank you for your quick answer. I will have a play with this, but I can already see that the control is not quite meant to support this behaviour as panning would also need to be limited to that one world. I guess I will end up playing with the Min Zoom Level as you suggested.