我想在标记周围画一个正方形。如果我画一个大正方形, map 应该自动缩小,以便我们可以完整地看到正方形。如果我画一个小正方形, map 应该自动放大以完全显示正方形。
In this image I have drawn small square so we can see the square completely
In this image I have drawn a larger square, Since the map is not zooming out we cannot see the square sides
最佳答案
见 ol.View在 openlayers 3 文档中。有一个功能setZoom(zoom)
.
所以如果你的 map 变量是 map
, 放大使用 map.getView().setZoom(map.getView().getZoom() + 1);
并缩小使用 map.getView().setZoom(map.getView().getZoom() - 1);
关于openlayers-3 - 如何以编程方式缩放 map Openlayers 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40905127/