这个问题在这里已有答案:
我需要在地图上只显示一个区域。例如阿拉斯加或纽约市。
该解决方案与许多js库相关。 1.以geojson格式通过nominatim.openstreetmap.org API获取边界。 2.在[基础]图层上设置多边形/多面镜蒙版
您可以找到您的区域边界并设置地图以限制平移。看下面的示例:
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);
});