Template:Fragoria Map

From FragoriaWiki

(Difference between revisions)
Jump to: navigation, search
Line 40: Line 40:
map.setMapTypeId('moon');
map.setMapTypeId('moon');
-
// Add a move listener to restrict the bounds range
+
// bounds of the desired area
-
GEvent.addListener(map, "move", function() {
+
var allowedBounds = new google.maps.LatLngBounds(
-
checkBounds();
+
new google.maps.LatLng(-50, 80),
-
});
+
new google.maps.LatLng(50, -80)
 +
);
 +
var lastValidCenter = map.getCenter();
-
// The allowed region which the whole map must be within
+
google.maps.event.addListener(map, 'center_changed', function() {
-
var allowedBounds = new GLatLngBounds(new GLatLng(-50,80), new GLatLng(50,-80));
+
    if (allowedBounds.contains(map.getCenter())) {
-
     
+
         // still within valid bounds, so save the last valid position
-
// If the map position is out of range, move it back
+
         lastValidCenter = map.getCenter();
-
function checkBounds() {
+
         return;  
-
// Perform the check and return if OK
+
    }
-
if (allowedBounds.contains(map.getCenter())) {
+
-
return;
+
-
}
+
-
         // It`s not OK, so find the nearest allowed point and move there
+
-
         var C = map.getCenter();
+
-
         var X = C.lng();
+
-
        var Y = C.lat();
+
-
        var AmaxX = allowedBounds.getNorthEast().lng();
+
    // not valid anymore => return to last valid position
-
        var AmaxY = allowedBounds.getNorthEast().lat();
+
    map.panTo(lastValidCenter);
-
        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));
+
-
}
+
var marker = new google.maps.Marker({
var marker = new google.maps.Marker({

Revision as of 21:50, 3 April 2015

Fragoria Map

Personal tools
Date/Time
Server & Cross

Super-Cross Server