[OpenLayers-Users] How to access style properties of features?

Andreas Hocevar ahocevar at opengeo.org
Mon Dec 21 07:48:32 EST 2009


Hi,

Peter.Sykora at ooe.gv.at wrote:
>> Try feature.style.graphicWidth instead of 
>> feature.Vector.style.graphicWidth.
>>     
>
> I tried that, and several other things as well but I didn´t get any results so far.
>
> Just to be sure that the problem is not the code of the rest of my project I added the following line
>
> alert (features[0].style.graphicWidth);
>
> to the styleMap Example (http://www.openlayers.org/dev/examples/stylemap.html)
> Again, features[0].style is null.
>   

Ok, I thought your features come e.g. from a Layer.KML, which sets a 
style property on the feature. Where do your feature styles come from, 
or what makes you think your features have a style property (because by 
default they don't, unless you set it)? I think that you have a 
graphicWidth attribute in your features, not a style. So you would use 
feature.attributes.graphicWidth to access that.

> I just wonder why there is a "style" property in OpenLayers.Feature.Vector but not in OpenLayers.Feature
>   

Because OpenLayers.Feature is for Markers layers, and Markers layers 
don't have the concept of a style.

Regards,
Andreas.

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list