Create a single HTML object, and modify its style attributes to move it whenever generate is called -- this will hopefully allow us to add events to it. Note that the event registration in this code currently fails: wehn triggerEvent is called, this.listeners['click'] is called, which is something I have not yet been able to fully understand.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@133 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-18 11:22:49 +00:00
parent b4f80c494c
commit 575474654b

View File

@@ -18,7 +18,10 @@ OpenLayers.Marker.prototype = {
/** @type OpenLayers.Map */
map: null,
object: null,
events:null,
/**
* @param {OpenLayers.Icon} icon
* @param {OpenLayers.LonLat lonlat
@@ -26,6 +29,12 @@ OpenLayers.Marker.prototype = {
initialize: function(icon, lonlat) {
this.icon = icon;
this.lonlat = lonlat;
this.object = OpenLayers.Util.createImage(
this.icon.url,
this.icon.size
);
this.events = new OpenLayers.Events(this, this.object, null);
this.events.register("click", this, this.onclick );
},
/**
@@ -38,13 +47,14 @@ OpenLayers.Marker.prototype = {
generateMarker: function(pixel) {
// Create a div here, and set the location to the pixel above modified
// by the icon size.
var iconPosition = pixel.add(this.icon.offset.x, this.icon.offset.y);
var markerObject = OpenLayers.Util.createImage(this.icon.url,
this.icon.size,
iconPosition);
return markerObject;
},
this.object.style.top = (pixel.y+this.icon.offset.y) + "px"
this.object.style.left = (pixel.x+this.icon.offset.x) + "px";
this.object.onclick = this.onclick;
return this.object;
},
onclick: function(evt) {
alert('onclick');
}
/** @final @type String */
CLASS_NAME: "OpenLayers.Marker"
}