簡體   English   中英

OL3:如何判斷特定矢量源中的點特征?

[英]OL3:How to judge a point feature in a specific vector source?

在使用ol3構建的網站中,我的地圖中有兩個或多個帶有不同源的矢量層,我想單擊特定源中的要素並顯示一些彈出窗口。 我的方法是在地圖上添加一個單擊事件,並使用source.getFeaturesAtCoordinate(evt.coordinate)但始終會得到空結果[]。在這種情況下我該怎么辦?

對於積分,您需要非常幸運地達到確切的坐標。 您需要考慮點的渲染大小,為此,最好使用ol.Map#forEachFeatureAtPixel() 它適用於圖層,而不適用於源:

map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
  // get the source
  source = layer.getSource();
  // do something with the feature
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM