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:
@@ -19,50 +19,62 @@ OpenLayers.Geometry.LinearRing.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.LineString, {
|
||||
|
||||
/**
|
||||
* 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: ["OpenLayers.Geometry.Point"],
|
||||
|
||||
/**
|
||||
* Linear rings are constructed with an array of points. This array
|
||||
* can represent a closed or open ring. If the ring is open (the last
|
||||
* point does not equal the first point), the constructor will close
|
||||
* the ring. If the ring is already closed (the last point does equal
|
||||
* the first point), it will be left closed.
|
||||
*
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.Point)} points
|
||||
*/
|
||||
initialize: function(points) {
|
||||
OpenLayers.Geometry.LineString.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @returns An exact clone of this OpenLayers.Geometry.LinearRing
|
||||
* @type OpenLayers.Geometry.LinearRing
|
||||
*/
|
||||
clone: function (obj) {
|
||||
if (obj == null) {
|
||||
obj = new OpenLayers.Geometry.LinearRing();
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.components.length; i++) {
|
||||
obj.addComponent(this.components[i].clone());
|
||||
}
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a point to geometry components
|
||||
* Adds a point to geometry components. If the point is to be added to
|
||||
* the end of the components array and it is the same as the last point
|
||||
* already in that array, the duplicate point is not added. This has the
|
||||
* effect of closing the ring if it is not already closed, and doing the
|
||||
* right thing if it is already closed. This behavior can be overridden
|
||||
* by calling the method with a non-null index as the second argument.
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
* @type Boolean
|
||||
* @return Point was successfully added
|
||||
*/
|
||||
addComponent: function(point, index) {
|
||||
var added = false;
|
||||
|
||||
//remove last point
|
||||
var lastPoint = this.components[this.components.length-1];
|
||||
OpenLayers.Geometry.Curve.prototype.removeComponent.apply(this,
|
||||
[lastPoint]);
|
||||
|
||||
//add our point
|
||||
OpenLayers.Geometry.LineString.prototype.addComponent.apply(this,
|
||||
arguments);
|
||||
OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this,
|
||||
[lastPoint]);
|
||||
|
||||
// given an index, add the point
|
||||
// without an index only add non-duplicate points
|
||||
if(index != null || !point.equals(lastPoint)) {
|
||||
added = OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
arguments);
|
||||
}
|
||||
|
||||
//append copy of first point
|
||||
var firstPoint = this.components[0];
|
||||
OpenLayers.Geometry.Curve.prototype.addComponent.apply(this,
|
||||
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
[firstPoint.clone()]);
|
||||
|
||||
return added;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -75,15 +87,15 @@ OpenLayers.Geometry.LinearRing.prototype =
|
||||
|
||||
//remove last point
|
||||
var lastPoint = this.components[this.components.length-1];
|
||||
OpenLayers.Geometry.Curve.prototype.removeComponent.apply(this,
|
||||
OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this,
|
||||
[lastPoint]);
|
||||
|
||||
//remove our point
|
||||
OpenLayers.Geometry.LineString.prototype.removeComponent.apply(this,
|
||||
OpenLayers.Geometry.Collection.prototype.removeComponent.apply(this,
|
||||
arguments);
|
||||
//append copy of first point
|
||||
var firstPoint = this.components[0];
|
||||
OpenLayers.Geometry.Curve.prototype.addComponent.apply(this,
|
||||
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
[firstPoint.clone()]);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user