1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
6 * @requires OpenLayers/Geometry/MultiPoint.js
10 * Class: OpenLayers.Geometry.Curve
11 * A Curve is a MultiPoint, whose points are assumed to be connected. To
12 * this end, we provide a "getLength()" function, which iterates through
13 * the points, summing the distances between them.
16 * - <OpenLayers.Geometry.MultiPoint>
18 OpenLayers.Geometry.Curve = OpenLayers.Class(OpenLayers.Geometry.MultiPoint, {
21 * Property: componentTypes
22 * {Array(String)} An array of class names representing the types of
23 * components that the collection can include. A null
24 * value means the component types are not restricted.
26 componentTypes: ["OpenLayers.Geometry.Point"],
29 * Constructor: OpenLayers.Geometry.Curve
32 * point - {Array(<OpenLayers.Geometry.Point>)}
34 initialize: function(points) {
35 OpenLayers.Geometry.MultiPoint.prototype.initialize.apply(this,
40 * APIMethod: getLength
43 * {Float} The length of the curve
45 getLength: function() {
47 if ( this.components && (this.components.length > 1)) {
48 for(var i=1, len=this.components.length; i<len; i++) {
49 length += this.components[i-1].distanceTo(this.components[i]);
56 * APIMethod: getGeodesicLength
57 * Calculate the approximate length of the geometry were it projected onto
60 * projection - {<OpenLayers.Projection>} The spatial reference system
61 * for the geometry coordinates. If not provided, Geographic/WGS84 is
65 * {Float} The appoximate geodesic length of the geometry in meters.
67 getGeodesicLength: function(projection) {
68 var geom = this; // so we can work with a clone if needed
70 var gg = new OpenLayers.Projection("EPSG:4326");
71 if(!gg.equals(projection)) {
72 geom = this.clone().transform(projection, gg);
76 if(geom.components && (geom.components.length > 1)) {
78 for(var i=1, len=geom.components.length; i<len; i++) {
79 p1 = geom.components[i-1];
80 p2 = geom.components[i];
81 // this returns km and requires lon/lat properties
82 length += OpenLayers.Util.distVincenty(
83 {lon: p1.x, lat: p1.y}, {lon: p2.x, lat: p2.y}
91 CLASS_NAME: "OpenLayers.Geometry.Curve"