I want to limit bounds between using a lat & Lng co-ords, if the co-ords hits the bounds then the map, should not be draggable.
The script loads fine, in addition to my styedMap (variable). However I cannot seem to merge this code snippet - How do I limit panning in Google maps API V3?, into my own.
NOTE: the IF Statement just checks whether a Data Attr is present, so the code is invoked.
function area_page_map() {
var mapOptions = {
center: new google.maps.LatLng(51.5697317,-1.7923051),
minZoom: 11,
maxZoom: 20,
zoom: 11,
scrollwheel: false,
scaleControl: false,
streetViewControl: false,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(51.4380251,-2.047586),
new google.maps.LatLng(51.6556491,-1.6716272)
);
var lastValidCenter = map.getCenter();
google.maps.event.addListener(map, 'center_changed', function() {
if (allowedBounds.contains(map.getCenter())) {
lastValidCenter = map.getCenter();
return;
}
// not valid anymore => return to last valid position
map.panTo(lastValidCenter);
});
var map = new google.maps.Map(document.getElementById("area__map"), mapOptions);
// Associate the styled map
map.mapTypes.set('area__map', styledMap);
map.setMapTypeId('area__map');
}
if ( $area__page__map.length ){
google.maps.event.addDomListener(window, 'load', area_page_map);
}
If there also a means to trigger a function when the bounds are met, that would be great.. E.g. map wrapper red border.
-Many thanks