This question already has an answer here:
- Google Maps v3 - limit viewable area and zoom level 12 answers
I need to show only one region on the map. For example Alaska or New-York city.
This question already has an answer here:
I need to show only one region on the map. For example Alaska or New-York city.
This solution is relevant to many js libraries. 1. Get boundaries via nominatim.openstreetmap.org API in a geojson format. 2. Set polygon/multipolygon mask on a [base]layer
You could find you'r area boundary and set map to limit panning. look at sample below:
var allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(70.33956792419954, 178.01171875),
new google.maps.LatLng(83.86483689701898, -88.033203125)
);
var lastValidCenter = map.getCenter();
google.maps.event.addListener(map, 'center_changed', function() {
if (allowedBounds.contains(map.getCenter())) {
// still within valid bounds, so save the last valid position
lastValidCenter = map.getCenter();
return;
}
// not valid anymore => return to last valid position
map.panTo(lastValidCenter);
});
Also you can use this link: https://jsfiddle.net/cse_tushar/9d4jy4ye/