From 840406a82e55ab7e0d23d7355f4783f4f9afc2af Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 6 Dec 2016 16:40:54 +0100 Subject: [PATCH] refs #2 make marker style option change directly effective --- js/gpxedit.js | 54 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/js/gpxedit.js b/js/gpxedit.js index 13546ec..4afa1f1 100644 --- a/js/gpxedit.js +++ b/js/gpxedit.js @@ -611,38 +611,50 @@ function addTileServer(){ }); } +// affects future markers and also existing ones function updateLeafletDrawMarkerStyle(){ var wst = $('#markerstyleselect').val(); + var theicon; if (wst === 'tp' || wst === 'p'){ - gpxedit.drawControl.setDrawingOptions({ - marker: { - icon: L.divIcon({ - className: 'leaflet-div-icon2', - iconAnchor: [5, 30] - }) - } + theicon = L.divIcon({ + className: 'leaflet-div-icon2', + iconAnchor: [5, 30] }); } else if (wst === 'ts' || wst === 's'){ - gpxedit.drawControl.setDrawingOptions({ - marker: { - icon: L.divIcon({ - iconSize:L.point(6,6), - html:'
' - }) - } + theicon = L.divIcon({ + iconSize:L.point(6,6), + html:'
' }); } else if (wst === 'tm' || wst === 'm'){ - gpxedit.drawControl.setDrawingOptions({ - marker: { - icon: L.divIcon({ - className: 'leaflet-marker-blue', - iconAnchor: [12, 41] - }) - } + theicon = L.divIcon({ + className: 'leaflet-marker-blue', + iconAnchor: [12, 41] }); } + + gpxedit.drawControl.setDrawingOptions({ + marker: { + icon: theicon + } + }); + gpxedit.editableLayers.eachLayer(function(layer){ + var id = layer.gpxedit_id; + var name = gpxedit.layersData[id].name; + if (layer.type === 'marker'){ + layer.setIcon(theicon); + } + if (name !== ''){ + layer.unbindTooltip(); + if (wst === 'tm' || wst === 'tp' || wst === 'ts'){ + layer.bindTooltip(name, {permanent:true}); + } + else{ + layer.bindTooltip(name, {sticky:true}); + } + } + }); } $(document).ready(function(){