Fix layer command for non core base layers

to Close #195
This commit is contained in:
Dave Conway-Jones 2022-04-08 11:53:10 +01:00
parent cc16b81729
commit 0e6c2505b2
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
4 changed files with 30 additions and 25 deletions

View File

@ -1,5 +1,6 @@
### Change Log for Node-RED Worldmap ### Change Log for Node-RED Worldmap
- v2.28.1 - Fix layer command bug for non-core layers. Issue #195
- v2.28.0 - Better Handling of sidc icons in geojson - v2.28.0 - Better Handling of sidc icons in geojson
- v2.27.3 - Try to handle greatcircles crossing antimeridian - v2.27.3 - Try to handle greatcircles crossing antimeridian
- v2.27.1 - Reload existing markers for late joiners - v2.27.1 - Reload existing markers for late joiners

View File

@ -11,6 +11,7 @@ map web page for plotting "things" on.
### Updates ### Updates
- v2.28.1 - Fix layer command bug for non-core layers. Issue #195
- v2.28.0 - Better Handling of sidc icons in geojson - v2.28.0 - Better Handling of sidc icons in geojson
- v2.27.3 - Try to handle greatcircles crossing antimeridian - v2.27.3 - Try to handle greatcircles crossing antimeridian
- v2.27.1 - Reload existing markers for late joiners - v2.27.1 - Reload existing markers for late joiners

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-web-worldmap", "name": "node-red-contrib-web-worldmap",
"version": "2.28.0", "version": "2.28.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": {
"@turf/bezier-spline": "~6.5.0", "@turf/bezier-spline": "~6.5.0",

View File

@ -733,16 +733,21 @@ map.on('contextmenu', function(e) {
} }
}); });
// Layer control based on select box rather than radio buttons.
//var layercontrol = L.control.selectLayers(basemaps, overlays).addTo(map);
layercontrol = L.control.layers(basemaps, overlays);
// Add all the base layer maps if we are online. // Add all the base layer maps if we are online.
var addBaseMaps = function(maplist,first) { var addBaseMaps = function(maplist,first) {
// console.log("MAPS",first,maplist) // console.log("MAPS",first,maplist)
if (navigator.onLine) { var layerlookup = { OSMG:"OSM grey", OSMC:"OSM", OSMH:"OSM Humanitarian", EsriC:"Esri", EsriS:"Esri Satellite",
var layerlookup = { OSMG:"OSM grey", OSMC:"OSM", OSMH:"OSM Humanitarian", EsriC:"Esri", EsriS:"Esri Satellite", EsriR:"Esri Relief", EsriT:"Esri Topography", EsriO:"Esri Ocean", EsriDG:"Esri Dark Grey", NatGeo: "National Geographic",
EsriR:"Esri Relief", EsriT:"Esri Topography", EsriO:"Esri Ocean", EsriDG:"Esri Dark Grey", NatGeo: "National Geographic", UKOS:"UK OS OpenData", OS45:"UK OS 1919-1947", OS00:"UK OS 1900", OpTop:"Open Topo Map",
UKOS:"UK OS OpenData", OS45:"UK OS 1919-1947", OS00:"UK OS 1900", OpTop:"Open Topo Map", HB:"Hike Bike OSM", ST:"Stamen Topography", SW:"Stamen Watercolor", AN:"AutoNavi (Chinese)"
HB:"Hike Bike OSM", ST:"Stamen Topography", SW:"Stamen Watercolor", AN:"AutoNavi (Chinese)" }
}
if (navigator.onLine) {
// Use this for OSM online maps // Use this for OSM online maps
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © OpenStreetMap contributors'; var osmAttrib='Map data © OpenStreetMap contributors';
@ -903,18 +908,19 @@ var addBaseMaps = function(maplist,first) {
attribution: 'Map tiles by <a href="https://stamen.com">Stamen Design</a>, under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="https://openstreetmap.org">OpenStreetMap</a>, under <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>' attribution: 'Map tiles by <a href="https://stamen.com">Stamen Design</a>, under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="https://openstreetmap.org">OpenStreetMap</a>, under <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>'
}); });
} }
}
if (first) { if (first) {
if (layerlookup[first]) { basemaps[layerlookup[first]].addTo(map); } if (layerlookup[first]) { baselayername = layerlookup[first]; }
else { basemaps[first].addTo(map); } else { basenayername = first; }
} }
else { else {
basemaps[Object.keys(basemaps)[0]].addTo(map); basenayername = Object.keys(basemaps)[0];
} }
if (showLayerMenu) { basemaps[baselayername].addTo(map);
map.removeControl(layercontrol); if (showLayerMenu) {
layercontrol = L.control.layers(basemaps, overlays).addTo(map); map.removeControl(layercontrol);
} layercontrol = L.control.layers(basemaps, overlays).addTo(map);
} }
} }
@ -960,7 +966,7 @@ var addOverlays = function(overlist) {
}); });
var changeDrawColour = function(col) { var changeDrawColour = function(col) {
drawingColour = col; drawingColour = col;
console.log("COLOR",col) // console.log("COLOR",col)
drawControl.setDrawingOptions({ drawControl.setDrawingOptions({
polyline: { shapeOptions: { color:drawingColour } }, polyline: { shapeOptions: { color:drawingColour } },
circle: { shapeOptions: { color:drawingColour } }, circle: { shapeOptions: { color:drawingColour } },
@ -1111,7 +1117,7 @@ var addOverlays = function(overlist) {
} }
// Add the countries (world-110m) for offline use // Add the countries (world-110m) for offline use
if (overlist.indexOf("CO")!==-1 || (!navigator.onLine)) { if (overlist.indexOf("CO") !== -1 || !navigator.onLine) {
var customTopoLayer = L.geoJson(null, {clickable:false, style: {color:"blue", weight:2, fillColor:"#cf6", fillOpacity:0.04}}); var customTopoLayer = L.geoJson(null, {clickable:false, style: {color:"blue", weight:2, fillColor:"#cf6", fillOpacity:0.04}});
layers["_countries"] = omnivore.topojson('images/world-50m-flat.json',null,customTopoLayer); layers["_countries"] = omnivore.topojson('images/world-50m-flat.json',null,customTopoLayer);
overlays["countries"] = layers["_countries"]; overlays["countries"] = layers["_countries"];
@ -1196,10 +1202,6 @@ var addOverlays = function(overlist) {
} }
} }
// Layer control based on select box rather than radio buttons.
//var layercontrol = L.control.selectLayers(basemaps, overlays).addTo(map);
layercontrol = L.control.layers(basemaps, overlays);
// Add the layers control widget // Add the layers control widget
if (!inIframe) { layercontrol.addTo(map); } if (!inIframe) { layercontrol.addTo(map); }
else { showLayerMenu = false;} else { showLayerMenu = false;}
@ -2224,7 +2226,7 @@ function doCommand(cmd) {
var existsalready = false; var existsalready = false;
// Add a new base map layer // Add a new base map layer
if (cmd.map && cmd.map.hasOwnProperty("name") && cmd.map.name.length>0 && cmd.map.hasOwnProperty("url") && cmd.map.hasOwnProperty("opt")) { if (cmd.map && cmd.map.hasOwnProperty("name") && cmd.map.name.length>0 && cmd.map.hasOwnProperty("url") && cmd.map.hasOwnProperty("opt")) {
console.log("BASE",cmd.map); // console.log("BASE",cmd.map);
if (basemaps.hasOwnProperty(cmd.map.name)) { existsalready = true; } if (basemaps.hasOwnProperty(cmd.map.name)) { existsalready = true; }
if (cmd.map.hasOwnProperty("wms")) { // special case for wms if (cmd.map.hasOwnProperty("wms")) { // special case for wms
console.log("New WMS:",cmd.map.name); console.log("New WMS:",cmd.map.name);
@ -2523,6 +2525,7 @@ function doCommand(cmd) {
baselayername = cmd.layer; baselayername = cmd.layer;
basemaps[baselayername].addTo(map); basemaps[baselayername].addTo(map);
} }
// If set to none then remove the baselayer...
if (cmd.layer && (cmd.layer === "none")) { if (cmd.layer && (cmd.layer === "none")) {
map.removeLayer(basemaps[baselayername]); map.removeLayer(basemaps[baselayername]);
baselayername = cmd.layer; baselayername = cmd.layer;