Merge vector-2.4 branch back to trunk.
svn merge sandbox/vector-2.4/@2307 sandbox/vector-2.4/@HEAD trunk/openlayers/ git-svn-id: http://svn.openlayers.org/trunk/openlayers@2803 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
201
lib/OpenLayers/Geometry/Collection.js
Normal file
201
lib/OpenLayers/Geometry/Collection.js
Normal file
@@ -0,0 +1,201 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* A Collection is exactly what it sounds like: A collection of different
|
||||
* Geometries. These are stored in the local parameter "components" (which
|
||||
* can be passed as a parameter to the constructor).
|
||||
*
|
||||
* As new geometries are added to the collection, they are NOT cloned.
|
||||
* When removing geometries, they need to be specified by reference (ie you
|
||||
* have to pass in the *exact* geometry to be removed).
|
||||
*
|
||||
* The getArea() and getLength() functions here merely iterate through
|
||||
* the components, summing their respective areas and lengths.
|
||||
*
|
||||
* @requires OpenLayers/Geometry.js
|
||||
*/
|
||||
OpenLayers.Geometry.Collection = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.Collection.prototype =
|
||||
OpenLayers.Class.inherit( OpenLayers.Geometry, {
|
||||
|
||||
/** @type Array(OpenLayers.Geometry) */
|
||||
components: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry)} components
|
||||
*/
|
||||
initialize: function (components) {
|
||||
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
|
||||
this.components = new Array();
|
||||
if (components != null) {
|
||||
this.addComponents(components);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
destroy: function () {
|
||||
this.components.length = 0;
|
||||
this.components = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @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());
|
||||
}
|
||||
|
||||
// catch any randomly tagged-on properties
|
||||
OpenLayers.Util.applyDefaults(obj, this);
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns the components of the geometry
|
||||
* @type Array(OpenLayers.Geometry)
|
||||
*/
|
||||
getComponents: function(){
|
||||
return this.components;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns the components of the geometry
|
||||
* @type Array(OpenLayers.Geometry)
|
||||
*/
|
||||
getComponentsString: function(){
|
||||
var strings = [];
|
||||
for(var i = 0; i < this.components.length; i++) {
|
||||
strings.push(this.components[i].toShortString());
|
||||
}
|
||||
return strings.join(",");
|
||||
},
|
||||
|
||||
/** Recalculate the bounds by iterating through the components and
|
||||
* calling calling extendBounds() on each item
|
||||
*
|
||||
*/
|
||||
calculateBounds: function() {
|
||||
this.bounds = null;
|
||||
if ( !this.components || (this.components.length > 0)) {
|
||||
this.setBounds(this.components[0].getBounds());
|
||||
for (var i = 1; i < this.components.length; i++) {
|
||||
this.extendBounds(this.components[i].getBounds());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array(OpenLayers.Geometry)} components
|
||||
*
|
||||
*/
|
||||
addComponents: function(components){
|
||||
if(!(components instanceof Array)) {
|
||||
components = [components];
|
||||
}
|
||||
for(var i=0; i < components.length; i++) {
|
||||
this.addComponent(components[i]);
|
||||
}
|
||||
},
|
||||
|
||||
/** Add a new component (geometry) to the collection.
|
||||
*
|
||||
* The bounds cache is reset.
|
||||
*
|
||||
* @param {OpenLayers.Geometry} component
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
addComponent: function(component, index) {
|
||||
if (component) {
|
||||
|
||||
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);
|
||||
}
|
||||
component.parent = this;
|
||||
this.clearBounds();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array(OpenLayers.Geometry)} components
|
||||
*/
|
||||
removeComponents: function(components) {
|
||||
if(!(components instanceof Array)) {
|
||||
components = [components];
|
||||
}
|
||||
for (var i = 0; i < components.length; i++) {
|
||||
this.removeComponent(components[i]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Geometry} component
|
||||
*/
|
||||
removeComponent: function(component) {
|
||||
|
||||
OpenLayers.Util.removeItem(this.components, component);
|
||||
|
||||
// clearBounds() so that it gets recalculated on the next call
|
||||
// to this.getBounds();
|
||||
this.clearBounds();
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The length of the geometry
|
||||
* @type float
|
||||
*/
|
||||
getLength: function() {
|
||||
var length = 0.0;
|
||||
for (var i = 0; i < this.components.length; i++) {
|
||||
length += this.components[i].getLength();
|
||||
}
|
||||
return length;
|
||||
},
|
||||
|
||||
/** Note how this function is overridden in Polygon
|
||||
*
|
||||
* @returns the area of the collection by summing its parts
|
||||
* @type float
|
||||
*/
|
||||
getArea: function() {
|
||||
var area = 0.0;
|
||||
for (var i = 0; i < this.components.length; i++) {
|
||||
area += this.components[i].getArea();
|
||||
}
|
||||
return area;
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves a collection in place
|
||||
* @param {Float} x
|
||||
* @param {Float} y
|
||||
*/
|
||||
move: function(x, y) {
|
||||
for(var i = 0; i < this.components.length; i++) {
|
||||
this.components[i].move(x, y);
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Collection"
|
||||
});
|
||||
58
lib/OpenLayers/Geometry/Curve.js
Normal file
58
lib/OpenLayers/Geometry/Curve.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* A Curve is a MultiPoint, whose points are assumed to be connected. To
|
||||
* this end, we provide a "getLength()" function, which iterates through
|
||||
* the points, summing the distances between them.
|
||||
*
|
||||
* @requires OpenLayers/Geometry/MultiPoint.js
|
||||
*/
|
||||
OpenLayers.Geometry.Curve = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.Curve.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.MultiPoint, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.Point)} points
|
||||
*/
|
||||
initialize: function(points) {
|
||||
OpenLayers.Geometry.MultiPoint.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns An exact clone of this OpenLayers.Feature
|
||||
* @type OpenLayers.Feature
|
||||
*/
|
||||
clone: function (obj) {
|
||||
if (obj == null) {
|
||||
obj = new OpenLayers.Geometry.Curve();
|
||||
}
|
||||
|
||||
obj = OpenLayers.Geometry.Collection.prototype.clone.apply(this,
|
||||
[obj]);
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The length of the curve
|
||||
* @type float
|
||||
*/
|
||||
getLength: function() {
|
||||
var length = 0.0;
|
||||
if ( this.components && (this.components.length > 1)) {
|
||||
for(var i=1; i < this.components.length; i++) {
|
||||
length += this.components[i-1].distanceTo(this.components[i]);
|
||||
}
|
||||
}
|
||||
return length;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Curve"
|
||||
});
|
||||
65
lib/OpenLayers/Geometry/LineString.js
Normal file
65
lib/OpenLayers/Geometry/LineString.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* A LineString is a Curve which, once two points have been added to it, can
|
||||
* never be less than two points long.
|
||||
*
|
||||
* @requires OpenLayers/Geometry/Curve.js
|
||||
*/
|
||||
OpenLayers.Geometry.LineString = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.LineString.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.Curve, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.Point)} points
|
||||
*/
|
||||
initialize: function(points) {
|
||||
OpenLayers.Geometry.Curve.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The coordinates components as a string
|
||||
* @type String
|
||||
*/
|
||||
toString: function() {
|
||||
return this.components.toString();
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns An exact clone of this OpenLayers.Feature
|
||||
* @type OpenLayers.Feature
|
||||
*/
|
||||
clone: function (obj) {
|
||||
if (obj == null) {
|
||||
obj = new OpenLayers.Geometry.LineString();
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.components.length; i++) {
|
||||
obj.addComponent(this.components[i].clone());
|
||||
}
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
/** Only allows removal of a point if there are three or more points in
|
||||
* the linestring. (otherwise the result would be just a single point)
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
*/
|
||||
removeComponent: function(point) {
|
||||
if ( this.components && (this.components.length > 2)) {
|
||||
OpenLayers.Geometry.Curve.prototype.removeComponent.apply(this,
|
||||
arguments);
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.LineString"
|
||||
});
|
||||
113
lib/OpenLayers/Geometry/LinearRing.js
Normal file
113
lib/OpenLayers/Geometry/LinearRing.js
Normal file
@@ -0,0 +1,113 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* A Linear Ring is a special LineString which is closed. It closes itself
|
||||
* automatically on every addPoint/removePoint by adding a copy of the first
|
||||
* point as the last point.
|
||||
*
|
||||
* Also, as it is the first in the line family to close itself, a getArea()
|
||||
* function is defined to calculate the enclosed area of the linearRing
|
||||
*
|
||||
* @requires OpenLayers/Geometry/LineString.js
|
||||
*/
|
||||
OpenLayers.Geometry.LinearRing = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.LinearRing.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.LineString, {
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
addComponent: function(point, index) {
|
||||
//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);
|
||||
//append copy of first point
|
||||
var firstPoint = this.components[0];
|
||||
OpenLayers.Geometry.Curve.prototype.addComponent.apply(this,
|
||||
[firstPoint.clone()]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a point from geometry components
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
*/
|
||||
removeComponent: function(point) {
|
||||
if (this.components.length > 4) {
|
||||
|
||||
//remove last point
|
||||
var lastPoint = this.components[this.components.length-1];
|
||||
OpenLayers.Geometry.Curve.prototype.removeComponent.apply(this,
|
||||
[lastPoint]);
|
||||
|
||||
//remove our point
|
||||
OpenLayers.Geometry.LineString.prototype.removeComponent.apply(this,
|
||||
arguments);
|
||||
//append copy of first point
|
||||
var firstPoint = this.components[0];
|
||||
OpenLayers.Geometry.Curve.prototype.addComponent.apply(this,
|
||||
[firstPoint.clone()]);
|
||||
}
|
||||
},
|
||||
|
||||
/** Note: The area is positive if the ring is oriented CW, otherwise
|
||||
* it will be negative.
|
||||
*
|
||||
* @returns The signed area for a ring.
|
||||
* @type float
|
||||
*/
|
||||
getArea: function() {
|
||||
var area = 0.0;
|
||||
if ( this.components && (this.components.length > 2)) {
|
||||
var sum = 0.0;
|
||||
for (var i = 0; i < this.components.length - 1; i++) {
|
||||
var b = this.components[i];
|
||||
var c = this.components[i+1];
|
||||
sum += (b.x + c.x) * (c.y - b.y);
|
||||
}
|
||||
area = - sum / 2.0;
|
||||
}
|
||||
return area;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.LinearRing"
|
||||
});
|
||||
42
lib/OpenLayers/Geometry/MultiLineString.js
Normal file
42
lib/OpenLayers/Geometry/MultiLineString.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* A MultiLineString is a collection of LineStrings
|
||||
*
|
||||
* @requires OpenLayers/Geometry/Collection.js
|
||||
*/
|
||||
OpenLayers.Geometry.MultiLineString = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.MultiLineString.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.LineString)} components
|
||||
*/
|
||||
initialize: function(components) {
|
||||
OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* adds a component to the MultiPoint, checking type
|
||||
*
|
||||
* @param {OpenLayers.Geometry.LineString} component lineString to add
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
addComponent: function(component, index) {
|
||||
if (!(component instanceof OpenLayers.Geometry.LineString)) {
|
||||
throw "component should be an OpenLayers.Geometry.LineString";
|
||||
}
|
||||
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.MultiLineString"
|
||||
});
|
||||
60
lib/OpenLayers/Geometry/MultiPoint.js
Normal file
60
lib/OpenLayers/Geometry/MultiPoint.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* MultiPoint is a collection of Points.
|
||||
*
|
||||
* @requires OpenLayers/Geometry/Collection.js
|
||||
*/
|
||||
OpenLayers.Geometry.MultiPoint = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.MultiPoint.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.Point)} components
|
||||
*/
|
||||
initialize: function(components) {
|
||||
OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* adds component to the MultiPoint, checking type
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} component point to add
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
addComponent: function(component, index) {
|
||||
if (!(component instanceof OpenLayers.Geometry.Point)) {
|
||||
throw "component should be an OpenLayers.Geometry.Point";
|
||||
}
|
||||
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Wrapper for addComponent()
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
* @param {int} index
|
||||
*/
|
||||
addPoint: function(point, index) {
|
||||
this.addComponent(point, index);
|
||||
},
|
||||
|
||||
/**
|
||||
* Wrapper for removeComponent()
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
*/
|
||||
removePoint: function(point){
|
||||
this.removeComponent(point);
|
||||
},
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.MultiPoint"
|
||||
});
|
||||
45
lib/OpenLayers/Geometry/MultiPolygon.js
Normal file
45
lib/OpenLayers/Geometry/MultiPolygon.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* MultiPolygon is a collection of Polygons.
|
||||
*
|
||||
* @requires OpenLayers/Geometry/Collection.js
|
||||
*/
|
||||
OpenLayers.Geometry.MultiPolygon = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.MultiPolygon.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.Polygon)} components
|
||||
*/
|
||||
initialize: function(components) {
|
||||
OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* adds component to the MultiPolygon, checking type
|
||||
*
|
||||
* @param {OpenLayers.Geometry.Polygon} component Polygon to add
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
addComponent: function(component, index) {
|
||||
if (!(component instanceof OpenLayers.Geometry.Polygon)) {
|
||||
var throwStr = "component should be an " +
|
||||
"OpenLayers.Geometry.Polygon but is an " +
|
||||
component.CLASS_NAME;
|
||||
throw throwStr;
|
||||
}
|
||||
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.MultiPolygon"
|
||||
});
|
||||
135
lib/OpenLayers/Geometry/Point.js
Normal file
135
lib/OpenLayers/Geometry/Point.js
Normal file
@@ -0,0 +1,135 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* The Point class is a subclass of Geometry and also a subclass of the
|
||||
* non-vector OpenLayers.LonLat class. The basic functionality that this adds
|
||||
* is the ability to switch between lon/lat and x/y at will, as well some
|
||||
* convenience functions to create a Bounds from a point and measure the
|
||||
* distance between two points.
|
||||
*
|
||||
* getX() and setX() should be used to access the x or lon variables.
|
||||
*
|
||||
* @requires OpenLayers/BaseTypes.js
|
||||
* @requires OpenLayers/Geometry.js
|
||||
*/
|
||||
OpenLayers.Geometry.Point = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.Point.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.LonLat, OpenLayers.Geometry, {
|
||||
|
||||
/** @type float */
|
||||
x: null,
|
||||
|
||||
/** @type float */
|
||||
y: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {float} x
|
||||
* @param {float} y
|
||||
*/
|
||||
initialize: function(x, y) {
|
||||
OpenLayers.LonLat.prototype.initialize.apply(this, arguments);
|
||||
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this.x = this.lon;
|
||||
this.y = this.lat;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns An exact clone of this OpenLayers.Geometry.Point
|
||||
* @type OpenLayers.Geometry.Point
|
||||
*/
|
||||
clone: function(obj) {
|
||||
if (obj == null) {
|
||||
obj = new OpenLayers.Geometry.Point(this.x, this.y);
|
||||
}
|
||||
|
||||
// catch any randomly tagged-on properties
|
||||
OpenLayers.Util.applyDefaults(obj, this);
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the x coordinate
|
||||
*
|
||||
* @param {float} x
|
||||
*/
|
||||
setX: function(x) {
|
||||
this.lon = x;
|
||||
this.x = x;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the y coordinate
|
||||
*
|
||||
* @param {float} y
|
||||
*/
|
||||
setY: function(y) {
|
||||
this.lat = y;
|
||||
this.y = y;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type float
|
||||
*/
|
||||
getX: function() {
|
||||
return this.lon;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type float
|
||||
*/
|
||||
getY: function() {
|
||||
return this.lat;
|
||||
},
|
||||
|
||||
/** Create a new Bounds based on the lon/lat
|
||||
*
|
||||
*/
|
||||
calculateBounds: function () {
|
||||
this.bounds = new OpenLayers.Bounds(this.lon, this.lat,
|
||||
this.lon, this.lat);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
*/
|
||||
distanceTo: function(point) {
|
||||
var distance = 0.0;
|
||||
if ( (this.x != null) && (this.y != null) &&
|
||||
(point != null) && (point.x != null) && (point.y != null) ) {
|
||||
|
||||
var dx2 = Math.pow(this.x - point.x, 2);
|
||||
var dy2 = Math.pow(this.y - point.y, 2);
|
||||
distance = Math.sqrt( dx2 + dy2 );
|
||||
}
|
||||
return distance;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns the coordinates as a string
|
||||
* @type String
|
||||
*/
|
||||
toString: function() {
|
||||
return this.toShortString();
|
||||
},
|
||||
|
||||
/**
|
||||
* Moves a point in place
|
||||
* @param {Float} x
|
||||
* @param {Float} y
|
||||
*/
|
||||
move: function(x, y) {
|
||||
this.setX(this.x + x);
|
||||
this.setY(this.y + y);
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Point"
|
||||
});
|
||||
66
lib/OpenLayers/Geometry/Polygon.js
Normal file
66
lib/OpenLayers/Geometry/Polygon.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* Polygon is a collection of Geometry.LinearRings.
|
||||
*
|
||||
* The first ring (this.component[0])is the outer bounds of the polygon and
|
||||
* all subsequent rings (this.component[1-n]) are internal holes.
|
||||
*
|
||||
* @requires OpenLayers/Geometry/Collection.js
|
||||
*/
|
||||
OpenLayers.Geometry.Polygon = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.Polygon.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {Array(OpenLayers.Geometry.LinearRing)}
|
||||
*/
|
||||
initialize: function(components) {
|
||||
OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* adds a component to the Polygon, checking type
|
||||
*
|
||||
* @param {OpenLayers.Geometry.LinearRing} point to add
|
||||
* @param {int} index Index into the array to insert the component
|
||||
*/
|
||||
addComponent: function(component, index) {
|
||||
if (!(component instanceof OpenLayers.Geometry.LinearRing)) {
|
||||
var throwStr = "component should be an " +
|
||||
"OpenLayers.Geometry.LinearRing but is a " +
|
||||
component.CLASS_NAME;
|
||||
throw throwStr;
|
||||
|
||||
}
|
||||
OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
|
||||
arguments);
|
||||
},
|
||||
|
||||
/** Calculated by subtracting the areas of the internal holes from the
|
||||
* area of the outer hole.
|
||||
*
|
||||
* @returns The area of the geometry
|
||||
* @type float
|
||||
*/
|
||||
getArea: function() {
|
||||
var area = 0.0;
|
||||
if ( this.components && (this.components.length > 0)) {
|
||||
area += Math.abs(this.components[0].getArea());
|
||||
for (var i = 1; i < this.components.length; i++) {
|
||||
area -= Math.abs(this.components[i].getArea());
|
||||
}
|
||||
}
|
||||
return area;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Polygon"
|
||||
});
|
||||
76
lib/OpenLayers/Geometry/Rectangle.js
Normal file
76
lib/OpenLayers/Geometry/Rectangle.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* A Rectangle is a simple geometry. It is specified by a a point (x and y)
|
||||
* and dimensions (width and height), all of which are directly accessible as
|
||||
* properties.
|
||||
*
|
||||
* @requires OpenLayers/Geometry.js
|
||||
*/
|
||||
|
||||
OpenLayers.Geometry.Rectangle = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.Rectangle.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry, {
|
||||
|
||||
/** @type float */
|
||||
x: null,
|
||||
|
||||
/** @type float */
|
||||
y: null,
|
||||
|
||||
/** @type float */
|
||||
width: null,
|
||||
|
||||
/** @type float */
|
||||
height: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {array} points
|
||||
*/
|
||||
initialize: function(x, y, width, height) {
|
||||
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
calculateBounds: function() {
|
||||
this.bounds = new OpenLayers.Bounds(this.x, this.y,
|
||||
this.x + this.width,
|
||||
this.y + this.height);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @returns The length of the geometry
|
||||
* @type float
|
||||
*/
|
||||
getLength: function() {
|
||||
var length = (2 * this.width) + (2 * this.height);
|
||||
return length;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The area of the geometry
|
||||
* @type float
|
||||
*/
|
||||
getArea: function() {
|
||||
var area = this.width * this.height;
|
||||
return area;
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Rectangle"
|
||||
});
|
||||
25
lib/OpenLayers/Geometry/Surface.js
Normal file
25
lib/OpenLayers/Geometry/Surface.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/* 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. */
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* @requires OpenLayers/Geometry.js
|
||||
*/
|
||||
OpenLayers.Geometry.Surface = OpenLayers.Class.create();
|
||||
OpenLayers.Geometry.Surface.prototype =
|
||||
OpenLayers.Class.inherit(OpenLayers.Geometry, {
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
*/
|
||||
initialize: function() {
|
||||
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Geometry.Surface"
|
||||
});
|
||||
Reference in New Issue
Block a user