]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Layer/Markers.js
Add google webmaster tools authorisation file.
[rails.git] / public / lib / OpenLayers / Layer / Markers.js
1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3  * text of the license. */
4 // @require: OpenLayers/Layer.js
5 /**
6 * @class
7 */
8 OpenLayers.Layer.Markers = Class.create();
9 OpenLayers.Layer.Markers.prototype = 
10   Object.extend( new OpenLayers.Layer(), {
11     
12     /** internal marker list
13     * @type Array(OpenLayers.Marker) */
14     markers: null,
15     
16     /**
17     * @constructor
18     *
19     * @param {String} name
20     */
21     initialize: function(name) {
22         OpenLayers.Layer.prototype.initialize.apply(this, arguments);
23         this.markers = new Array();
24     },
25     
26     /**
27      * 
28      */
29     destroy: function() {
30         this.clearMarkers();
31         markers = null;
32         OpenLayers.Layer.prototype.destroy.apply(this, arguments);
33     },
34
35     
36     /** 
37     * @param {OpenLayers.Bounds} bounds
38     * @param {Boolean} zoomChanged
39     */
40     moveTo: function(bounds, zoomChanged) {
41         if (zoomChanged) {
42             this.redraw();
43         }
44     },
45     
46     /** WFS layer is never a base class. 
47      * @type Boolean
48      */
49     isBaseLayer: function() {
50         return false;
51     },
52     
53     /**
54     * @param {OpenLayers.Marker} marker
55     */
56     addMarker: function(marker) {
57         this.markers.append(marker);
58         if (this.map && this.map.getExtent()) {
59             marker.map = this.map;
60             this.drawMarker(marker);
61         }
62     },
63
64     /**
65      * @param {OpenLayers.Marker} marker
66      */
67     removeMarker: function(marker) {
68         this.markers.remove(marker);
69         if ((marker.icon != null) && (marker.icon.imageDiv != null) &&
70             (marker.icon.imageDiv.parentNode == this.div) ) {
71             this.div.removeChild(marker.icon.imageDiv);    
72         }
73     },
74
75     /**
76      * 
77      */
78     clearMarkers: function() {
79         if (this.markers != null) {
80             while(this.markers.length > 0) {
81                 this.removeMarker(this.markers[0]);
82             }
83         }
84     },
85
86     /** clear all the marker div's from the layer and then redraw all of them.
87     *    Use the map to recalculate new placement of markers.
88     */
89     redraw: function() {
90         for(i=0; i < this.markers.length; i++) {
91             this.drawMarker(this.markers[i]);
92         }
93     },
94
95     /** Calculate the pixel location for the marker, create it, and 
96     *    add it to the layer's div
97     * 
98     * @private 
99     * 
100     * @param {OpenLayers.Marker} marker
101     */
102     drawMarker: function(marker) {
103         var px = this.map.getLayerPxFromLonLat(marker.lonlat);
104         var markerImg = marker.draw(px);
105         if (!marker.drawn) {
106             this.div.appendChild(markerImg);
107             marker.drawn = true;
108         }
109     },
110     
111     /** @final @type String */
112     CLASS_NAME: "OpenLayers.Layer.Markers"
113 });