[OpenLayers-Users] Problem with styling vectorfeatures depending on
their attributes
Max Stephan
x.zam at gmx.net
Thu Sep 17 09:47:26 EDT 2009
Hi list,
I have a vectorlayer to which the user can add features and modify those
features. The user can change the attributes for the features like
fillColor, strokeColor etc. in a form. A javascript-method is executed by a
button-click and saves those attributes as vectorattributes (e.g.
feature.attributes.fillColor).
In the styleMap I´m reading those values from the vectorattributes to change
the styling. The stylemap-Code looks like this:
var pointStyleMap = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
fillColor: "${fillColor}",
fillOpacity: 0.5,
strokeColor: "${strokeColor}",
strokeWidth: "${strokeWidth}",
pointRadius: 10,
graphicZIndex: "${graphicZIndex}"
}
),
"select": new OpenLayers.Style({
pointRadius: 10,
strokeColor: '#FF3333',
strokeWidth: "${strokeWidth}"
}
)
});This works so far. But now I want to add 2 to the strokeWidth when the
feature is selected, so I tried it like this:
strokeWidth: "${strokeWidth}" + 2The effect is that the 2 is only appended
(the code seems to interprete strokeWidth as a String although I parsed it
to an Int via parseInt(), e.g. for a strokeWidth of 2 I get 22 as a result).
It´s possible to solve this problem by defining a context for the style but
in my opinion that´s a little overkill for such a simple task.
{context:
{strokeWidth: function (feature){return (feature.attributes.strokeWidth +
2)}}
}Now I want to get the pointRadius from the attributes but no matter which
method I try, it always ends in the error message: "Line: 625 Column: 408,
invalid Argument (OpenLayer.js)". Also tried to parse it to an Int again
directly in the styleMap .. no effect.
I have to use IE for this project so no further debug information is
available (I´m also not able to install IE8 with it´s debugging features due
to limited admin rights at my workstation).
Any idea how I could solve this problem?
Thx in advance
Max Stephan
--
View this message in context: http://n2.nabble.com/Problem-with-styling-vectorfeatures-depending-on-their-attributes-tp3663197p3663197.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list