Template:Fragoria Map

From FragoriaWiki

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

Fragoria Map

Personal tools
Date/Time
Server & Cross

Super-Cross Server