2016-04-25 25 views
2

我想添加一個選擇交互的hightlighting我drawed像本例中的功能,但對我自己的畫吸引:選擇與hightlight我自己對OpenLayers3

http://openlayers.org/en/master/examples/select-features.html

要Hightlight功能我使用ol.events.condition.pointerMove

var highlighter = new ol.interaction.Select({ 
    layers: [featureOverlay], 
    condition: ol.events.condition.pointerMove 
}); 

在我的例子,當我畫一個多邊形,啓動「Hightlighter」,並走在drawed功能好像選擇切換開關。

我覺得這個代碼工作的3.13.1版本

這裏有一個Fiddle

回答

1

你加入你的繪製功能到非託管層(老ol.FeatureOverlay)與featureOverlay.setMap(map);。我不知道爲什麼你需要這個,爲什麼這個閃爍,但如果你更改爲管理ol.layer.Vector那麼這種行爲已經一去不復返了:

var featureOverlay = new ol.layer.Vector({ 
    source: new ol.source.Vector(), 
    style: featureStyle 
}); 
map.addLayer(featureOverlay); 

var drawPolygon = new ol.interaction.Draw({ 
    source: featureOverlay.getSource(), 
    type: 'Polygon' 
}); 

http://jsfiddle.net/jonataswalker/p1q7s50k/

+0

謝謝Jonatas,你的代碼運行良好。 添加矢量圖層並不是我喜歡的,因爲現在我在應用程序的layersTree上看到它們,它們並不總是處於頂層,但我認爲我可以修改它並避免此行爲 –

+0

@ A.Bahi因此,您可以發佈您的解決方案並將其標記爲正確並完成此主題。 –

相關問題