Template:Fragoria Map
From FragoriaWiki
(Difference between revisions)
Line 40: | Line 40: | ||
map.setMapTypeId('moon'); | map.setMapTypeId('moon'); | ||
- | + | // bounds of the desired area | |
- | + | var allowedBounds = new google.maps.LatLngBounds( | |
new google.maps.LatLng(-80, 90), | new google.maps.LatLng(-80, 90), | ||
- | new google.maps.LatLng(80, -300); | + | new google.maps.LatLng(80, -300) |
- | + | ); | |
- | + | 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() { | |
- | + | center = map.getCenter(); | |
- | + | if (allowedBounds.contains(center)) { | |
- | + | // still within valid bounds, so save the last valid position | |
- | + | lastValidCenter = map.getCenter(); | |
- | + | return; | |
- | + | } | |
- | + | newLat = lastValidCenter.lat(); | |
- | + | newLng = lastValidCenter.lng(); | |
- | + | if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){ | |
- | + | newLng = center.lng(); | |
- | + | } | |
- | map. | + | if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){ |
- | + | newLat = center.lat(); | |
- | + | } | |
- | + | map.panTo(new google.maps.LatLng(newLat, newLng)); | |
- | + | }); | |
- | + | ||
- | + | ||
var marker = new google.maps.Marker({ | var marker = new google.maps.Marker({ |
Revision as of 22:10, 3 April 2015