2
我想根据矢量图层的特征(点)来定位我的地图的中心和缩放级别。打开图层3根据矢量图层的范围将地图居中?
我有的填充我的地图GeoJSON的文件:
var vectorSource = new ol.source.Vector({
url: 'assets/js/data.geojson',
format: new ol.format.GeoJSON(),
projection: 'ESPG:3857'
});
我现在尝试获取矢量图层的程度:
vectorSource.once('change', function (e) {
if (vectorSource.getState() === 'ready') {
if (vectorLayer.getSource().getFeatures().length > 0) {
map.getView().fit(vectorSource.getExtent(), map.getSize());
}
}
});
我怎样才能获得地图的坐标基于图层特征并缩放至特定级别?
map.setCenter("// Center position of lon,lat based on layer features//");
map.setZoom("// Zoom level according to layer features//");
我没有意识到!我认为我仍然需要应用setCenter。 现在已解决!谢谢! –
看看[fit](http://openlayers.org/en/master/apidoc/ol.View.html#fit)方法,有一些选项。别客气。 –