summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2016-06-19 13:07:47 +0200
committerChristian Franke <nobody@nowhere.ws>2016-06-19 13:08:17 +0200
commit69ec660a501dbccc7bb630482149062dc4ff387c (patch)
tree88a299ef1e31e31f0880cbdd0065eb62a0e76f51 /web
parenta67704b5fed0626fca623c116d12f983e5d2c8c1 (diff)
Allow to get length of polylines
Diffstat (limited to 'web')
-rw-r--r--web/js/eventmap.js21
1 files changed, 21 insertions, 0 deletions
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));
+ }
}
]
});