Template:Fragoria Map
From FragoriaWiki
(Difference between revisions)
| Line 45: | Line 45: | ||
new google.maps.LatLng(50, -80) | new google.maps.LatLng(50, -80) | ||
); | ); | ||
| - | var | + | var boundLimits = { |
| + | maxLat : allowedBounds.getNorthEast().lat(), | ||
| + | maxLng : allowedBounds.getNorthEast().lng(), | ||
| + | minLat : allowedBounds.getSouthWest().lat(), | ||
| + | minLng : allowedBounds.getSouthWest().lng() | ||
| + | }; | ||
| + | var lastValidCenter = map.getCenter(); | ||
| + | var newLat, newLng; | ||
google.maps.event.addListener(map, 'center_changed', function() { | google.maps.event.addListener(map, 'center_changed', function() { | ||
| - | if (allowedBounds.contains( | + | center = map.getCenter(); |
| - | // still within valid bounds, so save the last valid position | + | if (allowedBounds.contains(center)) { |
| + | // still within valid bounds, so save the last valid position | ||
lastValidCenter = map.getCenter(); | lastValidCenter = map.getCenter(); | ||
| - | return; | + | return; |
} | } | ||
| - | + | newLat = lastValidCenter.lat(); | |
| - | map.panTo( | + | newLng = lastValidCenter.lng(); |
| + | if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){ | ||
| + | newLng = center.lng(); | ||
| + | } | ||
| + | if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){ | ||
| + | newLat = center.lat(); | ||
| + | } | ||
| + | map.panTo(new google.maps.LatLng(newLat, newLng)); | ||
}); | }); | ||
Revision as of 21:23, 3 April 2015

