Fixup pmtiles loading from other directories

This commit is contained in:
Dave Conway-Jones 2023-11-29 13:53:10 +00:00
parent e2990d2130
commit 30f90c0039
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643
4 changed files with 22 additions and 4 deletions

View File

@ -1,6 +1,7 @@
### 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.3.3 - Fix for objects changing layers.
- v4.3.2 - Fix geojson popup missing label name.

View File

@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
### Updates
- 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.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.
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
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

View File

@ -1,6 +1,6 @@
{
"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.",
"dependencies": {
"@turf/bezier-spline": "~6.5.0",

View File

@ -13,8 +13,9 @@ module.exports = function(RED) {
if (fs.existsSync((__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(RED.settings.userDir).filter(fn => fn.endsWith('.pmtiles'));
var pmtiles = fs.readdirSync(__dirname + '/worldmap').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) {
var allPoints = {};
@ -163,6 +164,17 @@ module.exports = function(RED) {
node.on('input', function(msg) {
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 (clients.hasOwnProperty(msg._sessionid)) {
clients[msg._sessionid].write(JSON.stringify(msg.payload));