Better implimentation of legend (thanks @zafrirron )

This commit is contained in:
Dave Conway-Jones 2020-01-03 10:38:44 +00:00
parent 9d904f5b10
commit 3350094154
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
4 changed files with 18 additions and 9 deletions

View File

@ -1,5 +1,6 @@
### Change Log for Node-RED Worldmap ### Change Log for Node-RED Worldmap
- v2.2.1 - Better implementation of legend create/show/hide
- v2.2.0 - Add rangering arcs function - v2.2.0 - Add rangering arcs function
- v2.1.6 - Add legend command to allow inserting an html legend - v2.1.6 - Add legend command to allow inserting an html legend
- v2.1.5 - Fix squawk icon color handling - v2.1.5 - Fix squawk icon color handling

View File

@ -10,6 +10,7 @@ map web page for plotting "things" on.
### Updates ### Updates
- v2.2.1 - Better implementation of legend create/show/hide
- v2.2.0 - Add rangerings arcs function - v2.2.0 - Add rangerings arcs function
- v2.1.6 - Add legend command to allow inserting an html legend - v2.1.6 - Add legend command to allow inserting an html legend
- v2.1.5 - Fix squawk icon color handling - v2.1.5 - Fix squawk icon color handling

View File

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

@ -1662,15 +1662,22 @@ function doCommand(cmd) {
} }
} }
if (cmd.hasOwnProperty("legend")) { if (cmd.hasOwnProperty("legend")) {
try { map.removeControl(legend); }
catch(e) {}
if (typeof cmd.legend === "string" && cmd.legend.length > 0) { if (typeof cmd.legend === "string" && cmd.legend.length > 0) {
legend.onAdd = function() { if (!legend.getContainer()) { //if legend not exist create it
var div = L.DomUtil.create("div", "legend"); legend.onAdd = function() {
div.innerHTML = cmd.legend; var div = L.DomUtil.create("div", "legend");
return div; div.innerHTML = cmd.legend;
return div;
};
legend.addTo(map);
}; };
legend.addTo(map); legend.getContainer().style.visibility = 'visible'; // if already exist use visibility to show/hide
legend.getContainer().innerHTML = cmd.legend; // set content of legend
}
else {
if (legend.getContainer()) {
legend.getContainer().style.visibility = 'hidden'; //if empty string and legend already created hide it
}
} }
} }