Bounds如何在OpenLayers 3中运行?

col*_*lin 14 openlayers openlayers-3

难道概念OpenLayers.Bounds从2.X的OpenLayers仍处于3的OpenLayers存在?它是如何改变的,它的新名称是什么?

Chr*_*ssy 8

更新:OL4:https://openlayers.org/en/latest/apidoc/ol.html#.Extent

似乎"边界"或"边界框"(BBOX)的新词是"范围".看到:

目前找出问题的一种方法是在OL3仓库中运行搜索,例如:https://github.com/openlayers/ol3/search? p = 3& q = BPOX&type = Code


Bas*_* Ho 6

没有找到有关此功能的任何文档,但Extent似乎有效:

var vectorSources = new ol.source.Vector();
var map = new ol.Map({
  target: map_id,
  layers: [
    new ol.layer.Tile({
      source: ol.source.OSM()
    }),
    new ol.layer.Vector({
      source: vectorSources
    })
  ],
  view: new ol.View({
    center: [0, 0],
    zoom: 12
  })
});

var feature1 = new ol.Feature({
  geometry: new ol.geom.Point(coords)
});
vectorSources.addFeature(feature1);
var feature2 = new ol.Feature({
  geometry: new ol.geom.Point(coords)
});
vectorSources.addFeature(feature2);
map.getView().fitExtent(vectorSources.getExtent(), map.getSize());
Run Code Online (Sandbox Code Playgroud)

该方法vectorSources.getExtent()也可以替换为任何Extent对象,如下所示:

map.getView().fitExtent([1,43,8,45],map.getSize());

自OpenLayer 3.9以来,该方法已经改变:

map.getView().fit(vectorSources.getExtent(), map.getSize());

  • 谢谢.这似乎是文档的**范围**:http://openlayers.org/en/v3.0.0/apidoc/ol.extent.html (2认同)

Grm*_*mbl 5

只是为答案添加一个小例子:Bounds现在称为"extent",它不再是复杂的Object/Class,而只是一个包含四个数字的数组.在"ol.extent"中有很多用于转换的辅助函数等等.关于如何进行转型的一个小例子:

var tfn = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
var textent = ol.extent.applyTransform([6, 43, 16, 50], tfn);
Run Code Online (Sandbox Code Playgroud)

var textent = ol.proj.transformExtent([6, 43, 16, 50], 'EPSG:4326', 'EPSG:3857');
Run Code Online (Sandbox Code Playgroud)

到目前为止,我无法在http://ol3js.org/en/master/apidoc中找到API-Doc,因此您必须阅读源代码才能获取信息.

自BETA以来,API-Docs已经完成.所以你现在就能找到它.

正如评论中所提到的,正确的API函数现在是ol.proj.transformExtent().