1

I didn't see any mention for measure tool in OL 3 API. Is there an alternative / a way to use a measure tool (line & area) with OL 3 ?

4 Answers 4

3

Measuring is easily accomplished with an ol.interaction.Draw on the application level. See https://openlayers.org/en/latest/examples/measure.html for the official example demonstrating this. OpenLayers has functions for measuring on a sphere in the ol/sphere module:

import {getLength, getArea} from 'ol/sphere.js';

const lineStringLength = getLength(lineString);
const polygonArea = getArea(polygon);
2
  • distances at poles are less than what is seen on a planar map. the example does not count this. any help? Jun 15, 2023 at 10:56
  • I just updated the example link and added example code to encourage use of the spherical getLength() and getArea() functions, which solve this problem.
    – ahocevar
    Jun 16, 2023 at 13:13
1

In openlayers 3 or newer versions, there is no inbuilt measure tool. You have to create it from scratch in OpenLayers. Go through following link to learn how you can create such tool.

Create a DynamicMeasurement tool in OpenLayers to show measurements on labels that follow changing geometry

enter image description here

1
  • 2
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 12, 2021 at 9:25
-1

link seems broken here is working link .

http://openlayers.org/en/v3.7.0/examples/measure.html

-2

The latest example for ol-measurments: https://openlayers.org/en/latest/examples/measure.html

1
  • 3
    Link-only answers are discouraged here. Please provide a more thorough answer which summarizes the content in the link, or the automated review process may result in deletion of this Answer.
    – Vince
    May 20, 2019 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.