Prevent horizontal world-wrapping of overlays in GMap v3

一曲冷凌霜 提交于 2019-12-21 17:38:31

问题


I'm trying to make a map that doesn't wrap horizontally, using the Google Maps API V3. So instead repeating the map side-by-side again and again, I want to show it only once. I got that to work by providing a custom getTileUrl function for google.maps.ImageMapType

But when I add overlays (like markers or polygons), those still are repeated horizontally. How can I stop the overlays from being repeated horizontally?

Edit Here's an image demonstrating the problem:

I was thinking of somehow modifying the google.maps.Projection.fromLatLngToPoint() method, but for some reason that doesn't seem to be available most of the time.


回答1:


By now I have figured out a way to do it. The solution did not lie with a modified projection, but instead was inspired by this question about limiting panning in Google Maps.

It's not really as clean as I'd like, but it works:

  1. Instead of starting out (showing the complete map as one map tile) at zoom level 0, start out at a higher zoom level. In my case, I started out at level 3. This way, the "imaginary" whole world is bigger, moving the repeating overlays farther apart:

  2. Limit the zoom level, so even own the lowest zoom level, the viewport doesn't contain two of the repeating overlays. This is done by setting the minZoom option on the map to the desired level.

  3. Limit panning/dragging the map, so you can't move out of the desired area. See my answer on the limit panning question.

This way, the repeating overlays are still there, but you will never be able to see them, since you can't reach them



来源:https://stackoverflow.com/questions/7718664/prevent-horizontal-world-wrapping-of-overlays-in-gmap-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!