From 63f064e481b42252c0916359e752c678156c11e2 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Thu, 12 Dec 2013 07:18:04 +0100 Subject: Allow to label nodes --- web/index.html | 2 ++ 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 @@ + @@ -18,6 +19,7 @@ + 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) { -- cgit v1.2.1