在我的应用程序中,我添加了一个包含开放层 3、绘制点和线的 Mapquest 层...
现在我需要使用
了解 map 中长/纬度点(可见区域)的像素坐标map.getPixelFromCoordinate(coordinate).
此函数始终返回null
(测试):
center = map.getView().getCenter();
px = map.getPixelFromCoordinate(center);
alert(JSON.stringify(px));
我做错了什么或者我没有正确理解什么?
最佳答案
我找到了这个答案:
I'd be careful with this. You might get wrong results, e.g. when the map does not have the final layout yet. It is better to wait with the first coordinate to pixel conversion until the map is rendered. You do not need a timeout for this, we have the 'postrender' event on ol.Map. So in your initialisation code, you could do something like this:
map.once('postrender', function() {
// safe to call map.getPixelFromCoordinate from now on
});
来源:github.com/openlayers/ol3/issues/5456
我希望这会有所帮助。
关于javascript - getPixelFromCoordinate 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37720736/