Prevent global packaging in GMap v3

Now I am moving from v2 to v3. The world should not be repeated in the longitudinal direction.

In v2, this can be archived with something like this:

var proj = new GMercatorProjection(30); 
proj.tileCheckRange = function(a,b,c) { 
  var tileBounds = Math.pow(2,b);
  if (a.y<0 || a.y >= tileBounds) {return false;}
  if (a.x<0 || a.x >= tileBounds) {return false;}
  return true; 
};

proj.getWrapWidth = function(zoom) {
  return 99999999999999;
};

G_NORMAL_MAP.getProjection = function() {return proj;};

But I still have to find a solution for v3.

EDIT To clarify a bit: I'm not looking for a way to prevent panning (moving sideways), but a way to prevent the map from repeating ourselves, especially. at low zoom levels

+5
source share
2 answers

Check out two answers to How to restrict panning in the Google V3 Map APIs? . The technique outlined there should help you (depending on your use case) most of the way there, or possibly to the end.

, , , . , , (, ), .

+2

( , Trott)

// prevent wrap                                                                                                                                                                                                                                                     
  var lastValid = map.getCenter();
  google.maps.event.addListener(map, 'center_changed', function() {
    if(map.getBounds().getNorthEast().lng() > map.getBounds().getSouthWest().lng()) {
      lastValid = map.getCenter();
    }
    else
      map.panTo(lastValid);
  });
-1

All Articles