【发布时间】:2018-03-30 03:17:07
【问题描述】:
对于我的地图应用程序,我想在不同的功能中使用 ol.View.zoom-property 和 ol.View.resolution 属性。根据 Open Layers 4 API 文档,如果给出分辨率,则忽略缩放属性。 因此,我正在尝试应用 getZoomForResolution,它记录在此处的 API 中:
https://openlayers.org/en/latest/apidoc/ol.View.html#getZoomForResolution
这是我使用的一些测试代码:
var map, view;
//initial definition of the map
function initializeMap(){
//define osm source and layer
var osmSource = new ol.source.OSM();
var osmLayer = new ol.layer.Tile({source: osmSource});
//define new map object
map = new ol.Map({
target:'map',
view: new ol.View({
center: ol.proj.fromLonLat([9.83276, 52.36554]),
resolution:300, // is required in some function
zoom:10 //ignored as expected according to API, also required in another function
}),
layers:[osmLayer]
});
var currentResolution = map.getView().getResolution(); // returns 300 as expected
console.log(map.getView().getZoomForResolution(currentResolution));
}
不幸的是,我只收到错误“map.getView().getZoomForResolution 不是函数”。我也看过this的帖子,但它指的是OL 3,没有给出证据。
所以,我的问题是:getZoomForResolution 功能不再实现了吗?还是我尝试访问它的方式有误?
【问题讨论】:
标签: openlayers