3
我正在使用ol.Interaction.Draw
在地圖上繪製多邊形。我想在繪製完個人特徵後對其進行設計。當我檢測到一個DRAWEND
事件時,我嘗試將樣式附加到繪製的最後一個要素上,但只有一般圖層樣式出現在屏幕上,儘管我在通過調試器搜索要素本身時看到了它。在繪製後附加樣式到要素
map.addInteraction(drawInter = new ol.interaction.Draw({
features: drawLayer.getFeatures(),
type: "Polygon"
})
);
drawInter.on('drawend', function(e) {
var style = new ol.style.Style({
fill: new ol.style.Fill({ color: newColor })
});
var features = drawLayer.getFeatures().getArray();
var last = features.length-1;
features[last].setStyle(style);
});
我工作過掉'繪製和修改功能example'在網站上,並定義我的圖層是這樣的: 'drawLayer = new ol.FeatureOverlay({source:new ol.source.Vector()});' 這會產生一個錯誤,使用'source:drawLayer.getSource ()'方法。 – Bill
**更新:**我將圖層初始化更改爲: 'drawLayer = new ol.layer.Vector({source:new ol.source.Vector()}); map.addLayer(this.drawLayer)' ,我現在可以風格特點,但是當我加入modifyInteraction: 'map.addInteraction(this.modifyInter =新ol.interaction.Modify({Y 來源:drawLayer .getSource()' 無論何時加載此代碼,我都會收到一個錯誤: _Uncaught TypeError:無法在ol-debug.js中讀取undefined屬性'forEach':90285_ – Bill
這是一個不同的問題。一個'ol.Collection',通過'features'選項指定。這個集合包括修改的候選對象。 – erilem