[OpenLayers-Users] OpenLayers.Feature.Vector style

Slawomir Messner slawomir.messner at staff.uni-marburg.de
Fri Aug 27 01:52:05 EDT 2010


  Hi,
1. Is this the recommended way to work with styles or is there a better 
way? Is there maybe already a tool? Jep, we could put any value in 
attributes or feature.sytle but sometimes there are more then 2000 
features so we want to have as few styles as possible. Are rule maybe 
better even if harder to parse?
  The functions described below are working already, but not always 
together, the workflow below will be the new one and before I change 
"all" our controls and loading mechanism from every source... I would 
like to have some opinions.
2. The docs telling you at OL.Feature.Vector under 
OpenLayers.Feature.Vector.style "OpenLayers features can have a number 
of style attributes..." but it's the layer, right? I see my style only 
if I set OpenLayers.Feature.Vector.style like {'pointRadius':6, 
fillColor:'#FF0000'} not OL.StyleMap({'default': {'pointRadius':6, 
fillColor:'#FF0000'}, 'select': {'pointRadius':6, fillColor:'#0000FF'} 
}) or {'default': {'pointRadius':6, fillColor:'#FF0000'}, 'select': 
{'pointRadius':6, fillColor:'#0000FF'} }.
3. StyleMap, Style and Object are the classes you have to work with. 
Sometimes it's ok to write attributes it into style directly and in some 
cases it's better to use style.styles["default"].defaultStyle. Are there 
some plans to change styling or limit the way to style to make it more 
clearly for OL 3.0? Something like: Every stlye attribute is a stylemap 
and when it doesn't have the style you want look in it's "container" 
(control)->feature->layer(or should it be feature->(control)>layer).

Step 1. Let's say we have some named places in a vector layer some 
chosen geometries form our data. When we load them we use the common way 
to style them with StyleMap in the layer also the labels, the text is 
stored in an attribute so we use ${attribName}.
Step 2. Now we want to edit the style of one feature so we have to use 
the style attribute of OL.Feature.Vector, right? Because we want to 
change only some attributes the layer style and not to create a new 
style than we have to copy the layer (default) style into the features 
style attribute before editing:
feature.style = 
OpenLayers.Util.extend({},layer.style.styles["default"].defaultStyle);
Step 2b. Because some attributes are calculated from attributes so the 
attributes of feature.style are replaced by the values if there is 
something like this ${attribName}. Nearly all style attributes should be 
editable labels, graphics, strokes, fill, radius...
But now we lost the ability to mark this feature as selected, it doesn't 
work by the select style of the layer. Expect we define a selectStyle in 
the SelectFeature control, but this style would be same for every 
feature so i.e. we cannot keep the different labels.
Step 3. Editing of attributes or moving features. For editing style it's 
not so important to have a select style but when you use the layer with 
other controls, like an attribute editor. What would we do if a user 
changes in a feature with edited style the attribute for the label? We 
have to read it again and put it into feature.style like in 2b.
Step 4. Adding new features.
A user expects that he can do Step 2,3 and 4 not in the row and multiple 
times.
Step 5. Now the user should be able to save the resulting map with style 
and attributes. so for every edited feature we have to save the style 
attribute for the others the layer.style.styles["default"].defaultStyle 
or mark them as "layerStyled" and save the default Style to reuse it as 
layer style the next time a user loads his layer.
I'm looking forward for your critics, tipps and other helping things. 
I'm open for questions and so on.
Thx and Regards,
Slawomir

-- 
-----------------------------------------------
Slawomir Messner
Forschungszentrum "Deutscher Sprachatlas"




More information about the Users mailing list