node-red-contrib-web-worldmap 4.5.2 → 4.6.1
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 +1 -0
- package/README.md +16 -1
- package/package.json +1 -1
- package/worldmap/worldmap.js +6 -3
- package/worldmap.js +12 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Feel free to [ 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
package/worldmap/worldmap.js
CHANGED
|
@@ -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-
|
|
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,9 +13,16 @@ 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
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
var pmtiles;
|
|
17
|
+
var pmtilesopts;
|
|
18
|
+
try {
|
|
19
|
+
pmtiles = fs.readdirSync(__dirname + '/worldmap').filter(fn => fn.endsWith('.pmtiles'));
|
|
20
|
+
pmtiles.forEach(file => { fs.unlinkSync(__dirname + '/worldmap/'+file); })
|
|
21
|
+
pmtiles = fs.readdirSync(RED.settings.userDir).filter(fn => fn.endsWith('.pmtiles'));
|
|
22
|
+
pmtilesopts = fs.readFileSync(RED.settings.userDir+'/pmtiles.opts');
|
|
23
|
+
pmtilesopts = JSON.parse(pmtilesopts);
|
|
24
|
+
}
|
|
25
|
+
catch(e) {};
|
|
19
26
|
|
|
20
27
|
function worldMap(node, n) {
|
|
21
28
|
var allPoints = {};
|
|
@@ -128,7 +135,7 @@ module.exports = function(RED) {
|
|
|
128
135
|
if (err.code !== "EEXIST") { console.log(err); }
|
|
129
136
|
}
|
|
130
137
|
})
|
|
131
|
-
client.write(JSON.stringify({command: {map: {name:pmtiles[p].split('.')[0], pmtiles:pmtiles[p] }}}));
|
|
138
|
+
client.write(JSON.stringify({command: {map: {name:pmtiles[p].split('.')[0], pmtiles:pmtiles[p], opt:pmtilesopts }}}));
|
|
132
139
|
}
|
|
133
140
|
var o = Object.values(allPoints);
|
|
134
141
|
o.map(v => delete v.tout);
|
|
@@ -169,7 +176,7 @@ module.exports = function(RED) {
|
|
|
169
176
|
if (msg.payload.command.map.pmtiles.indexOf("http") !== 0) {
|
|
170
177
|
fs.symlink(msg.payload.command.map.pmtiles, __dirname+'/worldmap/'+msg.payload.command.map.name+'.pmtiles', 'file', (err) => {
|
|
171
178
|
if (err) {
|
|
172
|
-
if (err.code !== "EEXIST") {
|
|
179
|
+
if (err.code !== "EEXIST") { node.log("PMTiles "+err.code,msg); }
|
|
173
180
|
}
|
|
174
181
|
});
|
|
175
182
|
msg.payload.command.map.pmtiles = msg.payload.command.map.name+'.pmtiles';
|