[英]openlayers vector feature get pixel position
獲取OpenLayers.Feature.Vector像素坐標的最快方法是什么? 我的意思是,我希望獲得相對於已繪制特征的地圖容器的像素(頂部,左側)位置,如果可能的話,不進行計算,因為性能改進。
謝謝和問候,拉斐爾。
在ol3中:
var geometry = feature.getGeometry();
var coordinate = geometry.getCoordinates();
var pixel = map.getPixelFromCoordinate(coordinate);
在OL2中:
var geometry = feature.geometry;
var coordinate = new OpenLayers.LonLat(geometry.x, geometry.y);
var pixel = map.getPixelFromLonLat(coordinate);
一些先決條件:要素必須是點,否則geometry.getCoordinates()返回坐標數組,您需要選擇一個。 另一個應該是非常明顯的,但無論如何我都會提到它:變量map是ol.Map或OpenLayers.Map的實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.