From 24f3a066bace6b360a9e5d70bf3cb3a6e95bf565 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Mon, 22 Oct 2018 22:09:56 +0100 Subject: [PATCH] Allow show/hidelayer to add multiple overlyas in one go To close #53 --- CHANGELOG.md | 3 ++- README.md | 7 ++++--- worldmap/index.html | 25 +++++++++++++++++++------ worldmap/worldmap.appcache | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f19585..f8e0cb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### Change Log for Node-RED Worldmap - - v1.5.4 - allow remote update of the split position via `msg.command.split` + - v1.5.5 - Allow multiple overlays to be enabled at once - Issue #53 + - v1.5.4 - Allow remote update of the split position via `msg.command.split` - v1.5.3 - Add side by side mode (via `msg.command` only). - v1.5.2 - Make manually added icons moveable by default. - v1.5.0 - Add multi-map capability - can now have multiple map endpoints. Issue #40 PR #51 diff --git a/README.md b/README.md index c127f15..1422ea1 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ map web page for plotting "things" on. ### Updates -- v1.5.4 - allow remote update of the split position via `msg.command.split` +- v1.5.5 - Allow multiple overlays to be enabled at once - Issue #53 +- v1.5.4 - Allow remote update of the split position via `msg.command.split` - v1.5.3 - Add side by side mode (via `msg.command` only). - v1.5.2 - Make manually added icons moveable by default. - v1.5.0 - Add multi-map capability - can now have multiple map endpoints. @@ -245,8 +246,8 @@ Optional properties include - **lon** - move map to specified longitude. - **zoom** - move map to specified zoom level (1 - world, 13 to 20 max zoom depending on map). - **layer** - set map to specified base layer name - `{command:{layer:"Esri"}}` - - **showlayer** - show the named overlay - `{command:{showlayer:"foo"}}` - - **hidelayer** - hide the named overlay - `{command:{hidelayer:"bar"}}` + - **showlayer** - show the named overlay(s) - `{command:{showlayer:"foo"}}` or `{command:{showlayer:["foo","bar"]}}` + - **hidelayer** - hide the named overlay(s) - `{command:{hidelayer:"bar"}}` or `{command:{hidelayer:["bar","another"}}` - **side** - add a second map alongside with slide between them. Use the name of the *baselayer* to add - or "none" to remove the control. - `{command:{side:"Esri Satellite"}}` - **split** - once you have split the screen - the split value is the % across the screen of the split line. - `{command:{split:50}}` - **map** - Object containing details of a new map layer: diff --git a/worldmap/index.html b/worldmap/index.html index e34cbc1..02b35f8 100644 --- a/worldmap/index.html +++ b/worldmap/index.html @@ -1506,13 +1506,26 @@ function doCommand(cmd) { sidebyside.lay = cmd.side; } if (cmd.split && sidebyside && (cmd.split <= 100) && (cmd.split >= 0)) { console.log("DING",cmd.split); sidebyside.setSplit(cmd.split); } - // Turn on an existing overlay - if (cmd.hasOwnProperty("showlayer") && overlays.hasOwnProperty(cmd.showlayer)) { - map.addLayer(overlays[cmd.showlayer]); + // Turn on an existing overlay(s) + if (cmd.hasOwnProperty("showlayer")) { + if (typeof cmd.showlayer === "string") { cmd.showlayer = [ cmd.showlayer ]; } + console.log(typeof cmd.showlayer,cmd.showlayer); + for (var i=0; i < cmd.showlayer.length; i++) { + console.log(cmd.showlayer[i]); + if (overlays.hasOwnProperty(cmd.showlayer[i])) { + console.log("DING"); + map.addLayer(overlays[cmd.showlayer[i]]); + } + } } - // Turn off an existing overlay - if (cmd.hasOwnProperty("hidelayer") && overlays.hasOwnProperty(cmd.hidelayer)) { - map.removeLayer(overlays[cmd.hidelayer]); + // Turn off an existing overlay(s) + if (cmd.hasOwnProperty("hidelayer")) { + if (typeof cmd.hidelayer === "string") { cmd.hidelayer = [ cmd.hidelayer ]; } + for (var i=0; i < cmd.hidelayer.length; i++) { + if (overlays.hasOwnProperty(cmd.hidelayer[i])) { + map.removeLayer(overlays[cmd.hidelayer[i]]); + } + } } var clat = map.getCenter().lat; var clon = map.getCenter().lng; diff --git a/worldmap/worldmap.appcache b/worldmap/worldmap.appcache index 742c6a6..1f3db5d 100644 --- a/worldmap/worldmap.appcache +++ b/worldmap/worldmap.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# date: Oct 17th 2018 - v1.5.4 +# date: Oct 17th 2018 - v1.5.5 CACHE: index.html