[OpenLayers-Users] marker label?
Matt H.
matt1767 at hotmail.com
Tue Nov 18 05:22:56 EST 2008
Code provided by Linda doesn't work for me with OpenLayers 2.8
This one work fine (tested on FF3 & IE7):
/**
* @requires OpenLayers/Marker.js
*
* Class: OpenLayers.Marker.LabelMarker
*
* Inherits from:
* - <OpenLayers.Marker>
*/
OpenLayers.Marker.LabelMarker = OpenLayers.Class(OpenLayers.Marker, {
/**
* Property: label
* {String} Marker label.
*/
label: "",
markerDiv: null,
initialize: function(lonlat, icon, label) {
OpenLayers.Marker.prototype.initialize.apply(this, [lonlat, icon]);
this.label = label;
this.markerDiv = OpenLayers.Util.createDiv();
this.markerDiv.appendChild(this.icon.imageDiv);
var txtDiv = OpenLayers.Util.createDiv();
txtDiv.className = 'markerLabel';
OpenLayers.Util.modifyDOMElement(txtDiv, null, new
OpenLayers.Pixel(0, this.icon.size.h));
txtDiv.innerHTML = this.label;
this.markerDiv.appendChild(txtDiv);
},
/**
* Method: destroy
* Nullify references and remove event listeners to prevent circular
* references and memory leaks
*/
destroy: function() {
OpenLayers.Marker.prototype.destroy.apply(this, arguments);
this.markerDiv.innerHTML = "";
this.markerDiv = null;
},
draw: function(px) {
OpenLayers.Util.modifyAlphaImageDiv(this.icon.imageDiv,
null,
null,
this.icon.size,
this.icon.url);
OpenLayers.Util.modifyDOMElement(this.markerDiv, null, px);
return this.markerDiv;
},
redraw: function(px) {
if ((px != null) && (this.markerDiv != null)) {
OpenLayers.Util.modifyDOMElement(this.markerDiv, null, px);
}
},
moveTo: function (px) {
this.redraw(px);
this.lonlat = this.map.getLonLatFromLayerPx(px);
},
isDrawn: function() {
return false;
},
CLASS_NAME: "OpenLayers.Marker.LabelMarker"
});
--
View this message in context: http://www.nabble.com/marker-label--tp19664832p20556852.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list