[OpenLayers-Users] Markers vs Features?

Matt J Cwanek mcwanek at fourddev.com
Fri Apr 4 12:38:47 EDT 2008


On 04/04/08 11:41 -0400, Christopher Schmidt wrote:
> > Coming from the GMap2 world, I initially ported our code to work with the
> > OpenLayers.Marker class, where it had been previously using GMarkers. I
> > knew that I would be using Features to support the vector functionality,
> > but when I started looking at how to make certain user-created Markers
> > draggable (as we had before with GMap2), I started getting lost.
> 
> Is there a reason that you treat Markers (icons) and vectors
> (points/line/polys) differently?

Historical, really. We had GMarkers working way before we needed lines and
areas in GMap2. But there's no reason now to treat them differently.

> If we were to look at The Way Things Should Probably be, I would say
> that Markers are only there as a historical thing. "Everything should be
> using Vectors" -- *including* things that you want graphical images for.

Ok, that's kinda the feeling I was getting looking at the code.

> Note that OpenLayers.Feature in and of itself doesn't get you
> draggability: just OpenLayers.Feature.*Vector* does. But yes.

Ah, right. Thanks for the tip.

> > But then I'm getting
> > confused by the fact that a Feature attaches to a particular Layer, when
> > we intended to have multiple base layer options for the user to pick
> > from.
> 
> This is another GMaps misconception: In GMaps, all overlays are on a
> single layer. In OpenLayers, the "layer" you attach features to is
> *just* for the features. You will have multiple base layers (Google, Not
> Google, Map tiles, whatever) and an *overlay* layer (which can be turned
> on and off).

Good, I'd already started heading down that road.

> In general, you can even have, for example, all your lines on one layer,
> all your points on another.
> 
> At the current time, only one layer can be 'selectable' (and therefore
> draggable) at a time -- therefore there are technical limitations
> blocking this, but that's at least the idea.

Well, then let me ask this. All our markers (draggable or not) currently
can be clicked to open a GMap2 infowindow for details about that marker.

If I split the markers into draggable and non-draggable, and create a
separate layer for each, does that mean only the selected layer will
receive click events? 

> > And finally, I don't understand why a Feature has it's own lonlat that
> > could be different from the one the Marker has....?
> 
> It shouldn't ever be different. Just two different levels of
> abstraction: Feature has a lonlat, and you shouldn't need to think about
> a marker at that point.

Ok, so it sounds like what I should do is use a Vector feature w/a Point
geometry and appropriate styling, instead of using a Marker or a base 
Feature w/a Marker.

> Hope this helps,

Yes, this is a huge help, thanks.




More information about the Users mailing list