From 5eb3985ad1290a25fa7a7357dfca4be8c67921f0 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 24 Sep 2021 14:08:18 +0100 Subject: [PATCH] adjust ui timing check for ui_worldmap --- CHANGELOG.md | 1 + README.md | 1 + package.json | 2 +- worldmap.js | 105 +++++++++++++++++++++++++-------------------------- 4 files changed, 54 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eef3a60..c3a02fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v2.15.8 - Adjust ui check timing for UI worldmap. - v2.15.7 - Tidy up geoJson handling a bit more. - v2.15.5 - Fix SIDC icons to accept unicoded icons as labels. - v2.15.4 - Let clear heatmap command do what it says. diff --git a/README.md b/README.md index 5af7669..f42aa30 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ map web page for plotting "things" on. ### Updates +- v2.15.8 - Adjust ui check timing for UI worldmap. - v2.15.7 - Tidy up geoJson handling a bit more. - v2.15.5 - Fix SIDC icons to accept unicoded icons as labels. - v2.15.4 - Let clear heatmap command do what it says. diff --git a/package.json b/package.json index 43d3aad..dc14805 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-web-worldmap", - "version": "2.15.7", + "version": "2.15.8", "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.js b/worldmap.js index 6a5d599..2717e1f 100644 --- a/worldmap.js +++ b/worldmap.js @@ -31,13 +31,12 @@ module.exports = function(RED) { function worldMap(node, n) { RED.nodes.createNode(node,n); - node.lat = n.lat || ""; - node.lon = n.lon || ""; - node.zoom = n.zoom || ""; + node.lat = n.lat ?? ""; + node.lon = n.lon ?? ""; + node.zoom = n.zoom ?? ""; node.layer = n.layer || ""; node.cluster = n.cluster || ""; - node.maxage = n.maxage || ""; - if (n.maxage == 0) { node.maxage = "0"; } + node.maxage = n.maxage ?? ""; node.showmenu = n.usermenu || "show"; node.layers = n.layers || "show"; node.panlock = n.panlock || "false"; @@ -127,7 +126,6 @@ module.exports = function(RED) { }); sockets[node.path].on('connection', callback); } - var WorldMap = function(n) { worldMap(this, n); } @@ -161,54 +159,54 @@ module.exports = function(RED) { } var ui = undefined; + try { + ui = RED.require("node-red-dashboard")(RED); + } + catch(e) { + RED.log.info("Node-RED Dashboard not found - ui_worldmap not installed."); + } setTimeout( function() { - try { - ui = RED.require("node-red-dashboard")(RED); - if (ui) { - function UIWorldMap(config) { - try { - var node = this; - worldMap(node, config); - var done = null; - if (checkConfig(node, config)) { - var html = HTML(ui, config); - done = ui.addWidget({ - node: node, - order: config.order, - group: config.group, - width: config.width, - height: config.height, - format: html, - templateScope: "local", - emitOnlyNewValues: false, - forwardInputMessages: false, - storeFrontEndInputAsState: false, - convertBack: function (value) { - return value; - }, - beforeEmit: function(msg, value) { - return { msg: { items: value } }; - }, - beforeSend: function (msg, orig) { - if (orig) { return orig.msg; } - }, - initController: function($scope, events) { - } - }); - } + if (ui) { + function UIWorldMap(config) { + try { + var node = this; + worldMap(node, config); + var done = null; + if (checkConfig(node, config)) { + var html = HTML(ui, config); + done = ui.addWidget({ + node: node, + order: config.order, + group: config.group, + width: config.width, + height: config.height, + format: html, + templateScope: "local", + emitOnlyNewValues: false, + forwardInputMessages: false, + storeFrontEndInputAsState: false, + convertBack: function (value) { + return value; + }, + beforeEmit: function(msg, value) { + return { msg: { items: value } }; + }, + beforeSend: function (msg, orig) { + if (orig) { return orig.msg; } + }, + initController: function($scope, events) { + } + }); } - catch (e) { - console.log(e); - } - node.on("close", function() { - if (done) { done(); } - }); } - setImmediate(function() { RED.nodes.registerType("ui_worldmap", UIWorldMap) }); + catch (e) { + console.log(e); + } + node.on("close", function() { + if (done) { done(); } + }); } - } - catch(e) { - RED.log.info("Node-RED Dashboard not found - ui_worldmap not installed."); + setImmediate(function() { RED.nodes.registerType("ui_worldmap", UIWorldMap) }); } }, 250); @@ -280,7 +278,7 @@ module.exports = function(RED) { var bezierSpline = require("@turf/bezier-spline").default; var doTrack = function(msg) { - if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("name")) { + if (msg?.payload.hasOwnProperty("name")) { var newmsg = RED.util.cloneMessage(msg); if (msg.payload.deleted) { if (msg.payload.name.substr(-1) === '_') { @@ -359,7 +357,7 @@ module.exports = function(RED) { node.send(newmsg); // send the track } } - if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("command") && msg.payload.command.hasOwnProperty("clear")) { + if (msg?.payload?.command.hasOwnProperty("clear")) { for (var p in node.pointsarray) { if (node.pointsarray.hasOwnProperty(p)) { if (node.pointsarray[p][0].layer === msg.payload.command.clear) { @@ -427,7 +425,7 @@ module.exports = function(RED) { } var doHull = function(msg) { - if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("name")) { + if (msg?.payload.hasOwnProperty("name")) { var newmsg = RED.util.cloneMessage(msg); newmsg.payload = {}; newmsg.payload[node.prop] = msg.payload[node.prop] || "unknown"; @@ -503,7 +501,6 @@ module.exports = function(RED) { } RED.nodes.registerType("worldmap-hull",WorldMapHull); - RED.httpNode.get("/.ui-worldmap", function(req, res) { res.send(ui ? "true": "false"); });