[OpenLayers-Users] Markers vs Features?
Christopher Schmidt
crschmidt at metacarta.com
Fri Apr 4 11:41:17 EDT 2008
On Fri, Apr 04, 2008 at 10:09:46AM -0400, Matt J Cwanek wrote:
>
> Hi:
>
> We have an application framework that we've decided to port from Google
> Maps 2 to OpenLayers, and so far it's been pretty painless. From the map
> perspective, our application provides for real-time marker updates via
> GPS devices, user-created markers w/custom icons, user-created vector
> features (lines, areas, polys), custom maptile sets, etc.
Cool.
> 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?
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.
As an example of that:
http://openlayers.org/dev/examples/sundials.html
These are vector features, with an external graphic styling object.
(Style properties are, specifically:
{"graphicOpacity":1,
"externalGraphic":"http://maps.google.com/mapfiles/kml/shapes/sunny.png",
"graphicXOffset":-19.2,
"graphicYOffset":-18.2,
"graphicWidth":38.4,
"graphicHeight":38.4,
"id":"sn_sunny_copy68",
"strokeLinecap":"round",
"strokeOpacity":1,
"fillOpacity":1,
"pointRadius":0}
)
These markers are easily draggable using the existing
OpenLayers.Feature.Vector dragging tools.
> I guess my question is, coming from a Google Maps 2 world, it seems like
> a GMarker is more like an OpenLayers.Marker except for being able to
> drag it around, in which case it looks like I should use
> OpenLayers.Features instead for everything.
Note that OpenLayers.Feature in and of itself doesn't get you
draggability: just OpenLayers.Feature.*Vector* does. But yes.
> 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).
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.
> 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.
Hope this helps,
--
Christopher Schmidt
MetaCarta
More information about the Users
mailing list