From 2335e7ed9a68b98111425694413ed7ccbad92c21 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 25 Jun 2021 15:38:34 +0100 Subject: [PATCH] let clear heatmap command clear heatmap... to address Issue #170 --- CHANGELOG.md | 1 + README.md | 1 + examples/Map in Dashboard.json | 178 +-------------------------------- package.json | 2 +- worldmap/worldmap.js | 41 ++++---- 5 files changed, 27 insertions(+), 196 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2231165..2137e15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v2.15.4 - Let clear heatmap command do what it says. - v2.15.3 - Fix panit command to work, try to use alt units, popup alignments. - v2.15.0 - let speed be text and specify units if required (kt,kn,knots,mph,kmh,kph) default m/s. - v2.14.0 - Let geojson features be clickable if added as overlay. diff --git a/README.md b/README.md index a3b894b..7357b30 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ map web page for plotting "things" on. ### Updates +- v2.15.4 - Let clear heatmap command do what it says. - v2.15.3 - Fix panit command to work, try to use alt units, popup alignments. - v2.15.0 - let speed be text and specify units if required (kt,kn,knots,mph,kmh,kph) default m/s. - v2.14.0 - Let geojson features be clickable if added as overlay. diff --git a/examples/Map in Dashboard.json b/examples/Map in Dashboard.json index 57b47e2..51a1ba6 100644 --- a/examples/Map in Dashboard.json +++ b/examples/Map in Dashboard.json @@ -1,177 +1 @@ -[ - { - "id": "9b2a29cc.3c53a8", - "type": "worldmap", - "z": "f59603d8.0a6a", - "name": "", - "lat": "", - "lon": "", - "zoom": "", - "layer": "OSM", - "cluster": "", - "maxage": "", - "usermenu": "hide", - "panit": "true", - "x": 750, - "y": 420, - "wires": [] - }, - { - "id": "1714967f.e691ea", - "type": "inject", - "z": "f59603d8.0a6a", - "name": "", - "topic": "", - "payload": "", - "payloadType": "str", - "repeat": "", - "crontab": "", - "once": false, - "onceDelay": "", - "x": 290, - "y": 360, - "wires": [ - [ - "1b24ad2f.198453" - ] - ] - }, - { - "id": "1b24ad2f.198453", - "type": "function", - "z": "f59603d8.0a6a", - "name": "", - "func": "// create random position\nvar lat = 51 + Math.random() * 0.2;\nvar lon = -1.45 + Math.random() * 0.2;\nmsg.payload={\n lat:lat, \n lon:lon, \n name:\"Mike\", \n icon:\"male\", \n color:\"#000\"};\nreturn msg;", - "outputs": 1, - "noerr": 0, - "x": 470, - "y": 420, - "wires": [ - [ - "9b2a29cc.3c53a8", - "de5c4044.d4e0f" - ] - ] - }, - { - "id": "5af27cae.299144", - "type": "inject", - "z": "f59603d8.0a6a", - "name": "", - "topic": "", - "payload": "", - "payloadType": "str", - "repeat": "", - "crontab": "", - "once": true, - "onceDelay": "", - "x": 270, - "y": 480, - "wires": [ - [ - "f1be23c1.dd096" - ] - ] - }, - { - "id": "4bab3415.afdf9c", - "type": "ui_template", - "z": "f59603d8.0a6a", - "group": "cd81d08b.eebb3", - "name": "", - "order": 0, - "width": "6", - "height": "6", - "format": "
", - "storeOutMessages": true, - "fwdInMessages": true, - "templateScope": "local", - "x": 640, - "y": 480, - "wires": [ - [] - ] - }, - { - "id": "f1be23c1.dd096", - "type": "template", - "z": "f59603d8.0a6a", - "name": "", - "field": "payload", - "fieldType": "msg", - "format": "handlebars", - "syntax": "mustache", - "template": "", - "x": 470, - "y": 480, - "wires": [ - [ - "4bab3415.afdf9c" - ] - ] - }, - { - "id": "de3a90c8.8179c", - "type": "ui_button", - "z": "f59603d8.0a6a", - "name": "", - "group": "cd81d08b.eebb3", - "order": 0, - "width": 0, - "height": 0, - "label": "Move Mike", - "color": "", - "icon": "fa-male", - "payload": "", - "payloadType": "str", - "topic": "", - "x": 290, - "y": 420, - "wires": [ - [ - "1b24ad2f.198453" - ] - ] - }, - { - "id": "223f301c.54ea9", - "type": "comment", - "z": "f59603d8.0a6a", - "name": "How to embed Map in Dashboard", - "info": "This example shows how to embed the Worldmap \ninto a template node within the `node-red-dashboard`\n\nThe first flow creates a dashboard button that \ngenerates a randon position, with the required \nicon, and passes that to the worldmap. The\nmap is configured to automatically pan to the\nposition of any point that arrives.\n\nThe second flow initialise the dashboard template\nwith the initial map and sets it to a more square shape\nby adjusting the height.", - "x": 340, - "y": 300, - "wires": [] - }, - { - "id": "de5c4044.d4e0f", - "type": "worldmap-tracks", - "z": "f59603d8.0a6a", - "name": "", - "depth": "5", - "layer": "combined", - "x": 610, - "y": 380, - "wires": [ - [ - "9b2a29cc.3c53a8" - ] - ] - }, - { - "id": "cd81d08b.eebb3", - "type": "ui_group", - "z": "f59603d8.0a6a", - "name": "Default", - "tab": "b34078e6.e60df8", - "disp": true, - "width": "6" - }, - { - "id": "b34078e6.e60df8", - "type": "ui_tab", - "z": "f59603d8.0a6a", - "name": "Home", - "icon": "dashboard" - } -] +[{"id":"1714967f.e691ea","type":"inject","z":"64eed394.c7935c","name":"","repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"str","x":180,"y":800,"wires":[["1b24ad2f.198453"]]},{"id":"1b24ad2f.198453","type":"function","z":"64eed394.c7935c","name":"","func":"// create random position\nvar lat = 51 + Math.random() * 0.2;\nvar lon = -1.45 + Math.random() * 0.2;\nmsg.payload={\n lat:lat, \n lon:lon, \n name:\"Mike\", \n icon:\"male\", \n color:\"#000\"};\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":860,"wires":[["de5c4044.d4e0f","e0ec963913cbf7a9"]]},{"id":"de3a90c8.8179c","type":"ui_button","z":"64eed394.c7935c","name":"","group":"cd81d08b.eebb3","order":0,"width":0,"height":0,"passthru":false,"label":"Move Mike","tooltip":"","color":"","bgcolor":"","icon":"fa-male","payload":"","payloadType":"str","topic":"","topicType":"str","x":180,"y":860,"wires":[["1b24ad2f.198453"]]},{"id":"223f301c.54ea9","type":"comment","z":"64eed394.c7935c","name":"How to embed Map in Dashboard","info":"This example shows how to embed the Worldmap \nwithin the `node-red-dashboard`\n\nThe flow creates a dashboard button that \ngenerates a randon position, with the required \nicon, and passes that to the worldmap. The\nmap is configured to automatically pan to the\nposition of any point that arrives.\n","x":230,"y":740,"wires":[]},{"id":"de5c4044.d4e0f","type":"worldmap-tracks","z":"64eed394.c7935c","name":"","depth":"5","layer":"combined","x":500,"y":820,"wires":[["e0ec963913cbf7a9"]]},{"id":"e0ec963913cbf7a9","type":"ui_worldmap","z":"64eed394.c7935c","group":"cd81d08b.eebb3","order":4,"width":0,"height":0,"name":"","lat":"","lon":"","zoom":"","layer":"","cluster":"","maxage":"","usermenu":"hide","layers":"hide","panit":"true","panlock":"false","zoomlock":"false","hiderightclick":"true","coords":"none","showgrid":"true","allowFileDrop":"false","path":"/worldmap","x":660,"y":860,"wires":[]},{"id":"cd81d08b.eebb3","type":"ui_group","z":"64eed394.c7935c","name":"Default","tab":"b34078e6.e60df8","order":1,"disp":true,"width":"6"},{"id":"b34078e6.e60df8","type":"ui_tab","z":"64eed394.c7935c","name":"Home","icon":"dashboard"}] \ No newline at end of file diff --git a/package.json b/package.json index 4e58fd2..b496602 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-web-worldmap", - "version": "2.15.3", + "version": "2.15.4", "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 f7f272d..fdfff6e 100644 --- a/worldmap/worldmap.js +++ b/worldmap/worldmap.js @@ -385,27 +385,32 @@ function doLock(v) { // Remove old markers function doTidyUp(l) { - var d = parseInt(Date.now()/1000); - for (var m in markers) { - if ((l && (l == markers[m].lay)) || typeof markers[m].ts != "undefined") { - if ((l && (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") && (Number(markers[m].ts) < d) && (markers[m].lay !== "_drawing"))) { - //console.log("STALE :",m); - if (typeof polygons[m+"_"] != "undefined") { - layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]); - delete polygons[m+"_"]; - } - if (typeof polygons[m] != "undefined") { - layers[markers[m].lay].removeLayer(polygons[m]); - delete polygons[m]; + if (l === "heatmap") { + heat.setLatLngs([]); + } + else { + var d = parseInt(Date.now()/1000); + for (var m in markers) { + if ((l && (l == markers[m].lay)) || typeof markers[m].ts != "undefined") { + if ((l && (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") && (Number(markers[m].ts) < d) && (markers[m].lay !== "_drawing"))) { + //console.log("STALE :",m); + if (typeof polygons[m+"_"] != "undefined") { + layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]); + delete polygons[m+"_"]; + } + if (typeof polygons[m] != "undefined") { + layers[markers[m].lay].removeLayer(polygons[m]); + delete polygons[m]; + } + layers[markers[m].lay].removeLayer(markers[m]); + delete markers[m]; } - layers[markers[m].lay].removeLayer(markers[m]); - delete markers[m]; } } - } - if (l) { - if (layers[l]) { map.removeLayer(layers[l]); layercontrol.removeLayer(layers[l]); delete layers[l]; } - if (overlays[l]) { map.removeLayer(overlays[l]); layercontrol.removeLayer(overlays[l]); delete overlays[l]; } + if (l) { + if (layers[l]) { map.removeLayer(layers[l]); layercontrol.removeLayer(layers[l]); delete layers[l]; } + if (overlays[l]) { map.removeLayer(overlays[l]); layercontrol.removeLayer(overlays[l]); delete overlays[l]; } + } } }