4

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: World-wrapping overlays

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.

HenningJ
  • 3,099
  • 1
  • 20
  • 17

1 Answers1

2

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: great distance between repeating overlays

  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. viewport does not contain two repeating overlays

  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

Community
  • 1
  • 1
HenningJ
  • 3,099
  • 1
  • 20
  • 17
  • Need the same task: limit map to show only single instance. removing repating of map. Have some questions: 1. Do we really need 3. option if we have min zoom? To which bounds to limit to show only whole world but no more repeat? 2. How you select min zoom for map? For my site I need map occupy all remaining from other controls space. So min zoom will vary depending on monitor screen resolution. Or at least on canvas size. – Yauhen.F Nov 01 '11 at 11:24
  • 1. If you don't limit panning, you can still pan until you reach the repeating markers. While most people wont pan around in the nothingness, so normally it wouldn't be a problem. But I still wanted to stop it from ever occurring. 2. I just tried in on the biggest screen I had and decided that was good enough. In the end I think I went with minzoom 5. – HenningJ Nov 01 '11 at 13:57
  • 1. For me it seem like a normal case. Because users could set center to the 180 longitude. And will see north America on right of it and australia on left. In your case as you limit this is not possible? Or what you use for limit (which boundaries)? 2. But in this case on law resolutions will be less then full map. User will not be able to see full map. – Yauhen.F Nov 01 '11 at 14:24
  • 1. All of this is not really applicable in a scenario where you use the default world map. It only makes sense if you have a rectangular map that doesn't repeat. Like the image in the question. 2. You're right. For me it wasn't a problem, so I don't know how you could do that automatically. Sorry. – HenningJ Nov 01 '11 at 15:01
  • @HenningJ can you elaborate on part 1 of your solution? Does this involve simply loading up alternate tiles at any given zoom level? For example, loading zoom level 0 tiles when you are at zoom level 3? I would REALLY like to see how this is done in action. I tried loading lower zoom level tiles (like level 0 tiles as level 3) but it loads the tiles starting in the upper left corner. Not sure how to center it... If you could put up a JSFiddle example of this it would be appreciated. – Jake Wilson Nov 05 '12 at 18:40
  • I'm sorry, I can't elaborate. I don't have the code anymore and I don't remember much about it. But I think it was just loading level 0 tiles at level 3. I don't know why this could be a problem and what you mean by centering...could you elaborate? – HenningJ Nov 07 '12 at 18:17
  • This is really wild because I've got the opposite issue. I have only a single instance of a large image ( basically covering -180 to +180 longitudinally ) and it does not tile. – carl crott Jul 02 '13 at 15:28