diff --git a/examples/measure.html b/examples/measure.html
index b594b37e05..1d997edeff 100644
--- a/examples/measure.html
+++ b/examples/measure.html
@@ -1,20 +1,24 @@
---
layout: example.html
title: Measure
-shortdesc: Example of using the ol.interaction.Draw interaction to create a simple measuring application.
+shortdesc: Using a draw interaction to measure lengths and areas.
docs: >
-
NOTE: By default, length and area are calculated using the projected coordinates. This is not accurate for projections like Mercator where the projected meters do not correspond to meters on the ground. To get a standarized measurement across all projections, use the geodesic measures.
+ The ol.Sphere.getLength() and ol.Sphere.getArea()
+ functions calculate spherical lengths and areas for geometries. Lengths are
+ calculated by assuming great circle segments between geometry coordinates.
+ Areas are calculated as if edges of polygons were great circle segments.
+ Note that the geometry.getLength() and geometry.getArea()
+ methods return measures of projected (planar) geometries. These can be very
+ different than on-the-ground measures in certain situations — in northern
+ and southern latitudes using Web Mercator for example. For better results,
+ use the functions on ol.Sphere.
tags: "draw, edit, measure, vector"
---
diff --git a/examples/measure.js b/examples/measure.js
index c1fa89c1f6..30c2dfaf11 100644
--- a/examples/measure.js
+++ b/examples/measure.js
@@ -8,7 +8,6 @@ goog.require('ol.geom.Polygon');
goog.require('ol.interaction.Draw');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
-goog.require('ol.proj');
goog.require('ol.source.OSM');
goog.require('ol.source.Vector');
goog.require('ol.style.Circle');
@@ -17,8 +16,6 @@ goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
-var wgs84Sphere = new ol.Sphere(6378137);
-
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
@@ -137,7 +134,6 @@ map.getViewport().addEventListener('mouseout', function() {
});
var typeSelect = document.getElementById('type');
-var geodesicCheckbox = document.getElementById('geodesic');
var draw; // global so we can remove it later
@@ -148,19 +144,7 @@ var draw; // global so we can remove it later
* @return {string} The formatted length.
*/
var formatLength = function(line) {
- var length;
- if (geodesicCheckbox.checked) {
- var coordinates = line.getCoordinates();
- length = 0;
- var sourceProj = map.getView().getProjection();
- for (var i = 0, ii = coordinates.length - 1; i < ii; ++i) {
- var c1 = ol.proj.transform(coordinates[i], sourceProj, 'EPSG:4326');
- var c2 = ol.proj.transform(coordinates[i + 1], sourceProj, 'EPSG:4326');
- length += wgs84Sphere.haversineDistance(c1, c2);
- }
- } else {
- length = Math.round(line.getLength() * 100) / 100;
- }
+ var length = ol.Sphere.getLength(line);
var output;
if (length > 100) {
output = (Math.round(length / 1000 * 100) / 100) +
@@ -179,16 +163,7 @@ var formatLength = function(line) {
* @return {string} Formatted area.
*/
var formatArea = function(polygon) {
- var area;
- if (geodesicCheckbox.checked) {
- var sourceProj = map.getView().getProjection();
- var geom = /** @type {ol.geom.Polygon} */(polygon.clone().transform(
- sourceProj, 'EPSG:4326'));
- var coordinates = geom.getLinearRing(0).getCoordinates();
- area = Math.abs(wgs84Sphere.geodesicArea(coordinates));
- } else {
- area = polygon.getArea();
- }
+ var area = ol.Sphere.getArea(polygon);
var output;
if (area > 10000) {
output = (Math.round(area / 1000000 * 100) / 100) +