node-red-contrib-web-worldmap 4.5.1 → 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,6 +1,8 @@
1
1
  ### Change Log for Node-RED Worldmap
2
2
 
3
- - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules
3
+ - v4.6.0 - let default pmtiles be light/dark or monocolored.
4
+ - v4.5.2 - Tidy up when pmtiles removed.
5
+ - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules.
4
6
  - v4.4.0 - Add quad(copter) drone icon.
5
7
  - v4.3.3 - Fix for objects changing layers.
6
8
  - v4.3.2 - Fix geojson popup missing label name.
package/README.md CHANGED
@@ -13,6 +13,8 @@ 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.
17
+ - v4.5.2 - Tidy up when pmtiles removed.
16
18
  - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules
17
19
  - v4.4.0 - Add quad(copter) drone icon.
18
20
  - v4.3.3 - Fix for objects changing layers.
@@ -723,6 +725,24 @@ You can use a PMtiles format map archive file from [Protomaps](https://docs.prot
723
725
 
724
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.
725
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
+
740
+ You can also load them dynamically with a command like
741
+
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.
745
+
726
746
  ### Using a Docker Map Server
727
747
 
728
748
  I have found the easiest to use mapserver for decent generic map to be Tileserver-gl. It uses mbtiles format maps - for example from [MapTiler Data](https://data.maptiler.com/downloads/planet/). You can download your mbtiles file into a directory and then from that directory run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-web-worldmap",
3
- "version": "4.5.1",
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
@@ -13,8 +13,15 @@ module.exports = function(RED) {
13
13
  if (fs.existsSync((__dirname + '/mapserv'))) {
14
14
  RED.httpNode.use("/cgi-bin/mapserv", require('cgi')(__dirname + '/mapserv'));
15
15
  }
16
- //var pmtiles = fs.readdirSync(__dirname + '/worldmap').filter(fn => fn.endsWith('.pmtiles'));
17
- var pmtiles = fs.readdirSync(RED.settings.userDir).filter(fn => fn.endsWith('.pmtiles'));
16
+ var pmtiles = fs.readdirSync(__dirname + '/worldmap').filter(fn => fn.endsWith('.pmtiles'));
17
+ pmtiles.forEach(file => { fs.unlinkSync(__dirname + '/worldmap/'+file); })
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) {};
18
25
 
19
26
  function worldMap(node, n) {
20
27
  var allPoints = {};
@@ -127,7 +134,7 @@ module.exports = function(RED) {
127
134
  if (err.code !== "EEXIST") { console.log(err); }
128
135
  }
129
136
  })
130
- 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 }}}));
131
138
  }
132
139
  var o = Object.values(allPoints);
133
140
  o.map(v => delete v.tout);
@@ -163,6 +170,17 @@ module.exports = function(RED) {
163
170
 
164
171
  node.on('input', function(msg) {
165
172
  if (!msg.hasOwnProperty("payload")) { node.warn("Missing payload"); return; }
173
+
174
+ if (msg.payload.hasOwnProperty("command") && msg.payload.command.hasOwnProperty("map") && msg.payload.command.map.hasOwnProperty("pmtiles")) {
175
+ if (msg.payload.command.map.pmtiles.indexOf("http") !== 0) {
176
+ fs.symlink(msg.payload.command.map.pmtiles, __dirname+'/worldmap/'+msg.payload.command.map.name+'.pmtiles', 'file', (err) => {
177
+ if (err) {
178
+ if (err.code !== "EEXIST") { node.log("PMTiles "+err.code,msg); }
179
+ }
180
+ });
181
+ msg.payload.command.map.pmtiles = msg.payload.command.map.name+'.pmtiles';
182
+ }
183
+ }
166
184
  if (msg.hasOwnProperty("_sessionid")) {
167
185
  if (clients.hasOwnProperty(msg._sessionid)) {
168
186
  clients[msg._sessionid].write(JSON.stringify(msg.payload));