#628 - a feature has a geometry - a geometry doesn't have a feature - features are rendered, selected, moved, modified, etc - down in the renderer, expando properties on nodes are limited to _featureId, _style, and _options - this removes expandos that created circular references back through the map and to other dom elements - when the renderer is involved in selecting features, it returns a featureId (instead of a geometry or feature) and the layer is responsible for fetching the appropriate feature

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3043 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-04-10 16:07:56 +00:00
parent 8af1822d94
commit 645bff1286
21 changed files with 335 additions and 336 deletions

View File

@@ -21,18 +21,12 @@ OpenLayers.Layer.Vector.prototype =
/** @type Boolean */
isVector: true,
/** @type {Array(OpenLayer.Feature.Vector)} */
/** @type Array(OpenLayer.Feature.Vector) */
features: null,
/** @type {Array(OpenLayers.Feature.Vector)} */
/** @type Array(OpenLayers.Feature.Vector) */
selectedFeatures: [],
/** @type {Boolean} */
editing: false,
/** @type {Boolean} */
editable: false,
/** @type {Boolean} */
reportError: true,
@@ -75,6 +69,7 @@ OpenLayers.Layer.Vector.prototype =
* Options renderer {Object}: Typically SVGRenderer or VMLRenderer.
*/
initialize: function(name, options) {
this.style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
// allow user-set renderer, otherwise assign one
@@ -102,8 +97,6 @@ OpenLayers.Layer.Vector.prototype =
// calling feature[i].destroy() here.
this.features = null;
this.selectedFeatures = null;
this.editing = null;
this.editable = null;
if (this.renderer) {
this.renderer.destroy();
}
@@ -172,7 +165,7 @@ OpenLayers.Layer.Vector.prototype =
/** Reset the vector layer's div so that it once again is lined up with
* the map. Notify the renderer of the change of extent, and in the
* case of a change of zoom level (resolution), have the
* renderer reproject.
* renderer redraw features.
*
* If the layer has not yet been drawn, cycle through the layer's
* features and draw each one.
@@ -191,15 +184,11 @@ OpenLayers.Layer.Vector.prototype =
this.renderer.setExtent(extent);
}
if (zoomChanged) {
this.renderer.reproject();
}
if (!this.drawn) {
if (!this.drawn || zoomChanged) {
this.drawn = true;
for(var i = 0; i < this.features.length; i++) {
var feature = this.features[i];
this.renderer.drawGeometry(feature.geometry, feature.style);
this.drawFeature(feature);
}
}
},
@@ -228,17 +217,13 @@ OpenLayers.Layer.Vector.prototype =
feature.layer = this;
if (!feature.style) {
if (this.style) {
feature.style = OpenLayers.Util.extend({}, this.style);
} else {
feature.style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
}
feature.style = OpenLayers.Util.extend({}, this.style);
}
this.preFeatureInsert(feature);
if (this.drawn) {
this.renderer.drawGeometry(feature.geometry, feature.style);
this.drawFeature(feature);
}
this.onFeatureInsert(feature);
@@ -271,45 +256,57 @@ OpenLayers.Layer.Vector.prototype =
},
/**
* @param {String} fid
* Draw (or redraw) a feature on the layer. If the optional style argument
* is included, this style will be used. If no style is included, the
* feature's style will be used. If the feature doesn't have a style,
* the layer's style will be used.
*
* @param {OpenLayers.Feature.Vector} feature
* @param {Object} style
*/
redrawFeature: function(fid, style) {
for (var i = 0; i < this.features.length; i++) {
var feature = this.features[i];
if (feature.fid == fid) {
this.renderer.drawGeometry(feature.geometry, style);
drawFeature: function(feature, style) {
if(style == null) {
if(feature.style) {
style = feature.style;
} else {
style = this.style;
}
}
this.renderer.drawFeature(feature, style);
},
/**
* Start editing the layer
*
* @returns Whether or not the layer is editable
* @type Boolean
* Given an event, return a feature if the event occurred over one.
* Otherwise, return null.
*
* @param {Event}
* @type OpenLayers.Feature.Vector
* @return A feature if one was under the event
*/
unlock: function() {
if(this.editable) {
this.editing = true;
}
return this.editable;
getFeatureFromEvent: function(evt) {
var featureId = this.renderer.getFeatureIdFromEvent(evt);
return this.getFeatureById(featureId);
},
/**
* Stop editing the layer
* Given a feature id, return the feature if it exists in the features array
*
* @return Whether or not the layer *was* editing
* HACK HACK This return value seems wierd to me.
* @type Boolean
* @param String featureId
* @type OpenLayers.Feature.Vector
* @return A feature corresponding to the given featureId
*/
lock: function() {
if(this.editing) {
this.editing = false;
getFeatureById: function(featureId) {
//TBD - would it be more efficient to use a hash for this.features?
var feature = null;
for(var i=0; i<this.features.length; ++i) {
if(this.features[i].id == featureId) {
feature = this.features[i];
break;
}
}
return this.editing;
return feature;
},
/**
* Unselect the selected features
* i.e. clears the featureSelection array
@@ -319,8 +316,7 @@ OpenLayers.Layer.Vector.prototype =
var vectorLayer = this.map.vectorLayer;
for (var i = 0; i < this.map.featureSelection.length; i++) {
var featureSelection = this.map.featureSelection[i];
vectorLayer.renderer.drawGeometry(featureSelection.geometry,
vectorLayer.style);
vectorLayer.drawFeature(featureSelection, vectorLayer.style);
}
this.map.featureSelection = [];
},