How to display only exact region on any open-sourc

2019-09-21 05:47发布

This question already has an answer here:

I need to show only one region on the map. For example Alaska or New-York city.

2条回答
冷血范
2楼-- · 2019-09-21 06:34

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

查看更多
老娘就宠你
3楼-- · 2019-09-21 06:43

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/

查看更多
登录 后发表回答