1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
7 * @requires OpenLayers/Util.js
8 * @requires OpenLayers/Marker.js
9 * @requires OpenLayers/Popup/AnchoredBubble.js
13 * Class: OpenLayers.Feature
14 * Features are combinations of geography and attributes. The OpenLayers.Feature
15 * class specifically combines a marker and a lonlat.
17 OpenLayers.Feature = OpenLayers.Class({
21 * {<OpenLayers.Layer>}
33 * {<OpenLayers.LonLat>}
45 * {<OpenLayers.Marker>}
50 * APIProperty: popupClass
51 * {<OpenLayers.Class>} The class which will be used to instantiate
52 * a new Popup. Default is <OpenLayers.Popup.AnchoredBubble>.
54 popupClass: OpenLayers.Popup.AnchoredBubble,
58 * {<OpenLayers.Popup>}
63 * Constructor: OpenLayers.Feature
64 * Constructor for features.
67 * layer - {<OpenLayers.Layer>}
68 * lonlat - {<OpenLayers.LonLat>}
72 * {<OpenLayers.Feature>}
74 initialize: function(layer, lonlat, data) {
77 this.data = (data != null) ? data : {};
78 this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
83 * nullify references to prevent circular references and memory leaks
87 //remove the popup from the map
88 if ((this.layer != null) && (this.layer.map != null)) {
89 if (this.popup != null) {
90 this.layer.map.removePopup(this.popup);
98 if (this.marker != null) {
99 this.destroyMarker(this.marker);
102 if (this.popup != null) {
103 this.destroyPopup(this.popup);
112 * {Boolean} Whether or not the feature is currently visible on screen
113 * (based on its 'lonlat' property)
115 onScreen:function() {
117 var onScreen = false;
118 if ((this.layer != null) && (this.layer.map != null)) {
119 var screenBounds = this.layer.map.getExtent();
120 onScreen = screenBounds.containsLonLat(this.lonlat);
127 * Method: createMarker
128 * Based on the data associated with the Feature, create and return a marker object.
131 * {<OpenLayers.Marker>} A Marker Object created from the 'lonlat' and 'icon' properties
132 * set in this.data. If no 'lonlat' is set, returns null. If no
133 * 'icon' is set, OpenLayers.Marker() will load the default image.
135 * Note - this.marker is set to return value
138 createMarker: function() {
140 if (this.lonlat != null) {
141 this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon);
147 * Method: destroyMarker
149 * If user overrides the createMarker() function, s/he should be able
150 * to also specify an alternative function for destroying it
152 destroyMarker: function() {
153 this.marker.destroy();
157 * Method: createPopup
158 * Creates a popup object created from the 'lonlat', 'popupSize',
159 * and 'popupContentHTML' properties set in this.data. It uses
160 * this.marker.icon as default anchor.
162 * If no 'lonlat' is set, returns null.
163 * If no this.marker has been created, no anchor is sent.
165 * Note - the returned popup object is 'owned' by the feature, so you
166 * cannot use the popup's destroy method to discard the popup.
167 * Instead, you must use the feature's destroyPopup
169 * Note - this.popup is set to return value
172 * closeBox - {Boolean} create popup with closebox or not
175 * {<OpenLayers.Popup>} Returns the created popup, which is also set
176 * as 'popup' property of this feature. Will be of whatever type
177 * specified by this feature's 'popupClass' property, but must be
178 * of type <OpenLayers.Popup>.
181 createPopup: function(closeBox) {
183 if (this.lonlat != null) {
185 var id = this.id + "_popup";
186 var anchor = (this.marker) ? this.marker.icon : null;
189 this.popup = new this.popupClass(id,
192 this.data.popupContentHTML,
196 if (this.data.overflow != null) {
197 this.popup.contentDiv.style.overflow = this.data.overflow;
200 this.popup.feature = this;
207 * Method: destroyPopup
208 * Destroys the popup created via createPopup.
210 * As with the marker, if user overrides the createPopup() function, s/he
211 * should also be able to override the destruction
213 destroyPopup: function() {
215 this.popup.feature = null;
216 this.popup.destroy();
221 CLASS_NAME: "OpenLayers.Feature"