Open Layers 4 中是否定义了 getZoomForResolution?如果是这样,我该如何让它工作?

Is getZoomForResolution defined in Open Layers 4? And if so, how do I get it working?

对于我的地图应用程序,我想在不同的函数中使用 ol.View.zoom-属性 以及 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 is not a function"。我也看了 post,但是它指的是OL 3,没有给出证据。

所以,我的问题是:getZoomForResolution 函数是否不再实现?还是我尝试访问它的方式有误?

在这里工作得很好。 https://codepen.io/anon/pen/vePjxa?editors=1011

 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));

您是否有无法正常工作的沙箱?