From 5a99aaf57d67106d95f035c5ed59d82c1e228c54 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 16 Aug 2019 17:25:45 +0100 Subject: [PATCH] allow loading overlays hidden to also not trigger addlayer event to close #108 --- CHANGELOG.md | 1 + README.md | 5 ++++- package.json | 2 +- worldmap/worldmap.js | 28 +++++++++++++++++++++------- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9edf361..4fe950c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v2.0.21 - allow adding overlays without making them visible (visible:false) - Issue #108 - v2.0.20 - ensure `fit` option is boolean, Issue #109. Fix track layers, Issue #110. - v2.0.18 - Stop map contextmenu bleedthrough to marker. Add compress middleware. - v2.0.17 - Let clear command also clear tracks from tracks node diff --git a/README.md b/README.md index c8adf2e..68b1acd 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ map web page for plotting "things" on. ### Updates +- v2.0.21 - allow adding overlays without making them visible (visible:false) - Issue #108 - v2.0.20 - ensure `fit` option is boolean, Issue #109. Fix track layers, Issue #110. - v2.0.18 - Stop map contextmenu bleedthrough to marker. Add compress middleware. - v2.0.17 - Let clear command also clear tracks from tracks node @@ -399,6 +400,8 @@ To add an overlay instead of a base layer - specify the `overlay` property inste "wms": true } +By default the overlay will be instantly visible. To load it hidden add a property to the command.map - `visible:false` + #### To add a new geoJSON overlay msg.payload.command.map = { @@ -431,7 +434,7 @@ As per the geojson overlay you can also inject a KML layer, GPX layer or TOPOJSO - **icon** : font awesome icon name. - **iconColor** : Standard CSS colour name or #rrggbb hex value. -Again the boolean `fit` property can be added to make the map zoom to the relevant area. +Again the boolean `fit` property can be added to make the map zoom to the relevant area, and the `visible` property can be set false to not immediately show the layer. #### To add a Velocity Grid Overlay diff --git a/package.json b/package.json index e6ed310..2e1b6f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-web-worldmap", - "version": "2.0.20", + "version": "2.0.21", "description": "A Node-RED node to provide a web page of a world map for plotting things on.", "dependencies": { "cgi": "0.3.1", diff --git a/worldmap/worldmap.js b/worldmap/worldmap.js index f31a9e3..53e9c7e 100644 --- a/worldmap/worldmap.js +++ b/worldmap/worldmap.js @@ -1677,7 +1677,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } if (cmd.map.hasOwnProperty("fit") && (cmd.map.fit === true)) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); } } // Add a new NVG XML overlay layer @@ -1716,7 +1718,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); } } var custIco = function() { @@ -1747,7 +1751,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); } } // Add a new TOPOJSON overlay layer @@ -1760,7 +1766,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); } } // Add a new GPX overlay layer @@ -1774,7 +1782,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); } } // Add a new velocity overlay layer @@ -1787,7 +1797,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } if (cmd.map.hasOwnProperty("fit")) { map.fitBounds(overlays[cmd.map.overlay].getBounds()); } } // Add a new overlay layer @@ -1814,7 +1826,9 @@ function doCommand(cmd) { if (!existsalready) { layercontrol.addOverlay(overlays[cmd.map.overlay],cmd.map.overlay); } - map.addLayer(overlays[cmd.map.overlay]); + if (!cmd.map.hasOwnProperty("visible") || (cmd.map.visible != false)) { + map.addLayer(overlays[cmd.map.overlay]); + } } // Swap a base layer if (cmd.layer && basemaps.hasOwnProperty(cmd.layer)) {