]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Feature.js
api06: Fix normal way and relation uploading (i.e. not as part of a diff).
[rails.git] / public / lib / OpenLayers / Feature.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.Feature = Class.create();
8 OpenLayers.Feature.prototype= {
9
10     /** @type OpenLayers.Events */
11     events:null,
12
13     /** @type OpenLayers.Layer */
14     layer: null,
15
16     /** @type String */
17     id: null,
18     
19     /** @type OpenLayers.LonLat */
20     lonlat:null,
21
22     /** @type Object */
23     data:null,
24
25     /** @type OpenLayers.Marker */
26     marker: null,
27
28     /** @type OpenLayers.Popup */
29     popup: null,
30
31     /** 
32      * @constructor
33      * 
34      * @param {OpenLayers.Layer} layer
35      * @param {String} id
36      * @param {OpenLayers.LonLat} lonlat
37      * @param {Object} data
38      */
39     initialize: function(layer, lonlat, data, id) {
40         this.layer = layer;
41         this.lonlat = lonlat;
42         this.data = (data != null) ? data : new Object();
43         this.id = (id ? id : 'f' + Math.random());
44     },
45
46     /**
47      * 
48      */
49     destroy: function() {
50
51         //remove the popup from the map
52         if ((this.layer != null) && (this.layer.map != null)) {
53             if (this.popup != null) {
54                 this.layer.map.removePopup(this.popup);
55             }
56         }
57
58         this.events = null;
59         this.layer = null;
60         this.id = null;
61         this.lonlat = null;
62         this.data = null;
63         if (this.marker != null) {
64             this.marker.destroy();
65             this.marker = null;
66         }
67         if (this.popup != null) {
68             this.popup.destroy();
69             this.popup = null;
70         }
71     },
72     
73
74     /**
75      * @returns A Marker Object created from the 'lonlat' and 'icon' properties
76      *          set in this.data. If no 'lonlat' is set, returns null. If no
77      *          'icon' is set, OpenLayers.Marker() will load the default image
78      * @type OpenLayers.Marker
79      */
80     createMarker: function() {
81
82         var marker = null;
83         
84         if (this.lonlat != null) {
85             this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon);
86         }
87         return this.marker;
88     },
89
90     /**
91      * 
92      */
93     createPopup: function() {
94
95         if (this.lonlat != null) {
96             
97             var id = this.id + "_popup";
98             var anchor = (this.marker) ? this.marker.icon : null;
99
100             this.popup = new OpenLayers.Popup.AnchoredBubble(id, 
101                                                     this.lonlat,
102                                                     this.data.popupSize,
103                                                     this.data.popupContentHTML,
104                                                     anchor); 
105         }        
106         return this.popup;
107     },
108
109     CLASS_NAME: "OpenLayers.Feature"
110 };