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. */
7 OpenLayers.Icon = Class.create();
8 OpenLayers.Icon.prototype = {
14 /** @type OpenLayers.Size */
17 /** distance in pixels to offset the image when being rendered
18 * @type OpenLayers.Pixel */
21 /** Function to calculate the offset (based on the size)
22 * @type OpenLayers.Pixel */
23 calculateOffset: null,
25 /** @type DOMElement */
28 /** @type OpenLayers.Pixel */
35 * @param {OpenLayers.Size} size
36 * @param {Function} calculateOffset
38 initialize: function(url, size, offset, calculateOffset) {
40 this.size = (size) ? size : new OpenLayers.Size(20,20);
41 this.offset = (offset) ? offset : new OpenLayers.Pixel(0,0);
42 this.calculateOffset = calculateOffset;
44 this.imageDiv = OpenLayers.Util.createAlphaImageDiv();
52 * @returns A fresh copy of the icon.
53 * @type OpenLayers.Icon
56 return new OpenLayers.Icon(this.size, this.url, this.offset);
60 * @param {OpenLayers.Size} size
62 setSize: function(size) {
70 * @param {OpenLayers.Pixel} px
72 * @return A new DOM Image of this icon set at the location passed-in
76 OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,
87 * @param {OpenLayers.Pixel} px
89 moveTo: function (px) {
90 //if no px passed in, use stored location
95 if ((this.px != null) && (this.imageDiv != null)) {
96 if (this.calculateOffset) {
97 this.offset = this.calculateOffset(this.size);
99 var offsetPx = this.px.offset(this.offset);
100 OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx);
104 /** @final @type String */
105 CLASS_NAME: "OpenLayers.Icon"