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

Peter.Sykora at ooe.gv.at Peter.Sykora at ooe.gv.at
Mon Dec 21 09:00:53 EST 2009


Hi,

>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 use a styleMap that contains a user style, so I thought that this style should be accessible.
The strange thing for me is that with my custom functions e.g.: getChartURL or getSizeH I am able to set and influence the styling prameters but afterwards I´m not able to access their values.  

var template = {
	fillOpacity: "${getOpacity}",
	externalGraphic: "${getChartURL}",
	graphicWidth: "${getSizeW}",
	graphicHeight: "${getSizeH}",
	strokeWidth: 0,
	graphicXOffset: "${getXOffset}",
	graphicYOffset: "${getYOffset}"
};
style = new OpenLayers.Style(template, {context: context});
styleMap = new OpenLayers.StyleMap({'default': style, 'select': {fillOpacity: 0.7}});
			
With this style template I define the functions that calculate the styling parameters. E.g. the getSizeH function looks something like this:

getSizeH: function(feature) {
	setDefaultValues(feature);
	var Sum = getSum(feature);
	var size = calcSize(feature,Sum);
	// Size for pin icons
	if (Sum==1) {
		if (feature.attributes.hover==1) {size=48} else {size=32}
	}
	return size;
}

This function works fine and sets the graphicHeight to the needed value. Somehow internally in OpenLayers this information must be stored, otherwise the features couldn´t be drawn correctly, but how can I access this information? I thought this should be in my user style ...

Maybe my problem is that the features themselfs never get a style assigned in my code. They seem to get their styling information from the layers styleMap. But again the information about each individual symbols size in the map must be stored somewhere, but where??

>I think that you have a graphicWidth attribute in your 
>features, not a style. So you would use 
>feature.attributes.graphicWidth to access that.

As you can see in the above function I don´t set any attribute values. I just return the size value.

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

Ok, thanks for the clarification.

Regards,
Peter



More information about the Users mailing list