1

i am using openlayers 3 measurement tool for measuring line lengths and polygons areas, and this example worked for me: http://www.rhone-mediterranee.eaufrance.fr/milieux-aquatiques/poissons/js/openlayers-v3.19.1/examples/measure.html , but i want to add something like getlenght or get perimeter for the polygon so when i draw a polygon i get the area and the perimter also ??

1

You can just ask for the perimeter of the outer linearring of your polygon. To do so within the example you provide and on the draw.on('drawstart', listener function change this block of code:

if (geom instanceof ol.geom.Polygon) {
output = formatArea(geom);
tooltipCoord = geom.getInteriorPoint().getCoordinates();
}

To this:

if (geom instanceof ol.geom.Polygon) {
output = formatArea(geom) +" " + formatLength(new ol.geom.LineString(geom.getLinearRing(0).getCoordinates()));
tooltipCoord = geom.getInteriorPoint().getCoordinates();
}

Here is a fiddle --> https://jsfiddle.net/p_tsagkis/utakLt5j/

  • no probms. glad to help – pavlos Aug 28 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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