From e71332dc1594a23d30bf5709750fa109f549c2a6 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Mon, 15 May 2017 13:55:22 +0100 Subject: [PATCH] Add Tracks node - and fix Windows web socket --- README.md | 1 + package.json | 2 +- worldmap.html | 42 ++++++++++++++++++++++++++++++ worldmap.js | 52 +++++++++++++++++++++++++++++++++++++- worldmap/index.html | 25 ++++++++++++++++-- worldmap/worldmap.appcache | 2 +- 6 files changed, 119 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4f6a4c7..b8b4b47 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ map web page for plotting "things" on. ![Map Image](https://dceejay.github.io/pages/images/redmap.png) ### Changes + - v1.0.29 - Add, tracks node, Fix websocket on Windows - v1.0.28 - Move websocket to specific path, and support satellite node - v1.0.26 - Add info on how to use with local WMS server - v1.0.24 - Add `.weblink` property to allow links out to other information. diff --git a/package.json b/package.json index f2a35a3..05fe7fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-contrib-web-worldmap", - "version" : "1.0.28", + "version" : "1.0.29", "description" : "A Node-RED node to provide a web page of a world map for plotting things on.", "dependencies" : { "express": "^4.15.0", diff --git a/worldmap.html b/worldmap.html index d740f47..cbd8596 100644 --- a/worldmap.html +++ b/worldmap.html @@ -169,3 +169,45 @@ } }); + + + + + + + diff --git a/worldmap.js b/worldmap.js index 03cfc27..d672b9b 100644 --- a/worldmap.js +++ b/worldmap.js @@ -24,7 +24,7 @@ module.exports = function(RED) { var WorldMap = function(n) { RED.nodes.createNode(this,n); if (!socket) { - var fullPath = path.join(RED.settings.httpNodeRoot, 'worldmap', 'socket.io'); + var fullPath = path.posix.join(RED.settings.httpNodeRoot, 'worldmap', 'socket.io'); socket = io.listen(RED.server, {path:fullPath}); } this.lat = n.lat || ""; @@ -104,4 +104,54 @@ module.exports = function(RED) { socket.on('connection', callback); } RED.nodes.registerType("worldmap in",WorldMapIn); + + var satarray = {}; + var WorldMapTracks = function(n) { + RED.nodes.createNode(this,n); + this.depth = Number(n.depth) || 20; + var node = this; + + node.on("input", function(msg) { + if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("name")) { + var newmsg = RED.util.cloneMessage(msg); + if (msg.payload.deleted) { + delete satarray[msg.payload.name]; + newmsg.payload.name = msg.payload.name + "_"; + node.send(newmsg); // send the track to be deleted + return; + } + if (!satarray.hasOwnProperty(msg.payload.name)) { + satarray[msg.payload.name] = []; + } + satarray[msg.payload.name].push(msg.payload); + if (satarray[msg.payload.name].length > node.depth) { + satarray[msg.payload.name].shift(); + } + + var line = []; + for (var i=0; i 1) { // only send track if two points or more + newmsg.payload.line = line; + newmsg.payload.name = msg.payload.name + "_"; + node.send(newmsg); // send the track + } + } + }); + + node.on("close", function() { + satarray = {}; + }); + } + RED.nodes.registerType("worldmap-tracks",WorldMapTracks); } diff --git a/worldmap/index.html b/worldmap/index.html index 7de29f9..579c092 100644 --- a/worldmap/index.html +++ b/worldmap/index.html @@ -223,7 +223,7 @@ if (!inIframe) { // Create the clear heatmap button var clrHeat = L.easyButton( 'Reset Heatmap', function() { - console.log("reset heatmap"); + console.log("Reset heatmap"); heat.setLatLngs([]); }, "Clears the current heatmap", "bottomright"); } @@ -285,6 +285,10 @@ function doTidyUp() { layers[markers[m].lay].removeLayer(polygons[m]); delete polygons[m]; } + if (typeof polygons[m+"_"] != "undefined") { + //layers[markers[m+"_"].lay].removeLayer(polygons[m+"_"]); + delete polygons[m+"_"]; + } delete markers[m]; } } @@ -821,7 +825,7 @@ function setMarker(data) { else if (data.icon === "car") { data.iconColor = data.iconColor || "black"; icon = ''; - icon += ''; + icon += ''; var svgcar = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"caricon", @@ -830,6 +834,23 @@ function setMarker(data) { }); marker = L.marker(ll, {title: data.name, icon: myMarker}); } + else if (data.icon === "satellite") { + data.iconColor = data.iconColor || "black"; + icon = ''; + icon += ''; + icon += ''; + icon += ''; + icon += ''; + icon += ''; + icon += ''; + var svglocate = "data:image/svg+xml;base64," + btoa(icon); + myMarker = L.divIcon({ + className:"satelliteicon", + iconAnchor: [16, 16], + html:'', + }); + marker = L.marker(ll, {title:data.name, icon:myMarker}); + } else if (data.icon === "locate") { data.iconColor = data.iconColor || "cyan"; icon = ''; diff --git a/worldmap/worldmap.appcache b/worldmap/worldmap.appcache index 11d4c08..8cafa73 100644 --- a/worldmap/worldmap.appcache +++ b/worldmap/worldmap.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# date: May 2nd 2017 - v1.0.28 +# date: May 2nd 2017 - v1.0.29 CACHE: index.html