[OpenLayers-Users] Having difficulty creating my own feature layer....
nick@hogweed.org
nick at hogweed.org
Tue Jun 20 05:25:13 CDT 2006
Related to my OpenStreetMap/OpenLayers project (see posts last week) I am
trying to create my own layer to represent map annotations. At the moment the
server-side component of the layer is very basic: all it does is return the
lats and longs of each annotation in a semicolon-separated list e.g.
http://nick.dev.openstreetmap.org/openlayers/markers2.php?bbox=-1,51,0,52
What I want to do is to plot these lats and longs on the map as markers. To do
this, I have used the OpenLayers WFS code as a basis.
I have modified two classes: OpenLayers.Layer.WFS and OpenLayers.Tile.WFS. The
layer class is virtually unchanged: the only real change is that it now calls
my tile class (see below) to get its tiles rather than the WFS tile class.
The tile class is more seriously altered: it contacts my annotation server
(see above) and parses the data returned, attempting to plot the lats and
longs as markers.
However I can't get it to work. I get the lats and longs returned over AJAX
ok, but the problem is adding the markers to the map. I have to admit I'm not
terribly familiar with some of the more advanced JS library features used
(the slightly strange 'inheritance' model, the 'apply()' method, etc) but by
looking at the OpenLayers code I thought I may have figured it out. However,
maybe not: I tried to use the code below to call the addMarker() method of
the Layer.Markers class (which my layer class 'inherits' from...) to add
markers to the layer:
var a = new Array();
a[0] = new OpenLayers.Marker
(lonLat,newOpenLayers.Icon('images/amenity.png'));
OpenLayers.Layer.Markers.prototype.addMarker.apply(this,a);
However, doing that I get an error: "this.markers has no properties" in the
file http://openlayers.org/dev/lib/OpenLayers/Layer/Markers.js
My full source code for my custom classes is at:
http://nick.dev.openstreetmap.org/openlayers/osmlayer.js (the layer);
http://nick.dev.openstreetmap.org/openlayers/osmtile.js (the tile)
I guess I must have misunderstood a small point of detail, so any pointers
would be gratefully received :-) Would also be good to get some feedback on
whether the way I'm doing it is "correct" from an OpenLayers library design
point of view, as there is always the possibility of merging the code back
into the openlayers library itself.
Thanks,
Nick
More information about the Users
mailing list