diff --git a/lib/OpenLayers/Icon.js b/lib/OpenLayers/Icon.js index 88d724d58a..7cb7b143fa 100644 --- a/lib/OpenLayers/Icon.js +++ b/lib/OpenLayers/Icon.js @@ -15,6 +15,9 @@ OpenLayers.Icon.prototype = { * @type OpenLayers.Pixel */ offset: null, + /** @type DOMElement */ + image: null, + /** * @constructor * @@ -27,6 +30,13 @@ OpenLayers.Icon.prototype = { this.url = url; this.offset = (offset) ? offset : new OpenLayers.Pixel(0,0); + + this.image = OpenLayers.Util.createAlphaImageDiv(null, + null, + this.size, + this.url, + "absolute" + ); }, /** @@ -37,6 +47,28 @@ OpenLayers.Icon.prototype = { return new OpenLayers.Icon(this.size, this.url, this.offset); }, + /** + * @param {OpenLayers.Pixel} px + * + * @return A new DOM Image of this icon set at the location passed-in + * @type DOMElement + */ + draw: function(px) { + this.moveTo(px); + return this.image; + }, + + /** + * @param {OpenLayers.Pixel} px + */ + moveTo: function (px) { + if ((px != null) && (this.image != null)) { + offsetPx = px.offset(this.offset); + this.image.style.left = offsetPx.x + "px"; + this.image.style.top = offsetPx.y + "px" + } + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Icon" }; \ No newline at end of file diff --git a/lib/OpenLayers/Marker.js b/lib/OpenLayers/Marker.js index 08b5f70a7d..cfc0b9237d 100644 --- a/lib/OpenLayers/Marker.js +++ b/lib/OpenLayers/Marker.js @@ -17,9 +17,6 @@ OpenLayers.Marker.prototype = { /** @type OpenLayers.Map */ map: null, - /** @type DOMElement */ - image: null, - /** * @constructor * @@ -28,16 +25,9 @@ OpenLayers.Marker.prototype = { */ initialize: function(lonlat, icon) { this.lonlat = lonlat; - this.icon = (icon) ? icon : OpenLayers.Marker.defaultIcon(); - this.image = OpenLayers.Util.createAlphaImageDiv(null, - null, - this.icon.size, - this.icon.url, - "absolute" - ); - this.events = new OpenLayers.Events(this, this.image, null); + this.events = new OpenLayers.Events(this, this.icon.image, null); }, /** @@ -48,18 +38,16 @@ OpenLayers.Marker.prototype = { * @type DOMElement */ draw: function(px) { - this.moveTo(px); - return this.image; + return this.icon.draw(px); }, /** * @param {OpenLayers.Pixel} px */ moveTo: function (px) { - if ((px != null) && (this.image != null)) { - this.image.style.top = (px.y + this.icon.offset.y) + "px" - this.image.style.left = (px.x + this.icon.offset.x) + "px"; - } + if ((px != null) && (this.icon != null)) { + this.icon.moveTo(px); + } }, /** @final @type String */