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

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,7 @@
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.5.2 - Tidy up when pmtiles removed.
4
+ - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules.
4
5
  - v4.4.0 - Add quad(copter) drone icon.
5
6
  - v4.3.3 - Fix for objects changing layers.
6
7
  - v4.3.2 - Fix geojson popup missing label name.
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.5.2 - Tidy up when pmtiles removed.
16
17
  - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules
17
18
  - v4.4.0 - Add quad(copter) drone icon.
18
19
  - v4.3.3 - Fix for objects changing layers.
@@ -723,6 +724,10 @@ You can use a PMtiles format map archive file from [Protomaps](https://docs.prot
723
724
 
724
725
  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
726
 
727
+ You can also load them dynamically with a command like
728
+
729
+ msg.payload = {"command":{"map":{"name":"MyMap","pmtiles":"/path/to/mymap.pmtiles"}}}
730
+
726
731
  ### Using a Docker Map Server
727
732
 
728
733
  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.0",
3
+ "version": "4.5.2",
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",
package/worldmap.js CHANGED
@@ -13,8 +13,9 @@ 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'));
18
19
 
19
20
  function worldMap(node, n) {
20
21
  var allPoints = {};
@@ -126,10 +127,8 @@ module.exports = function(RED) {
126
127
  if (err) {
127
128
  if (err.code !== "EEXIST") { console.log(err); }
128
129
  }
129
- else {
130
- client.write(JSON.stringify({command: {map: {name:pmtiles[p].split('.')[0], pmtiles:pmtiles[p] }}}));
131
- }
132
130
  })
131
+ client.write(JSON.stringify({command: {map: {name:pmtiles[p].split('.')[0], pmtiles:pmtiles[p] }}}));
133
132
  }
134
133
  var o = Object.values(allPoints);
135
134
  o.map(v => delete v.tout);
@@ -165,6 +164,17 @@ module.exports = function(RED) {
165
164
 
166
165
  node.on('input', function(msg) {
167
166
  if (!msg.hasOwnProperty("payload")) { node.warn("Missing payload"); return; }
167
+
168
+ if (msg.payload.hasOwnProperty("command") && msg.payload.command.hasOwnProperty("map") && msg.payload.command.map.hasOwnProperty("pmtiles")) {
169
+ if (msg.payload.command.map.pmtiles.indexOf("http") !== 0) {
170
+ fs.symlink(msg.payload.command.map.pmtiles, __dirname+'/worldmap/'+msg.payload.command.map.name+'.pmtiles', 'file', (err) => {
171
+ if (err) {
172
+ if (err.code !== "EEXIST") { console.log(err); }
173
+ }
174
+ });
175
+ msg.payload.command.map.pmtiles = msg.payload.command.map.name+'.pmtiles';
176
+ }
177
+ }
168
178
  if (msg.hasOwnProperty("_sessionid")) {
169
179
  if (clients.hasOwnProperty(msg._sessionid)) {
170
180
  clients[msg._sessionid].write(JSON.stringify(msg.payload));