#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

@@ -61,7 +61,7 @@ OpenLayers.Renderer.Elements.prototype =
/**
* Remove all the elements from the root
*
* @private
*/
clear: function() {
if (this.root) {
@@ -71,24 +71,6 @@ OpenLayers.Renderer.Elements.prototype =
}
},
/**
* Cycle through the rendered nodes and reproject them (this should be
* called when the extent or size has changed);
*
* @param {OpenLayers.Bounds} extent
*/
reproject: function(extent) {
for (var i = 0; i < this.root.childNodes.length; i++) {
var node = this.root.childNodes[i];
//reproject node
// for the moment, this only really happens so as to reset
// the heaviness of the line relative to the resolution and
// the size of the circle for the Point object
this.reprojectNode(node);
}
},
/** This function is in charge of asking the specific renderer which type
* of node to create for the given geometry. All geometries in an
* Elements-based renderer consist of one node and some attributes. We
@@ -100,23 +82,42 @@ OpenLayers.Renderer.Elements.prototype =
*
* @returns The corresponding node type for the specified geometry
* @type String
* @private
*/
getNodeType: function(geometry) { },
/**
* Draw the geometry on the specified layer, creating new nodes,
* setting paths, setting style.
* Draw the feature. The optional style argument can be used
* to override the feature's own style. This method should only
* be called from layer.drawFeature().
*
* @param {OpenLayers.Feature.Vector} feature
* @param {Object} style
*/
drawFeature: function(feature, style) {
if(style == null) {
style = feature.style;
}
this.drawGeometry(feature.geometry, style, feature.id);
},
/**
* Draw the geometry, creating new nodes, setting paths, setting style,
* setting featureId on the node. This method should only be called
* by the renderer itself.
*
* @param {OpenLayers.Geometry} geometry
* @param {Object} style
* @param {Object} style
* @param {String} featureId
* @private
*/
drawGeometry: function(geometry, style) {
drawGeometry: function(geometry, style, featureId) {
if ((geometry.CLASS_NAME == "OpenLayers.Geometry.MultiPoint") ||
(geometry.CLASS_NAME == "OpenLayers.Geometry.MultiLineString") ||
(geometry.CLASS_NAME == "OpenLayers.Geometry.MultiPolygon")) {
for (var i = 0; i < geometry.components.length; i++) {
this.drawGeometry(geometry.components[i], style);
this.drawGeometry(geometry.components[i], style, featureId);
}
return;
};
@@ -124,24 +125,27 @@ OpenLayers.Renderer.Elements.prototype =
//first we create the basic node and add it to the root
var nodeType = this.getNodeType(geometry);
var node = this.nodeFactory(geometry.id, nodeType, geometry);
node.geometry = geometry;
node.olStyle = style;
node._featureId = featureId;
node._geometryClass = geometry.CLASS_NAME;
node._style = style;
this.root.appendChild(node);
//now actually draw the node, and style it
this.drawGeometryNode(node);
this.drawGeometryNode(node, geometry);
},
/**
* Given a node, draw a geometry on the specified layer.
* node and geometry are required arguments, style is optional.
* This method is only called by the render itself.
*
* @param {DOMElement} node
* @param {OpenLayers.Geometry} geometry
* @param {Object} style
* @param {Object} style
* @private
*/
drawGeometryNode: function(node, geometry, style) {
geometry = geometry || node.geometry;
style = style || node.olStyle;
style = style || node._style;
var options = {
'isFilled': true,
@@ -171,19 +175,22 @@ OpenLayers.Renderer.Elements.prototype =
break;
}
node.olStyle = style;
node.olOptions = options;
node._style = style;
node._options = options;
//set style
this.setStyle(node);
//TBD simplify this
this.setStyle(node, style, options, geometry);
},
/**
* virtual functions for drawing different Geometries.
* These should all be implemented by subclasses.
* These methods are only called by the render itself.
*
* @param {DOMElement} node
* @param {OpenLayers.Geometry} geometry
* @param {OpenLayers.Geometry} geometry
* @private
*/
drawPoint: function(node, geometry) {},
drawLineString: function(node, geometry) {},
@@ -200,10 +207,9 @@ OpenLayers.Renderer.Elements.prototype =
* @returns A geometry from an event that happened on a layer
* @type OpenLayers.Geometry
*/
getGeometryFromEvent: function(evt) {
getFeatureIdFromEvent: function(evt) {
var node = evt.target || evt.srcElement;
var geometry = node.geometry ? node.geometry : null
return geometry;
return node._featureId;
},
/** Erase a geometry from the renderer. In the case of a multi-geometry,