[OpenLayers-Dev] Features, Styling and Rendering

Andreas Hocevar andreas.hocevar at gmail.com
Thu Nov 22 09:09:37 EST 2007


Hi,

thanks Eric for your comments.

On Nov 22, 2007 1:42 PM, Eric Lemoine <eric.c2c at gmail.com> wrote:
> On Nov 16, 2007 10:00 PM, Andreas Hocevar <andreas.hocevar at gmail.com> wrote:
> Makers were added in OpenLayers before all the vector stuff. I think
> that's the reason of these inconsistencies between markers and
> features.

I think so, too. And making Marker, Feature and Feature.Vector more
consistent is definitely a thing to be considered not before
OpenLayers 3.0 IMO.

> Also, note that OpenLayers.Marker doesn't inherit from
> OpenLayers.Feature.

I know. As I understand it, OpenLayers.Marker can be looked upon as a
renderer for OpenLayers.Feature, but I'm well aware that it can also
be used separately.

> > 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,
>                                             ^^^^^
>
> You mean Marker here, don't you?

No, I mean OpenLayers.Feature. Currently, we have OpenLayers.Feature
and OpenLayers.Feature.Vector, and my question was if those should
maybe be merged into one (again, nothing to be concerned of before
3.0). Let me sum up the things that they have in common and what is
different:

* Feature.Vector has a geometry and a style. In Feature, similar
information is stored in lonlat and data.icon.
* Feature.Vector has attributes, Feature has data. This is the same,
except that data has the icon (=style information) in it.
* Feature has a popup, Feature.Vector only dummy methods
createPopup/destroyPopup
* Feature.Vector is rendered using a layer it is contained in, Feature
using a marker created out of lonlat and data.icon

> > but can opt to have its geometries rendered by a new Renderer.Point
> > instead of Renderer.SVG or Renderer.VML?
>
> With the external graphics stuff, I'm not sure it's worth bothering
> adding Renderer.Point. I agree that it's a bit strange to rely on
> vector renderers (SVG and VML) for markers, but do we really want to
> have two different ways to render markers?

I would totally agree, if only vector layers would not prevent click
and hover events from being received by layers below
(http://trac.openlayers.org/ticket/434). With points rendered as
images, you can have several marker layers and do click action on any
of them. With points rendered as vectors, you can only have that in
the uppermost layer. Unfortunately, I do not have an idea on how to
change vector layers in a way that would allow to receive click/hover
events on more than one layer.

> > * 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
> > whatever.
>
> How would that work for user-defined styles?

Instead of storing a single style with a feature, we would store a
style map. In current trunk OL, this could be a hash of style hashed,
keyed by renderIntent (like the style constant in
OpenLayers.Feature.Vector). In the case of my OpenLayers.Style work,
it would be a hash of OpenLayers.Style, again keyed by renderIntent.

By saying "we have style maps already", I meant that SLD can have many
named styles for one named layer (think of style names as renderIntent
keys). This is similar to KML style maps.

Does that answer your question?

Regards,
Andreas.



More information about the Dev mailing list