node-red-contrib-web-worldmap 4.5.2 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ### Change Log for Node-RED Worldmap
2
2
 
3
+ - v4.6.0 - let default pmtiles be light/dark or monocolored.
3
4
  - v4.5.2 - Tidy up when pmtiles removed.
4
5
  - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules.
5
6
  - v4.4.0 - Add quad(copter) drone icon.
package/README.md CHANGED
@@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
13
13
 
14
14
  ### Updates
15
15
 
16
+ - v4.6.0 - let default pmtiles be light/dark or monocolored.
16
17
  - v4.5.2 - Tidy up when pmtiles removed.
17
18
  - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules
18
19
  - v4.4.0 - Add quad(copter) drone icon.
@@ -724,9 +725,23 @@ You can use a PMtiles format map archive file from [Protomaps](https://docs.prot
724
725
 
725
726
  Copy your .pmtiles file(s) into your `~/.node-red` user directory. On re-starting Node-RED the node will detect the file(s) and add them to the base map layer menu, using the file name as the layer name.
726
727
 
728
+ You can set some default options for the pmtiles by creating a file called **pmtiles.opts** in your user directory. For example to create a nightvision style
729
+
730
+ {
731
+ "attribution": "Protomaps and OSM",
732
+ "maxDataZoom": 15,
733
+ "maxZoom": 20,
734
+ "shade": "red",
735
+ "dark": true
736
+ }
737
+
738
+ The `maxDataZoom` should match the maximum zoom level in you pmtiles file(s) - whereas the `maxZoom` is the leaflet maximum zoom level you want to support. `shade` can be any valid html colour or #rrggbb string, and `dark` is a boolean (default false).
739
+
727
740
  You can also load them dynamically with a command like
728
741
 
729
- msg.payload = {"command":{"map":{"name":"MyMap","pmtiles":"/path/to/mymap.pmtiles"}}}
742
+ msg.payload = {"command":{"map":{"name":"MyMap", "pmtiles":"/path/to/mymap.pmtiles", "opt":"myOptionsObject"}}}
743
+
744
+ Where `opt` can be as per the options file mentioned above - or omitted completely.
730
745
 
731
746
  ### Using a Docker Map Server
732
747
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-web-worldmap",
3
- "version": "4.5.2",
3
+ "version": "4.6.0",
4
4
  "description": "A Node-RED node to provide a web page of a world map for plotting things on.",
5
5
  "dependencies": {
6
6
  "@turf/bezier-spline": "~6.5.0",
@@ -1296,7 +1296,7 @@ var addOverlays = function(overlist) {
1296
1296
  changeDrawColour("#4040F0"); // Set default drawing color to blue on start
1297
1297
  }
1298
1298
 
1299
- // Add the countries (world-110m) for offline use
1299
+ // Add the countries (world-50m geojson) outline for offline use
1300
1300
  if (overlist.indexOf("CO") !== -1 || !navigator.onLine) {
1301
1301
  var customTopoLayer = L.geoJson(null, {clickable:false, style: {color:"blue", weight:2, fillColor:"#cf6", fillOpacity:0.04}});
1302
1302
  layers["_countries"] = omnivore.topojson('images/world-50m-flat.json',null,customTopoLayer);
@@ -2605,11 +2605,14 @@ function doCommand(cmd) {
2605
2605
  existsalready = true;
2606
2606
  }
2607
2607
  var opt = {};
2608
- if (cmd.map.hasOwnProperty("opt")) { opt = cmd.map.opt; }
2608
+ if (cmd.map.hasOwnProperty("opt")) { opt = cmd.map.opt || {}; }
2609
2609
  opt.url = cmd.map.pmtiles;
2610
- opt.attribution = opt.attribution || '© Protomaps';
2610
+ opt.attribution = opt.attribution || '© Protomaps & OSM';
2611
2611
  opt.maxDataZoom = opt.maxDataZoom || 15;
2612
2612
  opt.maxZoom = opt.maxZoom || 20;
2613
+ // opt.shade = "grey";
2614
+ // opt.dark = false;
2615
+ // opt.xray = true;
2613
2616
  console.log("New PMtiles:",cmd.map.name,opt);
2614
2617
  basemaps[cmd.map.name] = protomapsL.leafletLayer(opt);
2615
2618
  if (!existsalready) {
package/worldmap.js CHANGED
@@ -16,6 +16,12 @@ module.exports = function(RED) {
16
16
  var pmtiles = fs.readdirSync(__dirname + '/worldmap').filter(fn => fn.endsWith('.pmtiles'));
17
17
  pmtiles.forEach(file => { fs.unlinkSync(__dirname + '/worldmap/'+file); })
18
18
  pmtiles = fs.readdirSync(RED.settings.userDir).filter(fn => fn.endsWith('.pmtiles'));
19
+ var pmtilesopts;
20
+ try {
21
+ pmtilesopts = fs.readFileSync(RED.settings.userDir+'/pmtiles.opts');
22
+ pmtilesopts = JSON.parse(pmtilesopts);
23
+ }
24
+ catch(e) {};
19
25
 
20
26
  function worldMap(node, n) {
21
27
  var allPoints = {};
@@ -128,7 +134,7 @@ module.exports = function(RED) {
128
134
  if (err.code !== "EEXIST") { console.log(err); }
129
135
  }
130
136
  })
131
- client.write(JSON.stringify({command: {map: {name:pmtiles[p].split('.')[0], pmtiles:pmtiles[p] }}}));
137
+ client.write(JSON.stringify({command: {map: {name:pmtiles[p].split('.')[0], pmtiles:pmtiles[p], opt:pmtilesopts }}}));
132
138
  }
133
139
  var o = Object.values(allPoints);
134
140
  o.map(v => delete v.tout);
@@ -169,7 +175,7 @@ module.exports = function(RED) {
169
175
  if (msg.payload.command.map.pmtiles.indexOf("http") !== 0) {
170
176
  fs.symlink(msg.payload.command.map.pmtiles, __dirname+'/worldmap/'+msg.payload.command.map.name+'.pmtiles', 'file', (err) => {
171
177
  if (err) {
172
- if (err.code !== "EEXIST") { console.log(err); }
178
+ if (err.code !== "EEXIST") { node.log("PMTiles "+err.code,msg); }
173
179
  }
174
180
  });
175
181
  msg.payload.command.map.pmtiles = msg.payload.command.map.name+'.pmtiles';