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
+
// Add a move listener to restrict the bounds range
-
var allowedBounds = new google.maps.LatLngBounds(
+
GEvent.addListener(map, "move", function() {
-
new google.maps.LatLng(-50, 80),  
+
checkBounds();
-
new google.maps.LatLng(50, -80)
+
});
-
);
+
-
var boundLimits = {
+
-
maxLat : allowedBounds.getNorthEast().lat(),
+
-
maxLng : allowedBounds.getNorthEast().lng(),
+
-
minLat : allowedBounds.getSouthWest().lat(),
+
-
minLng : allowedBounds.getSouthWest().lng()
+
-
};
+
-
var lastValidCenter = map.getCenter();
+
// The allowed region which the whole map must be within
-
var newLat, newLng;
+
var allowedBounds = new GLatLngBounds(new GLatLng(-50,80), new GLatLng(50,-80));
-
google.maps.event.addListener(map, 'center_changed', function() {
+
     
-
center = map.getCenter();
+
// If the map position is out of range, move it back
-
if (allowedBounds.contains(center)) {
+
function checkBounds() {
-
// still within valid bounds, so save the last valid position
+
// Perform the check and return if OK
-
lastValidCenter = map.getCenter();
+
if (allowedBounds.contains(map.getCenter())) {
-
return;
+
return;
-
}
+
-
newLat = lastValidCenter.lat();
+
-
newLng = lastValidCenter.lng();
+
-
if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){
+
-
newLng = center.lng();
+
}
}
-
if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){
+
        // It`s not OK, so find the nearest allowed point and move there
-
newLat = center.lat();
+
        var C = map.getCenter();
 +
        var X = C.lng();
 +
        var Y = C.lat();
 +
 
 +
        var AmaxX = allowedBounds.getNorthEast().lng();
 +
        var AmaxY = allowedBounds.getNorthEast().lat();
 +
        var AminX = allowedBounds.getSouthWest().lng();
 +
        var AminY = allowedBounds.getSouthWest().lat();
 +
 
 +
        if (X < AminX) {X = AminX;}
 +
        if (X > AmaxX) {X = AmaxX;}
 +
        if (Y < AminY) {Y = AminY;}
 +
        if (Y > AmaxY) {Y = AmaxY;}
 +
        //alert ("Restricting "+Y+" "+X);
 +
        map.setCenter(new GLatLng(Y,X));
}
}
-
map.panTo(new google.maps.LatLng(newLat, newLng));
 
-
});
 
var marker = new google.maps.Marker({
var marker = new google.maps.Marker({

Revision as of 21:43, 3 April 2015

Fragoria Map

Personal tools
Date/Time
Server & Cross

Super-Cross Server