git-svn-id: http://svn.openlayers.org/trunk/openlayers@3767 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
319 lines
8.5 KiB
JavaScript
319 lines
8.5 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. */
|
|
|
|
// TRASH THIS
|
|
OpenLayers.State = {
|
|
/** states */
|
|
UNKNOWN: 'Unknown',
|
|
INSERT: 'Insert',
|
|
UPDATE: 'Update',
|
|
DELETE: 'Delete'
|
|
}
|
|
|
|
/**
|
|
* @requires OpenLayers/Feature.js
|
|
* @requires OpenLayers/Util.js
|
|
*
|
|
* Class: OpenLayers.Feature.Vector
|
|
* Vector features use the OpenLayers.Geometry classes as geometry description.
|
|
* They have an 'attributes' property, which is the data object, and a 'style'
|
|
* property, the default values of which are defined in the
|
|
* <OpenLayers.Feature.Vector.style> objects.
|
|
*
|
|
* Inherits from:
|
|
* - <OpenLayers.Feature>
|
|
*/
|
|
OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
|
|
|
|
/**
|
|
* Property: fid
|
|
* {String}
|
|
*/
|
|
fid: null,
|
|
|
|
/**
|
|
* APIProperty: geometry
|
|
* {<OpenLayers.Geometry>}
|
|
*/
|
|
geometry: null,
|
|
|
|
/**
|
|
* APIProperty: attributes
|
|
* {Object} This object holds arbitrary properties that describe the
|
|
* feature.
|
|
*/
|
|
attributes: null,
|
|
|
|
/**
|
|
* Property: state
|
|
* {String}
|
|
*/
|
|
state: null,
|
|
|
|
/**
|
|
* APIProperty: style
|
|
* {Object}
|
|
*/
|
|
style: null,
|
|
|
|
/**
|
|
* Constructor: OpenLayers.Feature.Vector
|
|
* Create a vector feature.
|
|
*
|
|
* Parameters:
|
|
* geometry - {<OpenLayers.Geometry>} The geometry that this feature
|
|
* represents.
|
|
* attributes - {Object} An optional object that will be mapped to the
|
|
* <attributes> property.
|
|
* style - {Object} An optional style object.
|
|
*/
|
|
initialize: function(geometry, attributes, style) {
|
|
OpenLayers.Feature.prototype.initialize.apply(this,
|
|
[null, null, attributes]);
|
|
this.lonlat = null;
|
|
this.geometry = geometry;
|
|
this.state = null;
|
|
this.attributes = new Object();
|
|
if (attributes) {
|
|
this.attributes = OpenLayers.Util.extend(this.attributes,
|
|
attributes);
|
|
}
|
|
this.style = style ? style : null;
|
|
},
|
|
|
|
/**
|
|
* Method: destroy
|
|
* nullify references to prevent circular references and memory leaks
|
|
*/
|
|
destroy: function() {
|
|
if (this.layer) {
|
|
this.layer.removeFeatures(this);
|
|
this.layer = null;
|
|
}
|
|
|
|
this.geometry = null;
|
|
OpenLayers.Feature.prototype.destroy.apply(this, arguments);
|
|
},
|
|
|
|
/**
|
|
* Method: clone
|
|
*
|
|
* Returns:
|
|
* <OpenLayers.Feature> An exact clone of this OpenLayers.Feature
|
|
*/
|
|
clone: function (obj) {
|
|
if (obj == null) {
|
|
obj = new OpenLayers.Feature(null, this.geometry.clone(), this.data);
|
|
}
|
|
|
|
// catch any randomly tagged-on properties
|
|
OpenLayers.Util.applyDefaults(obj, this);
|
|
|
|
return obj;
|
|
},
|
|
|
|
/**
|
|
* Method: onScreen
|
|
* HACK - we need to rewrite this for non-point geometry
|
|
*
|
|
* Return:
|
|
* {Boolean} For now just returns null
|
|
*/
|
|
onScreen:function() {
|
|
return null;
|
|
},
|
|
|
|
/**
|
|
* Method: createMarker
|
|
* HACK - we need to decide if all vector features should be able to
|
|
* create markers
|
|
*
|
|
* Return:
|
|
* {<OpenLayers.Marker>} For now just returns null
|
|
*/
|
|
createMarker: function() {
|
|
return null;
|
|
},
|
|
|
|
/**
|
|
* Method: destroyMarker
|
|
* HACK - we need to decide if all vector features should be able to
|
|
* delete markers
|
|
*
|
|
* If user overrides the createMarker() function, s/he should be able
|
|
* to also specify an alternative function for destroying it
|
|
*/
|
|
destroyMarker: function() {
|
|
// pass
|
|
},
|
|
|
|
/**
|
|
* Method: createPopup
|
|
* HACK - we need to decide if all vector features should be able to
|
|
* create popups
|
|
*
|
|
* Return:
|
|
* {<OpenLayers.Popup>} For now just returns null
|
|
*/
|
|
createPopup: function() {
|
|
return null;
|
|
},
|
|
|
|
/**
|
|
* Method: atPoint
|
|
* Determins whether the feature intersects with the specified location.
|
|
*
|
|
* Parameters:
|
|
* lonlat - {<OpenLayers.LonLat>}
|
|
* toleranceLon - {float} Optional tolerance in Geometric Coords
|
|
* toleranceLat - {float} Optional tolerance in Geographic Coords
|
|
*
|
|
* Returns:
|
|
* {Boolean} Whether or not the feature is at the specified location
|
|
*/
|
|
atPoint: function(lonlat, toleranceLon, toleranceLat) {
|
|
var atPoint = false;
|
|
if(this.geometry) {
|
|
atPoint = this.geometry.atPoint(lonlat, toleranceLon,
|
|
toleranceLat);
|
|
}
|
|
return atPoint;
|
|
},
|
|
|
|
/**
|
|
* Method: destroyPopup
|
|
* HACK - we need to decide if all vector features should be able to
|
|
* delete popups
|
|
*/
|
|
destroyPopup: function() {
|
|
// pass
|
|
},
|
|
|
|
/**
|
|
* Method: toState
|
|
* Sets the new state
|
|
*
|
|
* Parameters:
|
|
* state - {String}
|
|
*/
|
|
toState: function(state) {
|
|
if (state == OpenLayers.State.UPDATE) {
|
|
switch (this.state) {
|
|
case OpenLayers.State.UNKNOWN:
|
|
case OpenLayers.State.DELETE:
|
|
this.state = state;
|
|
break;
|
|
case OpenLayers.State.UPDATE:
|
|
case OpenLayers.State.INSERT:
|
|
break;
|
|
}
|
|
} else if (state == OpenLayers.State.INSERT) {
|
|
switch (this.state) {
|
|
case OpenLayers.State.UNKNOWN:
|
|
break;
|
|
default:
|
|
this.state = state;
|
|
break;
|
|
}
|
|
} else if (state == OpenLayers.State.DELETE) {
|
|
switch (this.state) {
|
|
case OpenLayers.State.INSERT:
|
|
// the feature should be destroyed
|
|
break;
|
|
case OpenLayers.State.DELETE:
|
|
break;
|
|
case OpenLayers.State.UNKNOWN:
|
|
case OpenLayers.State.UPDATE:
|
|
this.state = state;
|
|
break;
|
|
}
|
|
} else if (state == OpenLayers.State.UNKNOWN) {
|
|
this.state = state;
|
|
}
|
|
},
|
|
|
|
CLASS_NAME: "OpenLayers.Feature.Vector"
|
|
});
|
|
|
|
|
|
/*
|
|
* Constant: OpenLayers.Feature.Vector.style
|
|
* OpenLayers features can have a number of
|
|
* style attributes. The 'default' style will
|
|
* typically be used if no other style is specified.
|
|
*
|
|
* Default style properties:
|
|
*
|
|
* - fillColor: "#ee9900",
|
|
* - fillOpacity: 0.4,
|
|
* - hoverFillColor: "white",
|
|
* - hoverFillOpacity: 0.8,
|
|
* - strokeColor: "#ee9900",
|
|
* - strokeOpacity: 1,
|
|
* - strokeWidth: 1,
|
|
* - strokeLinecap: "round",
|
|
* - hoverStrokeColor: "red",
|
|
* - hoverStrokeOpacity: 1,
|
|
* - hoverStrokeWidth: 0.2,
|
|
* - pointRadius: 6,
|
|
* - hoverPointRadius: 1,
|
|
* - hoverPointUnit: "%",
|
|
* - pointerEvents: "visiblePainted"
|
|
*/
|
|
|
|
OpenLayers.Feature.Vector.style = {
|
|
'default': {
|
|
fillColor: "#ee9900",
|
|
fillOpacity: 0.4,
|
|
hoverFillColor: "white",
|
|
hoverFillOpacity: 0.8,
|
|
strokeColor: "#ee9900",
|
|
strokeOpacity: 1,
|
|
strokeWidth: 1,
|
|
strokeLinecap: "round",
|
|
hoverStrokeColor: "red",
|
|
hoverStrokeOpacity: 1,
|
|
hoverStrokeWidth: 0.2,
|
|
pointRadius: 6,
|
|
hoverPointRadius: 1,
|
|
hoverPointUnit: "%",
|
|
pointerEvents: "visiblePainted"
|
|
},
|
|
'select': {
|
|
fillColor: "blue",
|
|
fillOpacity: 0.4,
|
|
hoverFillColor: "white",
|
|
hoverFillOpacity: 0.8,
|
|
strokeColor: "blue",
|
|
strokeOpacity: 1,
|
|
strokeWidth: 2,
|
|
strokeLinecap: "round",
|
|
hoverStrokeColor: "red",
|
|
hoverStrokeOpacity: 1,
|
|
hoverStrokeWidth: 0.2,
|
|
pointRadius: 6,
|
|
hoverPointRadius: 1,
|
|
hoverPointUnit: "%",
|
|
pointerEvents: "visiblePainted",
|
|
cursor: "pointer"
|
|
},
|
|
'temporary': {
|
|
fillColor: "yellow",
|
|
fillOpacity: 0.2,
|
|
hoverFillColor: "white",
|
|
hoverFillOpacity: 0.8,
|
|
strokeColor: "yellow",
|
|
strokeOpacity: 1,
|
|
strokeLinecap: "round",
|
|
strokeWidth: 4,
|
|
hoverStrokeColor: "red",
|
|
hoverStrokeOpacity: 1,
|
|
hoverStrokeWidth: 0.2,
|
|
pointRadius: 6,
|
|
hoverPointRadius: 1,
|
|
hoverPointUnit: "%",
|
|
pointerEvents: "visiblePainted"
|
|
}
|
|
};
|