See the nested function down at the bottom called checkbounds? Well, it's not getting the objects I'm sending it via the callback function at the very bottom... any thing jumping out at anybody?
Code: Select all
// pass two arrays [x,y]
UCA_Map.prototype.restrictBounds = function(ne, sw){
if(typeof ne != 'object' || typeof sw != 'object'){
throw 'Bad arguments for UCA_Map.restrictBounds. Expecting arrays';
return false;
}
neBound = new GLatLng(ne[0], ne[1]);
swBound = new GLatLng(sw[0], sw[1]);
// ====== Restricting the range of Zoom Levels =====
// Get the list of map types
var mt = this.map.getMapTypes();
// Overwrite the getMinimumResolution() and getMaximumResolution() methods
for (var i=0; i<mt.length; i++) {
mt[i].getMinimumResolution = function() {return 8;}
}
// The allowed region which the whole map must be within
var allowedBounds = new GLatLngBounds(swBound, neBound);
var checkBounds = function (map, allowedBounds) {
// 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();
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));
}
// Add a move listener to restrict the bounds range
GEvent.addListener(this.map, "move", checkBounds(this.map, allowedBounds));
}