【问题标题】:How to zoom map programmatically Openlayers 3?如何以编程方式缩放地图 Openlayers 3?
【发布时间】:2016-12-01 07:43:38
【问题描述】:

我想在标记周围画一个正方形。如果我画了一个大正方形,地图应该会自动缩小,这样我们就可以完全看到这个正方形。如果我画一个小正方形,地图应该会自动放大以完全显示正方形。

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

【问题讨论】:

    标签: openlayers-3


    【解决方案1】:

    请参阅 openlayers 3 文档中的 ol.View。有一个函数setZoom(zoom)

    所以如果你的地图变量是map,放大使用map.getView().setZoom(map.getView().getZoom() + 1);,缩小使用map.getView().setZoom(map.getView().getZoom() - 1);

    【讨论】:

      【解决方案2】:

      如果您想要平滑缩放:

      map.getView().animate({
        zoom: map.getView().getZoom() + 1,
        duration: 250
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-15
        • 2016-04-26
        • 1970-01-01
        • 1970-01-01
        • 2012-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多