[OpenLayers-Users] Having difficulty creating my own feature layer....

Paul Spencer pspencer at dmsolutions.ca
Tue Jun 20 06:56:09 CDT 2006


Nick,

I'm not that familiar with the openlayers code yet, but it seems to  
me that you need to call this.layer.addMarker(a)

 From what I understand, the syntax that invokes  
xxx.prototype.xxx.apply(this, ...) is used to call base-class  
functions that have the same name as a sub-class function name.  In  
javascript, there is no concept of a super class so you have to  
resort to 'tricks' like this.

The addMarker method is a method of the Markers layer type.  Since  
Layer.OSMtest extends Markers, you automatically gain an addMarker  
method in OSMtest.

Your call to addMarker is coming from Tile.OSMtest.  Tile has a  
member variable layer which points to the layer containing the tile.   
Therefore you can call addMarker directly.

You would have needed to use the prototype/apply thing if you had  
defined an addMarker function in your Layer.OSMtest but actually  
needed to call addMarker in the Layers.Markers code.

Um.  Not sure if that explains things very well.  It all makes sense  
in my head, though :)

Cheers

Paul


On 20-Jun-06, at 6:25 AM, nick at hogweed.org wrote:

>
> 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
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://mailman-viper.python-hosting.com/listinfo/users

+-----------------------------------------------------------------+
|Paul Spencer                           pspencer at dmsolutions.ca   |
+-----------------------------------------------------------------+
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
+-----------------------------------------------------------------+






More information about the Users mailing list