From 69ec660a501dbccc7bb630482149062dc4ff387c Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sun, 19 Jun 2016 13:07:47 +0200 Subject: Allow to get length of polylines --- web/js/eventmap.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web/js/eventmap.js b/web/js/eventmap.js index b9ded12..e974cb3 100644 --- a/web/js/eventmap.js +++ b/web/js/eventmap.js @@ -84,6 +84,20 @@ function polyline_set_type(marker, type) { marker.options.type = type; } +function polyline_get_length(marker) { + var last_node = undefined; + var distance = 0.0; + $.each(marker.getLatLngs(), function(index, node) { + if (last_node === undefined) { + last_node = node; + return true; + } + distance += L.latLng(last_node).distanceTo(node); + last_node = node; + }); + return distance; +} + function process_polyline_update(marker_name, marker_info) { if (marker_name in marker_store) { var marker = marker_store[marker_name]; @@ -245,6 +259,13 @@ function add_polyline_contextmenu(marker) { polyline_set_type(marker, "Unknown"); eventmap_send_update(); } + }, + { + text: 'Get length', + callback: function() { + alert(L.GeometryUtil.readableDistance( + polyline_get_length(marker), true)); + } } ] }); -- cgit v1.2.1