[OpenLayers-Dev] Features, Styling and Rendering

Andreas Hocevar andreas.hocevar at gmail.com
Fri Nov 16 16:00:19 EST 2007


after thinking about and looking at my code for styles and rules
(http://trac.openlayers.org/ticket/533, sandbox/ahocevar/sldRenderer)
as well as everything around it again and again, especially after Tim
asked me about ideas on how to implement KML StyleMaps, I came up with
the following conclusions and questions:

* #533 is not ready for review yet, because the way styles are stored
in layers, features and controls should be reconsidered in OpenLayers
in general. So if anyone wants to review my work, please do only look
at OpenLayers.Format.SLD, OpenLayers.Style and OpenLayers.Rule (plus
subclasses), those I would consider ready for trunk. The rest is about
applying and using styles, and there is a lot of open questions here.

* IMO calculating styles should happen in renderer.drawFeature (and
not in Layer.Vector.drawFeature, Control.SelectFeature.select and
Marker.draw and probably other places where it is now - in general,
not only in my sandbox)

* Having said that: why do vector features not have a draw method like
markers? (not related to my work). Shouldn't either Feature have a
drawMarker method, or Feature.Vector a draw method? And why do we have
markers anyway? Isn't rendering something that should happen at the
level of geometries, not features? And isn't drawing markers just a
different way of rendering point geometries? So maybe, instead of a
Feature having a Marker, Feature should be the same as Feature.Vector,
but can opt to have its geometries rendered by a new Renderer.Point
instead of Renderer.SVG or Renderer.VML?

* KML style maps are a good thing. And I think styles in OpenLayers
should generally be hadled as style maps somehow. Every method that
calls renderer.drawFeature should not pass a style, but a
renderingIntent. This would be a one-time assignment of which key from
a style map to use, and switching styles back and forth (like
currently in the Control.SelectFeature.select method) would not be
needed any more, e.g.

feature.style = {
    "default": defaultStyle,
    "select": selectStyle

layer.renderer.drawFeature(feature, "select")

--> draw feature with style["select"], with style being a style map of
OpenLayers.Style and "select" being a well known style key for
selected features. This is also something that SLD uses in a similar
way, because we have UserStyles with different names there. A
UserStyle in SLD is mapped to OpenLayers.Style, and the name of the
rule would be the key under which to add it to a style map. And guess
what: this is exactly what OpenLayers.Format.SLD is doing. So we have
style maps already, but we do not use them in layers, features or

I hope that after these statements, people will come up with
discussion, ideas and solutions. Unfortunately, I'm a little bit short
on time at the moment, but I have not given up on the whole styling
thing yet.


More information about the Dev mailing list