How to display only exact region on any open-source map (like maptalks)? [duplicate]

懵懂的女人 提交于 2019-12-13 09:23:28

问题


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


回答1:


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




回答2:


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/



来源:https://stackoverflow.com/questions/55572273/how-to-display-only-exact-region-on-any-open-source-map-like-maptalks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!