fix deleting hulls cleanly

This commit is contained in:
Dave Conway-Jones 2020-09-02 16:38:01 +01:00
parent 6595aa7dd6
commit f9b6c6743a
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
4 changed files with 29 additions and 8 deletions

View File

@ -1,5 +1,7 @@
### Change Log for Node-RED Worldmap ### Change Log for Node-RED Worldmap
- v2.5.4 - Fix delete of hulls
- v2.5.3 - Swap default satellite layer
- v2.5.2 - Add boolean parameter to feedback call to allow auto close of popup on click. Set Esc key to close all open popups. Issue #146 - v2.5.2 - Add boolean parameter to feedback call to allow auto close of popup on click. Set Esc key to close all open popups. Issue #146
- v2.5.1 - Add lat, lng and layer to feedback function. - v2.5.1 - Add lat, lng and layer to feedback function.
- v2.5.0 - Add minimap capability. - v2.5.0 - Add minimap capability.

View File

@ -11,6 +11,8 @@ map web page for plotting "things" on.
### Updates ### Updates
- v2.5.4 - Fix delete of hulls
- v2.5.3 - Swap default satellite layer
- v2.5.2 - Add boolean parameter to feedback call to allow auto close of popup on click. Set Esc key to close all open popups. Issue #146 - v2.5.2 - Add boolean parameter to feedback call to allow auto close of popup on click. Set Esc key to close all open popups. Issue #146
- v2.5.1 - Add lat, lng and layer to feedback function. - v2.5.1 - Add lat, lng and layer to feedback function.
- v2.5.0 - Add minimap capability. - v2.5.0 - Add minimap capability.

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-web-worldmap", "name": "node-red-contrib-web-worldmap",
"version": "2.5.3", "version": "2.5.4",
"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",

View File

@ -371,6 +371,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.prop = n.prop || "layer"; this.prop = n.prop || "layer";
var node = this; var node = this;
var oldl = 0;
node.hulls = {}; node.hulls = {};
var convexHull = function(points) { var convexHull = function(points) {
@ -423,15 +424,31 @@ module.exports = function(RED) {
var convexHullPoints = convexHull(node.hulls[newmsg.payload[node.prop]]); var convexHullPoints = convexHull(node.hulls[newmsg.payload[node.prop]]);
var leafletHull = convexHullPoints.map(function (element) {return ([element.lat,element.lon])}) var leafletHull = convexHullPoints.map(function (element) {return ([element.lat,element.lon])})
if (leafletHull.length > 1) { newmsg.payload.name = newmsg.payload[node.prop];
// if (leafletHull.length === 2) { newmsg.payload.line = leafletHull; } newmsg.payload.clickable = true;
// else {
newmsg.payload.area = leafletHull; if (leafletHull.length === 1 && oldl === 2) {
// } newmsg.payload.deleted = true;
newmsg.payload.name = newmsg.payload[node.prop];
newmsg.payload.clickable = true;
node.send(newmsg); node.send(newmsg);
} }
if (leafletHull.length === 2 && (oldl === 1 || oldl ===3)) {
newmsg.payload.deleted = true;
node.send(newmsg);
delete newmsg.payload.deleted;
newmsg.payload.line = leafletHull;
node.send(newmsg);
}
if (leafletHull.length === 3 && oldl === 2) {
newmsg.payload.deleted = true;
node.send(newmsg);
delete newmsg.payload.deleted;
}
if (leafletHull.length >= 3) {
newmsg.payload.area = leafletHull;
node.send(newmsg);
}
oldl = leafletHull.length;
} }
} }