Does the concept of OpenLayers.Bounds from OpenLayers 2.x still exist in OpenLayers 3? How has it changed, and what is its new name?
UPDATE: OL4: https://openlayers.org/en/latest/apidoc/ol.html#.Extent
It seems that the new word for 'bounds' or 'bounding box' (BBOX) is 'extent'. See:
One way to find out things at the moment is to run searches in the OL3 repo, for example: https://github.com/openlayers/ol3/search?p=3&q=BBOX&type=Code
Did'nt found any documentation about this feature but Extent seems to work :
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());
The method vectorSources.getExtent()
can also be replaced by any Extent object, like this :
map.getView().fitExtent([1,43,8,45], map.getSize());
Since OpenLayer 3.9, the method has changed :
map.getView().fit(vectorSources.getExtent(), map.getSize());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With