小编Som*_*lse的帖子

OpenLayers 3矢量图层上所有要素的范围?

我有一个OpenLayers 3地图,带有基础层和矢量图层.

this.topoLayer = new ol.layer.Vector({
  source: new ol.source.Vector(),
  style: style
});

var baseLayer = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://[…]/{z}/{x}/{y}.png',
        crossOrigin: 'null'
    })
});

this.map = new ol.Map({
    target: 'map',
    layers: [baseLayer, this.topoLayer],
    view: new ol.View2D({
        center: ol.proj.transform([11.38,  48.54], this.options.markerEPSG, this.options.mapEPSG),
        zoom: 5,
    }),
});
Run Code Online (Sandbox Code Playgroud)

在用户交互时,我向向量层添加和删除了几个要素.以下是添加新功能的功能:

  var feature = new ol.Feature({
        topo: topo,
        selected: false,
        geometry: new ol.geom.Point(ol.proj.transform(location, this.options.markerEPSG, this.options.mapEPSG)),
  });

  this.topoLayer.getSource().addFeatures([feature]);
Run Code Online (Sandbox Code Playgroud)

添加/删除新功能后,我想自动缩放和平移地图以适应我的功能.在旧的OpenLayers API中getDataExtent,矢量图层上有一个函数可以检索显示的所有特征周围的"边界框".但我想知道如何使用新的API做到这一点.

javascript openlayers openlayers-3

19
推荐指数
3
解决办法
3万
查看次数

标签 统计

javascript ×1

openlayers ×1

openlayers-3 ×1