Tim's big refactoring of the Geometry modules. Fixes #590. All tests pass in FF (except the PanZoomBar stuff, which wasn't touched by this patch) and IE.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@2931 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -24,6 +24,14 @@ OpenLayers.Geometry.Collection.prototype =
|
||||
|
||||
/** @type Array(OpenLayers.Geometry) */
|
||||
components: null,
|
||||
|
||||
/**
|
||||
* An array of class names representing the types of components that
|
||||
* the collection can include. A null value means the component types
|
||||
* are not restricted.
|
||||
* @type Array(String)
|
||||
*/
|
||||
componentTypes: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
@@ -59,19 +67,16 @@ OpenLayers.Geometry.Collection.prototype =
|
||||
* @returns An exact clone of this collection
|
||||
* @type OpenLayers.Geometry.Collection
|
||||
*/
|
||||
clone: function (obj) {
|
||||
if (obj == null) {
|
||||
obj = eval("new " + this.CLASS_NAME + "()");
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.components.length; i++) {
|
||||
obj.addComponent(this.components[i].clone());
|
||||
clone: function() {
|
||||
var geometry = eval("new " + this.CLASS_NAME + "()");
|
||||
for(var i=0; i<this.components.length; i++) {
|
||||
geometry.addComponent(this.components[i].clone());
|
||||
}
|
||||
|
||||
// catch any randomly tagged-on properties
|
||||
OpenLayers.Util.applyDefaults(obj, this);
|
||||
OpenLayers.Util.applyDefaults(geometry, this);
|
||||
|
||||
return obj;
|
||||
return geometry;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -121,28 +126,39 @@ OpenLayers.Geometry.Collection.prototype =
|
||||
}
|
||||
},
|
||||
|
||||
/** Add a new component (geometry) to the collection.
|
||||
/**
|
||||
* Add a new component (geometry) to the collection. If this.componentTypes
|
||||
* is set, then the component class name must be in the componentTypes array.
|
||||
*
|
||||
* The bounds cache is reset.
|
||||
*
|
||||
* @param {OpenLayers.Geometry} component
|
||||
* @param {int} index Index into the array to insert the component
|
||||
* @type Boolean
|
||||
* @return Component was successfully added
|
||||
*/
|
||||
addComponent: function(component, index) {
|
||||
if (component) {
|
||||
var added = false;
|
||||
if(component) {
|
||||
if(this.componentTypes == null ||
|
||||
(OpenLayers.Util.indexOf(this.componentTypes,
|
||||
component.CLASS_NAME) > -1)) {
|
||||
|
||||
if (index) {
|
||||
var components1 = this.components.slice(0, index);
|
||||
var components2 = this.components.slice(index,
|
||||
this.components.length);
|
||||
components1.push(component);
|
||||
this.components = components1.concat(components2);
|
||||
} else {
|
||||
this.components.push(component);
|
||||
if(index != null && (index < this.components.length)) {
|
||||
var components1 = this.components.slice(0, index);
|
||||
var components2 = this.components.slice(index,
|
||||
this.components.length);
|
||||
components1.push(component);
|
||||
this.components = components1.concat(components2);
|
||||
} else {
|
||||
this.components.push(component);
|
||||
}
|
||||
component.parent = this;
|
||||
this.clearBounds();
|
||||
added = true;
|
||||
}
|
||||
component.parent = this;
|
||||
this.clearBounds();
|
||||
}
|
||||
return added;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -205,6 +221,30 @@ OpenLayers.Geometry.Collection.prototype =
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Tests for equivalent geometries
|
||||
* @param {OpenLayers.Geometry}
|
||||
* @type Boolean
|
||||
* @return The coordinates are equivalent
|
||||
*/
|
||||
equals: function(geometry) {
|
||||
var equivalent = true;
|
||||
if(!geometry.CLASS_NAME || (this.CLASS_NAME != geometry.CLASS_NAME)) {
|
||||
equivalent = false;
|
||||
} else if(!(geometry.components instanceof Array) ||
|
||||
(geometry.components.length != this.components.length)) {
|
||||
equivalent = false;
|
||||
} else {
|
||||
for(var i=0; i<this.components.length; ++i) {
|
||||
if(!this.components[i].equals(geometry.components[i])) {
|
||||
equivalent = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return equivalent;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Collection"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user