[OpenLayers-Users] Styling a feature through drawFeature's constructor

Alexandre Dube adube at mapgears.com
Thu Mar 4 10:14:19 EST 2010


Krisitan,

You could register a "featureadded" event to your DrawControl to affect 
a unique style, something like this (untested) :

yourControl.events.on({
"featureadded": onPolygonDrawn,
scope: this
});

function onPolygonDrawn(event) {
var feature = event.feature;

// create a symbolizer from exiting stylemap
var symbolizer = feature.layer.styleMap.createSymbolizer(feature);

// apply the changes you want
symbolizer['fillColor'] = 'yellow';

// set the unique style to the feature
feature.style = symbolizer;

// redraw the feature with its new style
feature.layer.drawFeature(feature);
}

Regards,

Alexandre


Frost89 wrote:
> Hi list,
>
> I have added a control to my map to draw a polygon. Now I would like to give
> this polygon a style, so I tried this:
>
> redlining: new OpenLayers.Control.DrawFeature(vectorLayer,
> OpenLayers.Handler.Polygon, {
>     type: OpenLayers.Control.TYPE_TOOL,
>     style: { fillColor: 'yellow' }
> })
>
>
> And it didn't work. How can I do something similar to this?
>
> - Kristian Frost
>
>
>
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list