Adding methods for getting geodesic measures from geometries. Assuming geometries can be transformed into Geographic/WGS84, getGeodesicLength and getGeodesicArea should return reasonable 'on the ground' metrics. Use getLength and getArea for the planar metrics. r=crschmidt (closes #1819)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9248 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-04-08 23:12:24 +00:00
parent 5f335f4207
commit 08077f0f42
8 changed files with 250 additions and 44 deletions

View File

@@ -56,6 +56,14 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
*/
displaySystem: 'metric',
/**
* Property: geodesic
* {Boolean} Calculate geodesic metrics instead of planar metrics. This
* requires that geometries can be transformed into Geographic/WGS84
* (if that is not already the map projection). Default is false.
*/
geodesic: false,
/**
* Property: displaySystemUnits
* {Object} Units for various measurement systems. Values are arrays
@@ -213,10 +221,17 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
* {Float} The geometry area in the given units.
*/
getArea: function(geometry, units) {
var area = geometry.getArea();
var area, geomUnits;
if(this.geodesic) {
area = geometry.getGeodesicArea(this.map.getProjectionObject());
geomUnits = "m";
} else {
area = geometry.getArea();
geomUnits = this.map.getUnits();
}
var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units];
if(inPerDisplayUnit) {
var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[this.map.getUnits()];
var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits];
area *= Math.pow((inPerMapUnit / inPerDisplayUnit), 2);
}
return area;
@@ -257,10 +272,17 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
* {Float} The geometry length in the given units.
*/
getLength: function(geometry, units) {
var length = geometry.getLength();
var length, geomUnits;
if(this.geodesic) {
length = geometry.getGeodesicLength(this.map.getProjectionObject());
geomUnits = "m";
} else {
length = geometry.getLength();
geomUnits = this.map.getUnits();
}
var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units];
if(inPerDisplayUnit) {
var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[this.map.getUnits()];
var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits];
length *= (inPerMapUnit / inPerDisplayUnit);
}
return length;