handle kml and nvg strings as inputs
This commit is contained in:
parent
0f4edcb95d
commit
a7b78986b3
@ -1,5 +1,6 @@
|
|||||||
### Change Log for Node-RED Worldmap
|
### Change Log for Node-RED Worldmap
|
||||||
|
|
||||||
|
- v2.5.6 - Let node accept plain text payload kml or nvg input
|
||||||
- v2.5.5 - Fix NVG import to handle symbols for points
|
- v2.5.5 - Fix NVG import to handle symbols for points
|
||||||
- v2.5.4 - Fix delete of hulls
|
- v2.5.4 - Fix delete of hulls
|
||||||
- v2.5.3 - Swap default satellite layer
|
- v2.5.3 - Swap default satellite layer
|
||||||
|
@ -11,6 +11,7 @@ map web page for plotting "things" on.
|
|||||||
|
|
||||||
### Updates
|
### Updates
|
||||||
|
|
||||||
|
- v2.5.6 - Let node accept plain text payload kml or nvg input
|
||||||
- v2.5.5 - Fix NVG import to handle symbols for points
|
- v2.5.5 - Fix NVG import to handle symbols for points
|
||||||
- v2.5.4 - Fix delete of hulls
|
- v2.5.4 - Fix delete of hulls
|
||||||
- v2.5.3 - Swap default satellite layer
|
- v2.5.3 - Swap default satellite layer
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-web-worldmap",
|
"name": "node-red-contrib-web-worldmap",
|
||||||
"version": "2.5.5",
|
"version": "2.5.6",
|
||||||
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
|
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cgi": "0.3.1",
|
"cgi": "0.3.1",
|
||||||
@ -8,6 +8,9 @@
|
|||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"sockjs": "~0.3.21"
|
"sockjs": "~0.3.21"
|
||||||
},
|
},
|
||||||
|
"bundledDependencies": [
|
||||||
|
"cgi","compression","express","sockjs"
|
||||||
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/dceejay/RedMap"
|
"url": "https://github.com/dceejay/RedMap"
|
||||||
|
31
worldmap.js
31
worldmap.js
@ -269,13 +269,13 @@ module.exports = function(RED) {
|
|||||||
if (msg.payload.name.substr(-1) === '_') {
|
if (msg.payload.name.substr(-1) === '_') {
|
||||||
var a = node.pointsarray[msg.payload.name.substr(0,msg.payload.name.length-1)].pop();
|
var a = node.pointsarray[msg.payload.name.substr(0,msg.payload.name.length-1)].pop();
|
||||||
node.pointsarray[msg.payload.name.substr(0,msg.payload.name.length-1)] = [ a ];
|
node.pointsarray[msg.payload.name.substr(0,msg.payload.name.length-1)] = [ a ];
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete node.pointsarray[msg.payload.name];
|
delete node.pointsarray[msg.payload.name];
|
||||||
}
|
}
|
||||||
//newmsg.payload.name = msg.payload.name + "_";
|
//newmsg.payload.name = msg.payload.name + "_";
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!msg.payload.hasOwnProperty("lat") || !msg.payload.hasOwnProperty("lon")) { return; }
|
if (!msg.payload.hasOwnProperty("lat") || !msg.payload.hasOwnProperty("lon")) { return; }
|
||||||
@ -356,7 +356,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
doTrack(m);
|
doTrack(m);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -379,25 +379,25 @@ module.exports = function(RED) {
|
|||||||
for (const val of Object.values(points)) {
|
for (const val of Object.values(points)) {
|
||||||
arr.push(val);
|
arr.push(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
arr.sort(function (a, b) {
|
arr.sort(function (a, b) {
|
||||||
return a.lat != b.lat ? a.lat - b.lat : a.lon - b.lon;
|
return a.lat != b.lat ? a.lat - b.lat : a.lon - b.lon;
|
||||||
});
|
});
|
||||||
|
|
||||||
var n = arr.length;
|
var n = arr.length;
|
||||||
var hull = [];
|
var hull = [];
|
||||||
|
|
||||||
for (var i = 0; i < 2 * n; i++) {
|
for (var i = 0; i < 2 * n; i++) {
|
||||||
var j = i < n ? i : 2 * n - 1 - i;
|
var j = i < n ? i : 2 * n - 1 - i;
|
||||||
while (hull.length >= 2 && removeMiddle(hull[hull.length - 2], hull[hull.length - 1], arr[j]))
|
while (hull.length >= 2 && removeMiddle(hull[hull.length - 2], hull[hull.length - 1], arr[j]))
|
||||||
hull.pop();
|
hull.pop();
|
||||||
hull.push(arr[j]);
|
hull.push(arr[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
hull.pop();
|
hull.pop();
|
||||||
return hull;
|
return hull;
|
||||||
}
|
}
|
||||||
|
|
||||||
var removeMiddle = function(a, b, c) {
|
var removeMiddle = function(a, b, c) {
|
||||||
var cross = (a.lat- b.lat) * (c.lon - b.lon) - (a.lon - b.lon) * (c.lat- b.lat);
|
var cross = (a.lat- b.lat) * (c.lon - b.lon) - (a.lon - b.lon) * (c.lat- b.lat);
|
||||||
var dot = (a.lat- b.lat) * (c.lat- b.lat) + (a.lon - b.lon) * (c.lon - b.lon);
|
var dot = (a.lat- b.lat) * (c.lat- b.lat) + (a.lon - b.lon) * (c.lon - b.lon);
|
||||||
@ -427,27 +427,27 @@ module.exports = function(RED) {
|
|||||||
newmsg.payload.name = newmsg.payload[node.prop];
|
newmsg.payload.name = newmsg.payload[node.prop];
|
||||||
newmsg.payload.clickable = true;
|
newmsg.payload.clickable = true;
|
||||||
|
|
||||||
if (leafletHull.length === 1 && oldl === 2) {
|
if (leafletHull.length === 1 && oldl === 2) {
|
||||||
newmsg.payload.deleted = true;
|
newmsg.payload.deleted = true;
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
}
|
}
|
||||||
if (leafletHull.length === 2 && (oldl === 1 || oldl ===3)) {
|
if (leafletHull.length === 2 && (oldl === 1 || oldl ===3)) {
|
||||||
newmsg.payload.deleted = true;
|
newmsg.payload.deleted = true;
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
delete newmsg.payload.deleted;
|
delete newmsg.payload.deleted;
|
||||||
newmsg.payload.line = leafletHull;
|
newmsg.payload.line = leafletHull;
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
}
|
}
|
||||||
if (leafletHull.length === 3 && oldl === 2) {
|
if (leafletHull.length === 3 && oldl === 2) {
|
||||||
newmsg.payload.deleted = true;
|
newmsg.payload.deleted = true;
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
delete newmsg.payload.deleted;
|
delete newmsg.payload.deleted;
|
||||||
}
|
}
|
||||||
if (leafletHull.length >= 3) {
|
if (leafletHull.length >= 3) {
|
||||||
newmsg.payload.area = leafletHull;
|
newmsg.payload.area = leafletHull;
|
||||||
node.send(newmsg);
|
node.send(newmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
oldl = leafletHull.length;
|
oldl = leafletHull.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,7 +461,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
doHull(m);
|
doHull(m);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -471,6 +471,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
RED.nodes.registerType("worldmap-hull",WorldMapHull);
|
RED.nodes.registerType("worldmap-hull",WorldMapHull);
|
||||||
|
|
||||||
|
|
||||||
RED.httpNode.get("/.ui-worldmap", function(req, res) {
|
RED.httpNode.get("/.ui-worldmap", function(req, res) {
|
||||||
res.send(ui ? "true": "false");
|
res.send(ui ? "true": "false");
|
||||||
});
|
});
|
||||||
|
@ -93,7 +93,7 @@ var connect = function() {
|
|||||||
};
|
};
|
||||||
ws.onmessage = function(e) {
|
ws.onmessage = function(e) {
|
||||||
var data = JSON.parse(e.data);
|
var data = JSON.parse(e.data);
|
||||||
//console.log("DATA" typeof data,data);
|
// console.log("DATA",typeof data,data);
|
||||||
if (data) {
|
if (data) {
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
//console.log("ARRAY");
|
//console.log("ARRAY");
|
||||||
@ -110,6 +110,14 @@ var connect = function() {
|
|||||||
// map.fitBounds(bnds.pad(0.25));
|
// map.fitBounds(bnds.pad(0.25));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (typeof data === "string" && data.indexOf("<?xml") == 0) {
|
||||||
|
if (data.indexOf("<nvg") != -1) {
|
||||||
|
data = {command:{map:{overlay:"NVG", nvg:data}}};
|
||||||
|
}
|
||||||
|
else if (data.indexOf("<kml") != -1) {
|
||||||
|
data = {command:{map:{overlay:"KML", kml:data}}};
|
||||||
|
}
|
||||||
|
}
|
||||||
if (data.command) { doCommand(data.command); delete data.command; }
|
if (data.command) { doCommand(data.command); delete data.command; }
|
||||||
if (data.hasOwnProperty("name")) { setMarker(data); }
|
if (data.hasOwnProperty("name")) { setMarker(data); }
|
||||||
else if (data.hasOwnProperty("type")) { doGeojson("geojson",data); }
|
else if (data.hasOwnProperty("type")) { doGeojson("geojson",data); }
|
||||||
|
Loading…
Reference in New Issue
Block a user