]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Icon.js
back out the registration of the gpx mime type, as it didn't seem work
[rails.git] / public / lib / OpenLayers / Icon.js
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 /**
5 * @class
6 */
7 OpenLayers.Icon = Class.create();
8 OpenLayers.Icon.prototype = {
9     
10     /** image url
11     * @type String */
12     url: null,
13     
14     /** @type OpenLayers.Size */
15     size:null,
16
17     /** distance in pixels to offset the image when being rendered
18     * @type OpenLayers.Pixel */
19     offset: null,    
20     
21     /** Function to calculate the offset (based on the size) 
22      * @type OpenLayers.Pixel */
23     calculateOffset: null,    
24     
25     /** @type DOMElement */
26     imageDiv: null,
27
28     /** @type OpenLayers.Pixel */
29     px: null,
30     
31     /** 
32     * @constructor
33     *
34     * @param {String} url
35     * @param {OpenLayers.Size} size
36     * @param {Function} calculateOffset
37     */
38     initialize: function(url, size, offset, calculateOffset) {
39         this.url = url;
40         this.size = (size) ? size : new OpenLayers.Size(20,20);
41         this.offset = (offset) ? offset : new OpenLayers.Pixel(0,0);
42         this.calculateOffset = calculateOffset;
43
44         this.imageDiv = OpenLayers.Util.createAlphaImageDiv();
45     },
46     
47     destroy: function() {
48         this.imageDiv = null;
49     },
50
51     /** 
52     * @returns A fresh copy of the icon.
53     * @type OpenLayers.Icon
54     */
55     clone: function() {
56         return new OpenLayers.Icon(this.size, this.url, this.offset);
57     },
58     
59     /**
60      * @param {OpenLayers.Size} size
61      */
62     setSize: function(size) {
63         if (size != null) {
64             this.size = size;
65         }
66         this.draw();
67     },
68
69     /** 
70     * @param {OpenLayers.Pixel} px
71     * 
72     * @return A new DOM Image of this icon set at the location passed-in
73     * @type DOMElement
74     */
75     draw: function(px) {
76         OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, 
77                                             null, 
78                                             null, 
79                                             this.size, 
80                                             this.url, 
81                                             "absolute");
82         this.moveTo(px);
83         return this.imageDiv;
84     }, 
85
86     /**
87     * @param {OpenLayers.Pixel} px
88     */
89     moveTo: function (px) {
90         //if no px passed in, use stored location
91         if (px != null) {
92             this.px = px;
93         }
94
95         if ((this.px != null) && (this.imageDiv != null)) {
96             if (this.calculateOffset) {
97                 this.offset = this.calculateOffset(this.size);  
98             }
99             var offsetPx = this.px.offset(this.offset);
100             OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx);
101         }
102     },
103     
104     /** @final @type String */
105     CLASS_NAME: "OpenLayers.Icon"
106 };