Template:Fragoria Map

From FragoriaWiki

(Difference between revisions)
Jump to: navigation, search
Line 40: Line 40:
map.setMapTypeId('moon');
map.setMapTypeId('moon');
-
// Bounds
+
// bounds of the desired area
-
var allowedBounds = new google.maps.LatLngBounds(
+
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)
-
// Listen for the dragend event
+
);
-
google.maps.event.addListener(map, 'dragend', function() {
+
var boundLimits = {
-
if (allowedBounds.contains(map.getCenter())) return;
+
maxLat : allowedBounds.getNorthEast().lat(),
 +
maxLng : allowedBounds.getNorthEast().lng(),
 +
minLat : allowedBounds.getSouthWest().lat(),
 +
minLng : allowedBounds.getSouthWest().lng()
 +
};
-
// Out of bounds - Move the map back within the bounds
+
var lastValidCenter = map.getCenter();
-
var c = map.getCenter(),
+
var newLat, newLng;
-
x = c.lng(),
+
google.maps.event.addListener(map, 'center_changed', function() {
-
y = c.lat(),
+
center = map.getCenter();
-
maxX = allowedBounds.getNorthEast().lng(),
+
if (allowedBounds.contains(center)) {
-
maxY = allowedBounds.getNorthEast().lat(),
+
// still within valid bounds, so save the last valid position
-
minX = allowedBounds.getSouthWest().lng(),
+
lastValidCenter = map.getCenter();
-
minY = allowedBounds.getSouthWest().lat();
+
return;
-
 
+
}
-
if (x < minX) x = minX;
+
newLat = lastValidCenter.lat();
-
if (x > maxX) x = maxX;
+
newLng = lastValidCenter.lng();
-
if (y < minY) y = minY;
+
if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){
-
if (y > maxY) y = maxY;
+
newLng = center.lng();
-
 
+
}
-
map.setCenter(new google.maps.LatLng(y, x));
+
if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){
-
});
+
newLat = center.lat();
-
+
}
-
// Limit the zoom level
+
map.panTo(new google.maps.LatLng(newLat, newLng));
-
google.maps.event.addListener(map, 'zoom_changed', function() {
+
});
-
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
+
-
});
+
var marker = new google.maps.Marker({
var marker = new google.maps.Marker({

Revision as of 22:10, 3 April 2015

Fragoria Map

Personal tools
Date/Time
Server & Cross

Super-Cross Server