【问题标题】:How to zoom to any feature of Openlayers3 (v3.17.1) map如何缩放到 Openlayers3 (v3.17.1) 地图的任何功能
【发布时间】:2016-07-18 13:57:03
【问题描述】:

我知道这个问题已在许多其他主题中讨论过。但我仍然无法为我的问题找到解决方案。没有收据对我有用。

一个问题很简单。我的 Openlayers3 (v3.17.1) 地图上有一个功能。我应该能够缩放到我想要的任何功能。

缩放前:

缩放后:

正如我提到的,我使用的是 v3.17.1 版本。

var features = myLayer.getSource().getFeatures();
var myFirstFeature = features[0];

选项 1:

map.zoomToExtent(feature.geometry.getBounds());

选项 2:

    var bounds = f.geometry.getBounds().clone();
    this._map.zoomToExtent(bounds,false);

【问题讨论】:

  • 你能告诉我们你的代码不起作用吗?你到底尝试了什么?
  • 更新了原始描述

标签: openlayers-3


【解决方案1】:

有很多方法可以做到这一点,例如,如果您只想缩放到一个特征并且想要定义缩放级别,您可以使用以下方法:

var ext=feature.getGeometry().getExtent();
var center=ol.extent.getCenter(ext);
map.setView( new ol.View({
    projection: 'EPSG:4326',//or any projection you are using
    center: [center[0] , center[1]],//zoom to the center of your feature
    zoom: 12 //here you define the levelof zoom
}));

还有另一种方法可以放大到更多的功能:

map.getView().fit(extent, map.getSize());

假设你拥有你的一个或多个特征的范围

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-19
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多