如何设置 Google map 小部件的范围?例如,我只需要 [SW Angular : 40.5, -25.5] - [NE Angular 79.5, 178.5] 矩形。现在我正在使用另一个问题中的代码:
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(40.5, -25.5),
new google.maps.LatLng(79.5, 178.5)
);
// Listen for the dragend event
google.maps.event.addListener(map, 'dragend', function() {
if (strictBounds.contains(map.getCenter())) return;
// We're out of bounds - Move the map back within the bounds
var c = map.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
map.setCenter(new google.maps.LatLng(y, x));
});
但它没有给出所需的效果 - 无论如何,此代码允许缩放 map 并且用户可以看到跨越严格边界的片段。
所以,我想知道,API v3中有没有任何方法可以从完整的世界地图中裁剪必要的部分?
最佳答案
我认为在您的情况下,您可以通过设置相应的 minZoom 属性来另外禁止用户缩小范围
您可以在初始化 map 时执行此操作,也可以在 map 初始化后执行此操作,如下所示:
map.setOptions({minZoom:5});
关于javascript - 使用 Google Maps API v3 裁剪部分 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16885845/