Fixup pmtiles loading from other directories

master
Dave Conway-Jones 10 months ago
parent e2990d2130
commit 30f90c0039
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643

@ -1,6 +1,7 @@
### Change Log for Node-RED Worldmap ### Change Log for Node-RED Worldmap
- v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules - v4.5.2 - Tidy up when pmtiles removed.
- v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules.
- v4.4.0 - Add quad(copter) drone icon. - v4.4.0 - Add quad(copter) drone icon.
- v4.3.3 - Fix for objects changing layers. - v4.3.3 - Fix for objects changing layers.
- v4.3.2 - Fix geojson popup missing label name. - v4.3.2 - Fix geojson popup missing label name.

@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
### Updates ### Updates
- v4.5.2 - Tidy up when pmtiles removed.
- v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules - v4.5.0 - Fix pmtiles to look for maps in userdir rather than modules
- v4.4.0 - Add quad(copter) drone icon. - v4.4.0 - Add quad(copter) drone icon.
- v4.3.3 - Fix for objects changing layers. - 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
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. 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.
You can also load them dynamically with a command like
msg.payload = {"command":{"map":{"name":"MyMap","pmtiles":"/path/to/mymap.pmtiles"}}}
### Using a Docker Map Server ### Using a Docker Map Server
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 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

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

@ -13,8 +13,9 @@ module.exports = function(RED) {
if (fs.existsSync((__dirname + '/mapserv'))) { if (fs.existsSync((__dirname + '/mapserv'))) {
RED.httpNode.use("/cgi-bin/mapserv", require('cgi')(__dirname + '/mapserv')); RED.httpNode.use("/cgi-bin/mapserv", require('cgi')(__dirname + '/mapserv'));
} }
//var pmtiles = fs.readdirSync(__dirname + '/worldmap').filter(fn => fn.endsWith('.pmtiles')); var pmtiles = fs.readdirSync(__dirname + '/worldmap').filter(fn => fn.endsWith('.pmtiles'));
var pmtiles = fs.readdirSync(RED.settings.userDir).filter(fn => fn.endsWith('.pmtiles')); pmtiles.forEach(file => { fs.unlinkSync(__dirname + '/worldmap/'+file); })
pmtiles = fs.readdirSync(RED.settings.userDir).filter(fn => fn.endsWith('.pmtiles'));
function worldMap(node, n) { function worldMap(node, n) {
var allPoints = {}; var allPoints = {};
@ -163,6 +164,17 @@ module.exports = function(RED) {
node.on('input', function(msg) { node.on('input', function(msg) {
if (!msg.hasOwnProperty("payload")) { node.warn("Missing payload"); return; } if (!msg.hasOwnProperty("payload")) { node.warn("Missing payload"); return; }
if (msg.payload.hasOwnProperty("command") && msg.payload.command.hasOwnProperty("map") && msg.payload.command.map.hasOwnProperty("pmtiles")) {
if (msg.payload.command.map.pmtiles.indexOf("http") !== 0) {
fs.symlink(msg.payload.command.map.pmtiles, __dirname+'/worldmap/'+msg.payload.command.map.name+'.pmtiles', 'file', (err) => {
if (err) {
if (err.code !== "EEXIST") { console.log(err); }
}
});
msg.payload.command.map.pmtiles = msg.payload.command.map.name+'.pmtiles';
}
}
if (msg.hasOwnProperty("_sessionid")) { if (msg.hasOwnProperty("_sessionid")) {
if (clients.hasOwnProperty(msg._sessionid)) { if (clients.hasOwnProperty(msg._sessionid)) {
clients[msg._sessionid].write(JSON.stringify(msg.payload)); clients[msg._sessionid].write(JSON.stringify(msg.payload));

Loading…
Cancel
Save