Skip to content

Commit ca5e81c

Browse files
committed
add popupOptions to allow popup customisation
to Close #311
1 parent 6ff6ce6 commit ca5e81c

File tree

5 files changed

+44
-36
lines changed

5 files changed

+44
-36
lines changed

CHANGELOG.md

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

3+
- v5.3.0 - Let msg.payload.popupOptions object set Leaflet popup options so it can be customised. Issue #311
34
- v5.2.0 - Allow left click send back co-ords. Let Button be replaceable more easily and take value property. Issue #308 and #309
45
- v5.1.6 - Let Cot __milsym set the SIDC if present.
56
- v5.1.5 - Fix links to SIDC unitgenerator so it is now local.

README.md

Lines changed: 3 additions & 2 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.3.0 - Let msg.payload.popupOptions object set Leaflet popup options so it can be customised. Issue #311
1617
- v5.2.0 - Allow left click send back co-ords. Let Button be replaceable more easily and take value property. Issue #308 and #309
1718
- v5.1.6 - Let Cot __milsym set the SIDC if present.
1819
- v5.1.5 - Fix links to SIDC unitgenerator so it is now local.
@@ -28,8 +29,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
2829
- v5.0.3 - Add great context menu example flow. PR #290. Bump express lib. PR #291.
2930
- v5.0.2 - Fix sidcEdgeIcon docs PR #289.
3031
- v5.0.1 - Fix isArray error PR #288.
31-
- v5.0.0 - v5.0.0 - Feedback cleanup PR #281, edgeicons option PR #287, bump libs for vuln fixes.
32-
32+
- v5.0.0 - Feedback cleanup PR #281, edgeicons option PR #287, bump libs for vuln fixes.
3333

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

@@ -77,6 +77,7 @@ Optional properties for **msg.payload** include
7777
- **clickable** : Default true. Setting to false disables showing any popup.
7878
- **popped** : set to true to automatically open the popup info box, set to false to close it.
7979
- **popup** : html to fill the popup if you don't want the automatic default of the properties list. Using this overrides photourl, videourl and weblink options.
80+
- **popupOptions** : optional object to help style the popup - See Leaflet popup docs for options - eg to add a custom class - `{className:"mySpecialPopup",width:600}`
8081
- **label** : displays the contents as a permanent label next to the marker, or
8182
- **tooltip** : displays the contents when you hover over the marker. (Mutually exclusive with label. Label has priority)
8283
- **tooltipOptions** : custom tooltip/label options (offset, direction, permanent, sticky, interactive, opacity, className) )

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "node-red-contrib-web-worldmap",
3-
"version": "5.2.0",
3+
"version": "5.3.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",
77
"cgi": "0.3.1",
8-
"compression": "^1.8.0",
8+
"compression": "^1.8.1",
99
"express": "^4.21.2",
1010
"sockjs": "~0.3.24"
1111
},

worldmap/worldmap.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,31 +2358,37 @@ function setMarker(data) {
23582358
if (data.hasOwnProperty("radius")) { delete data.radius; }
23592359
if (data.hasOwnProperty("greatcircle")) { delete data.greatcircle; }
23602360

2361-
// then any remaining properties to the info box
2362-
var longline = 0;
2363-
if (data.popup) { words = data.popup; }
2364-
else {
2365-
words += '<table>';
2366-
for (var i in data) {
2367-
if ((i != "name") && (i != "length") && (i != "clickable")) {
2368-
if (typeof data[i] === "object") {
2369-
words += '<tr><td valign="top">'+ i +'</td><td>' + JSON.stringify(data[i]) + '</td></tr>';
2370-
}
2371-
else {
2372-
// words += i +" : "+data[i]+"<br/>";
2373-
if (data[i].length > longline) { longline = data[i].length; }
2374-
words += '<tr><td valign="top">'+ i +'</td><td>' + data[i] + '</td></tr>';
2361+
if (!data.hasOwnProperty("clickable") && data.clickable != false) {
2362+
var wopt = { autoClose:false, closeButton:true, closeOnClick:false, minWidth:200 };
2363+
if (words.indexOf('<video ') >=0 || words.indexOf('<img ') >=0 ) { wopt.maxWidth="640"; } // make popup wider if it has an image or video
2364+
if (data?.popupOptions) { // allow user to override popup options eg to add className
2365+
wopt = data.popupOptions;
2366+
delete data.popupOptions;
2367+
}
2368+
2369+
// then any remaining properties to the info box
2370+
var longline = 0;
2371+
if (data.popup) { words = data.popup; }
2372+
else {
2373+
words += '<table>';
2374+
for (var i in data) {
2375+
if ((i != "name") && (i != "length") && (i != "clickable")) {
2376+
if (typeof data[i] === "object") {
2377+
words += '<tr><td valign="top">'+ i +'</td><td>' + JSON.stringify(data[i]) + '</td></tr>';
2378+
}
2379+
else {
2380+
// words += i +" : "+data[i]+"<br/>";
2381+
if (data[i].length > longline) { longline = data[i].length; }
2382+
words += '<tr><td valign="top">'+ i +'</td><td>' + data[i] + '</td></tr>';
2383+
}
23752384
}
23762385
}
2386+
words += '<tr><td>lat, lon</td><td>'+ marker.getLatLng().toString().replace('LatLng(','').replace(')','') + '</td></tr>';
2387+
words += '</table>';
23772388
}
2378-
words += '<tr><td>lat, lon</td><td>'+ marker.getLatLng().toString().replace('LatLng(','').replace(')','') + '</td></tr>';
2379-
words += '</table>';
2380-
}
2381-
words = "<b>"+data["name"]+"</b><br/>" + words.replace(/\${name}/g,data["name"]); //"<button style=\"border-radius:4px; float:right; background-color:lightgrey;\" onclick='popped=false;popmark.closePopup();'>X</button><br/>" + words;
2382-
var wopt = {autoClose:false, closeButton:true, closeOnClick:false, minWidth:200};
2383-
if (words.indexOf('<video ') >=0 || words.indexOf('<img ') >=0 ) { wopt.maxWidth="640"; } // make popup wider if it has an image or video
2384-
if (longline > 100) { wopt.minWidth="640"; } // make popup wider if it has a long line
2385-
if (!data.hasOwnProperty("clickable") && data.clickable != false) {
2389+
words = "<b>"+data["name"]+"</b><br/>" + words.replace(/\${name}/g,data["name"]); //"<button style=\"border-radius:4px; float:right; background-color:lightgrey;\" onclick='popped=false;popmark.closePopup();'>X</button><br/>" + words;
2390+
2391+
if (longline > 100) { wopt.minWidth="640"; } // make popup wider if it has a long line
23862392
marker.bindPopup(words, wopt);
23872393
marker._popup.dname = data["name"];
23882394
}

0 commit comments

Comments
 (0)