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
8 OpenLayers.Layer.Markers = Class.create();
9 OpenLayers.Layer.Markers.prototype =
10 Object.extend( new OpenLayers.Layer(), {
12 /** internal marker list
13 * @type Array(OpenLayers.Marker) */
19 * @param {String} name
21 initialize: function(name) {
22 OpenLayers.Layer.prototype.initialize.apply(this, arguments);
23 this.markers = new Array();
32 OpenLayers.Layer.prototype.destroy.apply(this, arguments);
37 * @param {OpenLayers.Bounds} bounds
38 * @param {Boolean} zoomChanged
40 moveTo: function(bounds, zoomChanged) {
46 /** WFS layer is never a base class.
49 isBaseLayer: function() {
54 * @param {OpenLayers.Marker} marker
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);
65 * @param {OpenLayers.Marker} marker
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);
78 clearMarkers: function() {
79 if (this.markers != null) {
80 while(this.markers.length > 0) {
81 this.removeMarker(this.markers[0]);
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.
90 for(i=0; i < this.markers.length; i++) {
91 this.drawMarker(this.markers[i]);
95 /** Calculate the pixel location for the marker, create it, and
96 * add it to the layer's div
100 * @param {OpenLayers.Marker} marker
102 drawMarker: function(marker) {
103 var px = this.map.getLayerPxFromLonLat(marker.lonlat);
104 var markerImg = marker.draw(px);
106 this.div.appendChild(markerImg);
111 /** @final @type String */
112 CLASS_NAME: "OpenLayers.Layer.Markers"