Please note:
This question is very similar to this one I found on stackoverflow.
Google Maps v3 ImageMapType Prevent Wrapping
However, the above question and answer did not work for my example / issue as I need to be able to view all of my image at any zoom level and more importantly i need the drawing tools to work correctly.
My Scenario:
I have a custom google map using ImageMapType, it also has the DrawingManager library and tools.
My issue:
At first glance all works nicely, however if you are to draw any markers or polygons and then pan the map the markers / polygons repeat or move across the area of map in view.
The same issue occurs when drawing large polygons on the map, as you are drawing the polygon, you will notice the line you are drawing will suddenly snap to the wrong side of your polygon.
My question:
How do I go about preventing the wrapping issues so that all of the markers do not move, or duplicate, and so that the drawing tools work without snapping to the other side of your polygon?
Online example:
http://jsbin.com/ecujug/5/edit#javascript,live
Video of the issues:
https://dl.dropbox.com/u/14037764/Development/stackoverflow/map-drawing/issue.html
Desired Effect:
Instead of
1-3zoom levels, you should work in higher levels and choose another origin than(0,0)tile for images. What you need, is just simple Maths.As by default your map will be centered toLatLng(0,0)point(as you have mentioned in yourMapOptions), the calculations will be performed around that point.Theory
At any zoom, there are totally
2^zoom x 2^zoomtiles:As
LatLng(0,0)is the central GPS point, the tile,which contains that point, should be the central tile of thetile-sheet:So at any
zoomlevel, the central tile has(2^(zoom-1), 2^(zoom-1))coordinates. That tile will be theoriginof the mappings.By subtracting origin coordinates from the current tile’s coordinates, we will have such acoordinate-spaceas when we were working in1-3zoom levels and when the origin was the(0,0)tile.Implementation
First of all, choose higher zoom levels,for example:
Mapping will be done by
getNormalizedCoordfunction:And finally, the
ImageMapOptionsshould be:Live demo