diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/index.html | 2 | ||||
-rw-r--r-- | web/js/eventmap.js | 46 |
2 files changed, 45 insertions, 3 deletions
diff --git a/web/index.html b/web/index.html index b57c57f..388715b 100644 --- a/web/index.html +++ b/web/index.html @@ -5,6 +5,7 @@ <link rel="stylesheet" href="css/leaflet.css" /> <link rel="stylesheet" href="css/leaflet.contextmenu.css" /> <link rel="stylesheet" href="css/leaflet.draw.css" /> + <link rel="stylesheet" href="css/leaflet.label.css" /> <link rel="stylesheet" href="css/eventmap.css" /> </head> <body> @@ -18,6 +19,7 @@ <script src="js/leaflet.js"></script> <script src="js/leaflet.contextmenu.js"></script> <script src="js/leaflet.draw.js"></script> + <script src="js/leaflet.label.js"></script> <script src="js/eventmap.js"></script> </body> </html> diff --git a/web/js/eventmap.js b/web/js/eventmap.js index d95671b..775bb79 100644 --- a/web/js/eventmap.js +++ b/web/js/eventmap.js @@ -3,6 +3,20 @@ var draw_control; var layers = {}; var recorded_obj; +/* Functionality of (re)naming a marker - if I understood how objects worked + * in javascript, this should probably be one. :/ + */ +function rename_marker(marker) { + var label_text; + if (marker.options.label_text === undefined) + label_text = ''; + else + label_text = marker.options.label_text; + + marker.options.label_text = prompt("Please enter name", label_text); + marker.updateLabelContent(marker.options.label_text); +} + /* Functionality of moving a marker - if I understood how objects worked * in javascript, this should probably be one. :/ */ @@ -45,6 +59,20 @@ function move_marker(marker) { move_marker_enable_events(); } +/* other functionality */ +var marker_labels_no_hide = false; +function marker_labels_calc_nohide(e) { + marker_labels_no_hide = (map.getZoom() >= 3); + $.each(layers, function(layer_name, layer_group) { + var drawing_layer; + + drawing_layer = layer_group.getLayers()[1] + $.each(drawing_layer.getLayers(), function(marker_index, marker) { + marker.setLabelNoHide(marker_labels_no_hide); + }); + }); +} + $(function() { map = L.map('map', { center: new L.LatLng(70,-50), @@ -52,6 +80,8 @@ $(function() { zoom: 2 }); + map.on('zoomend', marker_labels_calc_nohide); + draw_control = new L.Control.Draw({ }); map.addControl(draw_control); @@ -60,10 +90,14 @@ $(function() { var created_object_type = e.layerType; var created_object = e.layer; - if (created_object_type === 'marker') { - created_object.bindPopup('A popup!'); + if (created_object_type !== 'marker') { + return; } + created_object.bindLabel('', { + noHide: marker_labels_no_hide + }); + $.each(layers, function(layer_name, layer_object) { if (!map.hasLayer(layer_object)) return true; @@ -75,6 +109,12 @@ $(function() { callback: function() { move_marker(created_object); } + }, + { + text: 'Rename', + callback: function() { + rename_marker(created_object); + } } ]; $.each(layers, function(layer_name, layer_object) { @@ -96,9 +136,9 @@ $(function() { created_object._initContextMenu(); layer_object.getLayers()[1].addLayer(created_object); - recorded_obj = created_object; return false; }); + rename_marker(created_object); }); $.getJSON('js/layers.json', function(data) { |