Skip to content

Commit 6ff6ce6

Browse files
committed
Let clicks be sendable, let buttons be updateable
to close #308 and close #309
1 parent 2004bd7 commit 6ff6ce6

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Change Log for Node-RED Worldmap
22

3+
- v5.2.0 - Allow left click send back co-ords. Let Button be replaceable more easily and take value property. Issue #308 and #309
34
- v5.1.6 - Let Cot __milsym set the SIDC if present.
45
- v5.1.5 - Fix links to SIDC unitgenerator so it is now local.
56
- v5.1.4 - Fix clearlayer for tracks node.
@@ -8,13 +9,13 @@
89
- v5.1.0 - Let special icons be sizeable using iconSize property.
910
- v5.0.9 - Slight tidy on flags, bump turf dep.
1011
- v5.0.8 - Fix flag handling for SIDC 2525D, add example.
11-
- v5.0.7 - Allow Tooltip options (see new example). #PR295.
12+
- v5.0.7 - Allow Tooltip options (see new example). PR #295.
1213
- v5.0.6 - Tweak SIDC flag handling slightly to show direction if available and moving.
1314
- v5.0.4 - Tweak CoT handling slightly.
14-
- v5.0.3 - Add great context menu example flow. PR#290. Bump express lib. PR#291.
15-
- v5.0.2 - Fix sidcEdgeIcon docs PR#289.
15+
- v5.0.3 - Add great context menu example flow. PR #290. Bump express lib. PR #291.
16+
- v5.0.2 - Fix sidcEdgeIcon docs PR #289.
1617
- v5.0.1 - Fix isArray error PR #288.
17-
- v5.0.0 - Feedback cleanup PR#281, edgeicons option PR#287, bump libs for vuln fixes.
18+
- v5.0.0 - Feedback cleanup PR #281, edgeicons option PR #287, bump libs for vuln fixes.
1819
- v4.9.0 - If payload.flag is two char ISO code replace it with flag emoji. Revert part of PR #271
1920
- v4.8.1 - Slight tidy of some of the geojson handling
2021
- v4.8.0 - Merged PR for feedback functionality cleanup and example. PR #271 and #272

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
1313

1414
### Updates
1515

16+
- v5.2.0 - Allow left click send back co-ords. Let Button be replaceable more easily and take value property. Issue #308 and #309
1617
- v5.1.6 - Let Cot __milsym set the SIDC if present.
1718
- v5.1.5 - Fix links to SIDC unitgenerator so it is now local.
1819
- v5.1.4 - Fix clearlayer for tracks node.
@@ -21,13 +22,13 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
2122
- v5.1.0 - Let special icons be sizeable using iconSize property.
2223
- v5.0.9 - Slight tidy on flags, bump turf dep.
2324
- v5.0.8 - Fix flag handling for SIDC 2525D, add example.
24-
- v5.0.7 - Allow Tooltip options (see new example). #PR295.
25+
- v5.0.7 - Allow Tooltip options (see new example). PR #295.
2526
- v5.0.6 - Tweak SIDC flag handling slightly to show direction if available and moving.
2627
- v5.0.4 - Tweak CoT handling slightly.
27-
- v5.0.3 - Add great context menu example flow. PR#290. Bump express lib. PR#291.
28-
- v5.0.2 - Fix sidcEdgeIcon docs PR#289.
28+
- v5.0.3 - Add great context menu example flow. PR #290. Bump express lib. PR #291.
29+
- v5.0.2 - Fix sidcEdgeIcon docs PR #289.
2930
- v5.0.1 - Fix isArray error PR #288.
30-
- v5.0.0 - v5.0.0 - Feedback cleanup PR#281, edgeicons option PR#287, bump libs for vuln fixes.
31+
- v5.0.0 - v5.0.0 - Feedback cleanup PR #281, edgeicons option PR #287, bump libs for vuln fixes.
3132

3233

3334
- see [CHANGELOG](https://github.com/dceejay/RedMap/blob/master/CHANGELOG.md) for full list of changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-web-worldmap",
3-
"version": "5.1.6",
3+
"version": "5.2.0",
44
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
55
"dependencies": {
66
"@turf/bezier-spline": "~7.2.0",

worldmap.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@
667667
{ value: "layer", label: "Add, remove layers"},
668668
{ value: "bounds", label: "Boundary change"},
669669
{ value: "files", label: "File drop"},
670+
{ value: "click", label: "Click on map"},
670671
{ value: "other", label: "All other"}
671672
]
672673
}]});

worldmap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ module.exports = function(RED) {
323323
var WorldMapIn = function(n) {
324324
RED.nodes.createNode(this,n);
325325
this.path = n.path || "/worldmap";
326-
this.events = n.events || "connect,disconnect,point,layer,bounds,files,draw,other";
326+
this.events = n.events || "connect,disconnect,point,layer,bounds,files,draw,click,other";
327327
if (this.path.charAt(0) != "/") { this.path = "/" + this.path; }
328328
if (!sockets[this.path]) {
329329
var libPath = path.posix.join(RED.settings.httpNodeRoot, this.path, 'leaflet', 'sockjs.min.js');
@@ -349,6 +349,9 @@ module.exports = function(RED) {
349349
if ((node.events.indexOf("bounds")!==-1) && (message.action === "bounds")) {
350350
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
351351
}
352+
if ((node.events.indexOf("click")!==-1) && (message.action === "click")) {
353+
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
354+
}
352355
if ((node.events.indexOf("point")!==-1) && ((message.action === "point")||(message.action === "move")||(message.action === "delete") )) {
353356
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
354357
}
@@ -362,7 +365,7 @@ module.exports = function(RED) {
362365
if ((node.events.indexOf("draw")!==-1) && ((message.action === "draw")||(message.action === "drawdelete"))) {
363366
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
364367
}
365-
if (node.events.indexOf("other")!==-1 && "connected,point,addlayer,dellayer,delete,move,draw,drawdelete,files,bounds".indexOf(message.action) === -1) {
368+
if (node.events.indexOf("other")!==-1 && "connected,point,addlayer,dellayer,delete,move,draw,drawdelete,files,bounds,click".indexOf(message.action) === -1) {
366369
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
367370
}
368371
}

worldmap/worldmap.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,9 @@ var feedback = function(n = "map",v,a = "feedback",c) {
938938
if (c === true) { map.closePopup(); }
939939
}
940940

941-
// map.on('click', function(e) {
942-
// ws.send(JSON.stringify({action:"click", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5)}));
943-
// });
941+
map.on('click', function(e) {
942+
ws.send(JSON.stringify({action:"click", lat:e.latlng.lat.toFixed(5), lon:e.latlng.lng.toFixed(5)}));
943+
});
944944

945945
// allow double right click to zoom out (if enabled)
946946
// single right click opens a message window that adds a marker
@@ -1966,7 +1966,6 @@ function setMarker(data) {
19661966
iconAnchor: [sizc, sizc],
19671967
html:'<img src="'+svgarrow+'" style="width:'+siz+'px; height:'+siz+'px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>',
19681968
});
1969-
console.log("MM",myMarker)
19701969
marker = L.marker(ll, {title:data["name"], icon:myMarker, draggable:drag});
19711970
}
19721971
else if (data.icon === "wind") {
@@ -2602,14 +2601,17 @@ function doCommand(cmd) {
26022601
if (cmd.hasOwnProperty("button")) {
26032602
if (!Array.isArray(cmd.button)) { cmd.button = [cmd.button]; }
26042603
cmd.button.forEach(function(b) {
2605-
if (b.icon) {
2606-
if (!buttons[b.name]) {
2607-
buttons[b.name] = L.easyButton( b.icon, function() {
2608-
ws.send(JSON.stringify({action:"button", name:b.name}));
2609-
}, b.name, { position:b.position||'topright' }).addTo(map);
2604+
if (b.name && b.icon) {
2605+
if (buttons[b.name]) {
2606+
buttons[b.name].removeFrom(map);
2607+
delete buttons[b.name];
26102608
}
2609+
buttons[b.name] = L.easyButton( b.icon, function() {
2610+
ws.send(JSON.stringify({action:"button", name:b.name, value:b?.value}));
2611+
}, b.name, { position:b.position||'topright' });
2612+
buttons[b.name].addTo(map);
26112613
}
2612-
else {
2614+
else if (b.name && !b.icon){
26132615
if (buttons[b.name]) {
26142616
buttons[b.name].removeFrom(map);
26152617
delete buttons[b.name];

0 commit comments

Comments
 (0)