diff options
author | Christian Franke <nobody@nowhere.ws> | 2016-06-19 11:57:39 +0200 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2016-06-19 13:08:17 +0200 |
commit | a67704b5fed0626fca623c116d12f983e5d2c8c1 (patch) | |
tree | 8e66692e5e4f24f907eea46a9d44ed40096ddd3d /web/js | |
parent | f54b50c52a801c65608e03d6a70bf1a4a7a0473c (diff) |
Allow for different polyline styles
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/eventmap.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/web/js/eventmap.js b/web/js/eventmap.js index cae02fa..b9ded12 100644 --- a/web/js/eventmap.js +++ b/web/js/eventmap.js @@ -46,6 +46,7 @@ function eventmap_send_update() { }); }); marker_info.layer = marker.options.layer_name; + marker_info.type = marker.options.type; } else { /* Regular marker */ marker_info.lat = marker.getLatLng().lat; @@ -71,12 +72,27 @@ function LoadingException(message) { this.name = "LoadingException"; } +var polyline_styles = { + "Unknown": { color: 'grey', dashArray: '' }, + "Power": { color: 'red', dashArray: '' }, + "Network": { color: 'blue', dashArray: '' }, + "Wifi": { color: 'blue', dashArray: '1, 10' } +}; + +function polyline_set_type(marker, type) { + marker.setStyle(polyline_styles[type]); + marker.options.type = type; +} + function process_polyline_update(marker_name, marker_info) { if (marker_name in marker_store) { var marker = marker_store[marker_name]; /* TODO: compare array, update only on change*/ marker.setLatLngs(marker_info.points); + if (marker.options.type != marker_info.type) + polyline_set_type(marker, marker_info.type); + marker.options.sync_id = marker_store_sync_id; console.log("Kept polyline '" + marker_name + "'."); } else { @@ -95,6 +111,11 @@ function process_polyline_update(marker_name, marker_info) { } target_layer_group.getLayers()[1].addLayer(marker); + if (marker_info.type !== undefined) { + polyline_set_type(marker, marker_info.type); + } else { + polyline_set_type(marker, "Unknown"); + } marker.options.sync_id = marker_store_sync_id; add_contextmenu(marker); console.log("Added polyline '" + marker_name + "'."); @@ -187,6 +208,7 @@ function delete_marker(marker) { } function add_polyline_contextmenu(marker) { + /* TODO: Generated menu from polyline styles */ marker.bindContextMenu({ contextmenu: true, contextmenuItems: [ @@ -195,6 +217,34 @@ function add_polyline_contextmenu(marker) { callback: function() { delete_marker(marker); } + }, + { + text: 'Power -> Type', + callback: function() { + polyline_set_type(marker, "Power"); + eventmap_send_update(); + } + }, + { + text: 'Network -> Type', + callback: function() { + polyline_set_type(marker, "Network"); + eventmap_send_update(); + } + }, + { + text: 'Wifi -> Type', + callback: function() { + polyline_set_type(marker, "Wifi"); + eventmap_send_update(); + } + }, + { + text: 'Unknown -> Type', + callback: function() { + polyline_set_type(marker, "Unknown"); + eventmap_send_update(); + } } ] }); @@ -361,6 +411,7 @@ function polyline_added(e) { marker_store[marker_name] = created_object; created_object.options.label_text = marker_name; add_contextmenu(created_object); + polyline_set_type(created_object, "Unknown"); eventmap_send_update(); return false; } |