has been done in the NaturalDocs branch back to trunk. Thanks to everyone who helped out in making this happen. (I could list people, but the list would be long, and I'm already mentally on vacation.) git-svn-id: http://svn.openlayers.org/trunk/openlayers@3545 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
209 lines
5.3 KiB
JavaScript
209 lines
5.3 KiB
JavaScript
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
|
|
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
|
* for the full text of the license. */
|
|
|
|
|
|
/**
|
|
* @requires OpenLayers/Util.js
|
|
* @requires OpenLayers/Marker.js
|
|
*
|
|
* Class: OpenLayers.Feature
|
|
* Features are combinations of geography and attributes. The OpenLayers.Feature
|
|
* class specifically combines a marker and a lonlat.
|
|
*/
|
|
OpenLayers.Feature = OpenLayers.Class.create();
|
|
OpenLayers.Feature.prototype= {
|
|
|
|
/**
|
|
* Property: events
|
|
* {<OpenLayers.Events>}
|
|
*/
|
|
events: null,
|
|
|
|
/**
|
|
* Property: layer
|
|
* {<OpenLayers.Layer>}
|
|
*/
|
|
layer: null,
|
|
|
|
/**
|
|
* Property: id
|
|
* {String}
|
|
*/
|
|
id: null,
|
|
|
|
/**
|
|
* Property: lonlat
|
|
* {<OpenLayers.LonLat>}
|
|
*/
|
|
lonlat: null,
|
|
|
|
/**
|
|
* Property: data
|
|
* {Object}
|
|
*/
|
|
data: null,
|
|
|
|
/**
|
|
* Property: marker
|
|
* {<OpenLayers.Marker>}
|
|
*/
|
|
marker: null,
|
|
|
|
/**
|
|
* Property: popup
|
|
* {<OpenLayers.Popup>}
|
|
*/
|
|
popup: null,
|
|
|
|
/**
|
|
* Constructor: OpenLayers.Feature
|
|
* Constructor for features.
|
|
*
|
|
* Parameters:
|
|
* layer - {<OpenLayers.Layer>}
|
|
* lonlat - {<OpenLayers.LonLat>}
|
|
* data - {Object}
|
|
*
|
|
* Return:
|
|
* {<OpenLayers.Feature>}
|
|
*/
|
|
initialize: function(layer, lonlat, data) {
|
|
this.layer = layer;
|
|
this.lonlat = lonlat;
|
|
this.data = (data != null) ? data : new Object();
|
|
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
|
|
},
|
|
|
|
/**
|
|
* Method: destroy
|
|
* nullify references to prevent circular references and memory leaks
|
|
*/
|
|
destroy: function() {
|
|
|
|
//remove the popup from the map
|
|
if ((this.layer != null) && (this.layer.map != null)) {
|
|
if (this.popup != null) {
|
|
this.layer.map.removePopup(this.popup);
|
|
}
|
|
}
|
|
|
|
if (this.events) {
|
|
this.events.destroy();
|
|
}
|
|
this.events = null;
|
|
|
|
this.layer = null;
|
|
this.id = null;
|
|
this.lonlat = null;
|
|
this.data = null;
|
|
if (this.marker != null) {
|
|
this.destroyMarker(this.marker);
|
|
this.marker = null;
|
|
}
|
|
if (this.popup != null) {
|
|
this.destroyPopup(this.popup);
|
|
this.popup = null;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Method: onScreen
|
|
*
|
|
* Returns:
|
|
* {Boolean} Whether or not the feature is currently visible on screen
|
|
* (based on its 'lonlat' property)
|
|
*/
|
|
onScreen:function() {
|
|
|
|
var onScreen = false;
|
|
if ((this.layer != null) && (this.layer.map != null)) {
|
|
var screenBounds = this.layer.map.getExtent();
|
|
onScreen = screenBounds.containsLonLat(this.lonlat);
|
|
}
|
|
return onScreen;
|
|
},
|
|
|
|
|
|
/**
|
|
* Method: createMarker
|
|
* Based on the data associated with the Feature, create and return a marker object.
|
|
*
|
|
* Return:
|
|
* {<OpenLayers.Marker>} A Marker Object created from the 'lonlat' and 'icon' properties
|
|
* set in this.data. If no 'lonlat' is set, returns null. If no
|
|
* 'icon' is set, OpenLayers.Marker() will load the default image.
|
|
*
|
|
* Note - this.marker is set to return value
|
|
*
|
|
*/
|
|
createMarker: function() {
|
|
|
|
var marker = null;
|
|
|
|
if (this.lonlat != null) {
|
|
this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon);
|
|
}
|
|
return this.marker;
|
|
},
|
|
|
|
/**
|
|
* Method: destroyMarker
|
|
* Destroys marker.
|
|
* If user overrides the createMarker() function, s/he should be able
|
|
* to also specify an alternative function for destroying it
|
|
*/
|
|
destroyMarker: function() {
|
|
this.marker.destroy();
|
|
},
|
|
|
|
/**
|
|
* Method: createPopup
|
|
* Creates a popup object created from the 'lonlat', 'popupSize',
|
|
* and 'popupContentHTML' properties set in this.data. It uses
|
|
* this.marker.icon as default anchor.
|
|
*
|
|
* If no 'lonlat' is set, returns null.
|
|
* If no this.marker has been created, no anchor is sent.
|
|
*
|
|
* Note - this.popup is set to return value
|
|
*
|
|
* Parameters:
|
|
* closeBox - {Boolean} create popup with closebox or not
|
|
*
|
|
* Returns:
|
|
* {<OpenLayers.Popup.AnchoredBubble>}
|
|
*
|
|
*/
|
|
createPopup: function(closeBox) {
|
|
|
|
if (this.lonlat != null) {
|
|
|
|
var id = this.id + "_popup";
|
|
var anchor = (this.marker) ? this.marker.icon : null;
|
|
|
|
this.popup = new OpenLayers.Popup.AnchoredBubble(id,
|
|
this.lonlat,
|
|
this.data.popupSize,
|
|
this.data.popupContentHTML,
|
|
anchor, closeBox);
|
|
}
|
|
return this.popup;
|
|
},
|
|
|
|
|
|
/**
|
|
* Method: destroyPopup
|
|
* Destroys the popup created via createPopup.
|
|
*
|
|
* As with the marker, if user overrides the createPopup() function, s/he
|
|
* should also be able to override the destruction
|
|
*/
|
|
destroyPopup: function() {
|
|
this.popup.destroy()
|
|
},
|
|
|
|
/** @final @type String */
|
|
CLASS_NAME: "OpenLayers.Feature"
|
|
};
|