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