I need to show only one region on the map. For example Alaska or New-York city.
Asked
Active
Viewed 327 times
-2
-
1Could you show some code ? – Moad Ennagi Apr 08 '19 at 11:23
-
2Which library? Usually you achieve this by restricting the view to a specific bounding box. – scai Apr 08 '19 at 11:25
-
1https://developers.google.com/maps/documentation/javascript/reference/map#MapRestriction - do not follow the answers you have received so far, they are either wrong, incomplete or do not make use of the adequate interface provided by the API. – MrUpsidown Apr 08 '19 at 11:57
2 Answers
0
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

Gregory Orlov
- 517
- 1
- 6
- 15
-1
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/

Mahdi.momtaheni
- 113
- 1
- 1
- 8