I am using ol.Interaction.Draw
to draw polygons atop a map. I want to style the individual features after they're drawn.
When I detect a DRAWEND
event, I try to attach a style to the last feature drawn, but only the general layer styling appears onscreen, although I see it when I search in the feature itself via the debugger.
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);
});
Draw and modify features example
on the site, and have defined my layer like this:drawLayer=new ol.FeatureOverlay({ source: new ol.source.Vector() } );
and this yields an error using the'source: drawLayer.getSource()
method. – Gamy