[OpenLayers-Trac] [OpenLayers] #533: Style vector layers with SLD

OpenLayers trac at openlayers.org
Tue Nov 6 18:27:41 EST 2007


#533: Style vector layers with SLD
----------------------+-----------------------------------------------------
  Reporter:  sderle   |       Owner:             
      Type:  feature  |      Status:  new        
  Priority:  minor    |   Milestone:  2.6 Release
 Component:  Layer    |     Version:             
Resolution:           |    Keywords:  review     
----------------------+-----------------------------------------------------
Comment (by ahocevar):

 Replying to [comment:5 elemoine]:
 Eric, thank you for reviewing my code! I fixed most of the problems, and I
 have additional comments for some of them:
 >  * (line 405) The style property of an !OpenLayers.Layer.Vector object
 may cover multiple layers whereas only the part related to that object
 (layer) is relevant. Wouldn't it make sense to store only what's
 necessary? By doing so, we could also avoid the lookup done in
 getDefaultStyle().

 You are absolutely right. This was how it was originally implemented. But
 the magic to determine the correct style that is in SLD (and also in a
 hash of styles derived from it), seemed too precious to ignore. Anyway, I
 think I have found a solution: a hash of OpenLayers.Style can no longer be
 passed as option with the constructor. But the setStyle method can take a
 hash and determine the correct style, which will then be stored in the
 style property of the vector layer.

 >  * On a more general note, I don't like too much the fact that
 !OpenLayers.Layer.Vector's style property can be a hash or an
 !OpenLayers.Style object (instanceof must be used). Wouldn't be possible
 to use !OpenLayers.Style everywhere - !OpenLayers.Style looks pretty
 generic. Maybe you're concerned with backward compatibility here.

 Yes, backwards compatibility was exactly my concern. I wanted to leave a
 footprint as small as possible on the existing code base. But you are
 right, OpenLayers.Style is pretty generic. And it holds a style hash in
 its defaultStyle and defaultSelectStyle properties that will be used if no
 rules are defined.

 I created a new patch. This one also contains the changes proposed in
 http://trac.openlayers.org/ticket/1073. Another new feature: style
 properties in a style object can now have references to feature
 attributes, acting as a variable, eg.
 {{{
 feature.attributes['labelText'] = 'myLabelText';
 feature.style.defaultStyle.label = 'feature labeled ${labelText}';
 }}}
 This label property would evaluate to "feature labelled myLabelText". In
 SLD, the same could be defined by saying
 {{{
 <sld:Label>feature labelled
 <ogc:PropertyName>labelText</ogc:PropertyName></sld:Label>
 }}}
 This fancy trick is somewhat beyond the SLD spec, except for labels. But
 it is convenient, especially when working with style objects directly
 instead of SLD. The use case of #1073 can be solved without lookup style
 rules, by simply saying
 {{{
 style.defaultStyle.externalGraphic = "${category}.png";
 }}}
 It does not only work when set for style properties, but also for value
 and lower/upper boundary of comparison rules and for
 min/maxScaleDenominator.

 This patch is still lacking some tests for the new features, but I provide
 it anyway for reviewing. Tests will follow soon.

-- 
Ticket URL: <http://trac.openlayers.org/ticket/533#comment:6>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list