let button settings be an array

This commit is contained in:
Dave Conway-Jones 2022-06-08 19:18:11 +01:00
parent 0e6c2505b2
commit 5787896cd5
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
4 changed files with 20 additions and 13 deletions

View File

@ -1,5 +1,6 @@
### Change Log for Node-RED Worldmap
- v2.28.2 - Let button declaration be an array
- v2.28.1 - Fix layer command bug for non-core layers. Issue #195
- v2.28.0 - Better Handling of sidc icons in geojson
- v2.27.3 - Try to handle greatcircles crossing antimeridian

View File

@ -11,6 +11,7 @@ map web page for plotting "things" on.
### Updates
- v2.28.2 - Let button declaration be an array
- v2.28.1 - Fix layer command bug for non-core layers. Issue #195
- v2.28.0 - Better Handling of sidc icons in geojson
- v2.27.3 - Try to handle greatcircles crossing antimeridian
@ -420,7 +421,7 @@ Optional properties include
- **hiderightclick** - disables the right click that allows adding or deleting points on the map - `{"command":{"hiderightclick":true}}`
- **coords** - turns on and off a display of the current mouse co-ordinates. Values can be "deg", "dms", or "none" (default). - `{"command":{"coords":"deg"}}`
- **button** - if supplied with a `name` and `icon` property - adds a button to provide user input - sends
a msg `{"action":"button", "name":"the_button_name"}` to the worldmap in node. If supplied with a `name` property only, it will remove the button. Optional `position` property can be 'bottomright', 'bottomleft', 'topleft' or 'topright' (default).
a msg `{"action":"button", "name":"the_button_name"}` to the worldmap in node. If supplied with a `name` property only, it will remove the button. Optional `position` property can be 'bottomright', 'bottomleft', 'topleft' or 'topright' (default). button can also be an array of button objects.
- **contextmenu** - html string to define the right click menu when not on a marker. Defaults to the simple add marker input. Empty string `""` disables this right click.
- **toptitle** - Words to replace title in title bar (if not in iframe)
- **toplogo** - URL to logo image for top tile bar (if not in iframe) - ideally 60px by 24px.
@ -445,6 +446,8 @@ to remove
msg.payload.command = { "button": { "name":"My Fancy Button" } };
Multiple buttons can declared by using an array of button objects.
#### To add a custom popup or contextmenu
You can customise a marker's popup, or context menu (right click), by setting the

View File

@ -1,6 +1,6 @@
{
"name": "node-red-contrib-web-worldmap",
"version": "2.28.1",
"version": "2.28.2",
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
"dependencies": {
"@turf/bezier-spline": "~6.5.0",

View File

@ -2166,19 +2166,22 @@ function doCommand(cmd) {
}
}
if (cmd.hasOwnProperty("button")) {
if (cmd.button.icon) {
if (!buttons[cmd.button.name]) {
buttons[cmd.button.name] = L.easyButton( cmd.button.icon, function() {
ws.send(JSON.stringify({action:"button",name:cmd.button.name}));
}, cmd.button.name, { position:cmd.button.position||'topright' }).addTo(map);
if (!isArray(cmd.button)) { cmd.button = [cmd.button]; }
cmd.button.forEach(function(b) {
if (b.icon) {
if (!buttons[b.name]) {
buttons[b.name] = L.easyButton( b.icon, function() {
ws.send(JSON.stringify({action:"button", name:b.name}));
}, b.name, { position:b.position||'topright' }).addTo(map);
}
}
else {
if (buttons[cmd.button.name]) {
buttons[cmd.button.name].removeFrom(map);
delete buttons[cmd.button.name];
if (buttons[b.name]) {
buttons[b.name].removeFrom(map);
delete buttons[b.name];
}
}
})
}
if (cmd.hasOwnProperty("contextmenu")) {
if (typeof cmd.contextmenu === "string") {