Skip to content

Commit b1d71bd

Browse files
committed
Add ability to load raster pmtiles
to close #312
1 parent 86834b5 commit b1d71bd

File tree

7 files changed

+40
-27
lines changed

7 files changed

+40
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Change Log for Node-RED Worldmap
22

3+
- v5.5.0 - Add ability to load raster pmtiles files. Issue #312
34
- v5.4.0 - Let msg.payload.command.zoomLevels set an array of acceptable zoom levels. Issue #312
45
- v5.3.0 - Let msg.payload.popupOptions object set Leaflet popup options so it can be customised. Issue #311
56
- v5.2.0 - Allow left click send back co-ords. Let Button be replaceable more easily and take value property. Issue #308 and #309

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Feel free to [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%
1313

1414
### Updates
1515

16+
- v5.5.0 - Add ability to load raster pmtiles files. Issue #312
1617
- v5.4.0 - Let msg.payload.command.zoomLevels set an array of acceptable zoom levels. Issue #312
1718
- v5.3.0 - Let msg.payload.popupOptions object set Leaflet popup options so it can be customised. Issue #311
1819
- v5.2.0 - Allow left click send back co-ords. Let Button be replaceable more easily and take value property. Issue #308 and #309
@@ -772,15 +773,19 @@ You can also load them dynamically with a command like
772773

773774
Where `opt` can be as per the options file mentioned above - or omitted completely.
774775

776+
NOTE: for some reason many files converted to pmtiles format fail to load/display. In this case you can easily use the tileserver-gl map server either natively or via docker (see below) to serve the pmtiles format file.
777+
775778
### Using a Docker Map Server
776779

777-
I have found the easiest to use mapserver for a 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
780+
I have found the easiest to use mapserver for a decent generic map to be Tileserver-gl. It uses mbtiles or pmtiles 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
778781
```
779782
docker run --name maptiler -d -v $(pwd):/data -p 1884:8080 maptiler/tileserver-gl -p 8080 --mbtiles yourMapFile.mbtiles
780783
```
781784
and use a url like `"url": "http://localhost:1884/styles/basic-preview/{z}/{x}/{y}.png"`
782785

783-
Other more traditional map servers include containers like https://hub.docker.com/r/camptocamp/mapserver, then assuming you have the mapfile 'my-app.map' in the current working directory, you could mount it as:
786+
This also works for pmtiles format map files.
787+
788+
Other more traditional map servers include containers like https://hub.docker.com/r/camptocamp/mapserver, which then assuming you have the mapfile 'my-app.map' in the current working directory, you could mount it as:
784789
```
785790
docker run -d --name camptocamp -v $(pwd):/etc/mapserver/:ro -p 1881:80 camptocamp/mapserver
786791
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-contrib-web-worldmap",
3-
"version": "5.4.0",
3+
"version": "5.5.0",
44
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
55
"dependencies": {
66
"@turf/bezier-spline": "~7.2.0",

worldmap/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<script src="leaflet/VectorTileLayer.umd.min.js"></script>
7878
<script src="leaflet/esri-leaflet.js"></script>
7979
<script src="leaflet/protomaps-leaflet.min.js"></script>
80+
<script src="leaflet/pmtiles.js"></script>
8081
<script src="leaflet/Semicircle.js"></script>
8182
<script src="leaflet/Leaflet.LimitZoom.js"></script>
8283
<script src="leaflet/leaflet-arc.min.js"></script>

worldmap/leaflet/pmtiles.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

worldmap/leaflet/protomaps-leaflet.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

worldmap/worldmap.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,29 +2727,33 @@ function doCommand(cmd) {
27272727
basemaps[cmd.map.name].removeFrom(map);
27282728
existsalready = true;
27292729
}
2730-
let opt = {};
2731-
if (cmd.map.hasOwnProperty("opt")) { opt = cmd.map.opt || {}; }
2732-
2733-
if (!opt.paintRules && !opt.labelRules && !opt.backgroundColor && !opt.theme) {
2734-
opt.theme = "light"; // light, dark, white, black, grayscale
2735-
};
2736-
2737-
opt.url = cmd.map.pmtiles;
2738-
opt.attribution = opt.attribution || '&copy; Protomaps & OSM';
2739-
opt.maxDataZoom = opt.maxDataZoom || 15;
2740-
opt.maxZoom = opt.maxZoom || 20;
2741-
2742-
console.log("New PMtiles:",cmd.map.name,opt);
2743-
basemaps[cmd.map.name] = protomapsL.leafletLayer(opt);
2744-
if (!existsalready) {
2745-
layercontrol.addBaseLayer(basemaps[cmd.map.name],cmd.map.name);
2746-
}
2747-
if (Object.keys(basemaps).length === 1) {
2748-
baselayername = cmd.map.name;
2749-
basemaps[baselayername].addTo(map);
2750-
}
2751-
if (pmtloaded === "") { pmtloaded = cmd.map.name; }
2752-
} catch(e) { console.log(e); }
2730+
const p = new pmtiles.PMTiles(cmd.map.pmtiles);
2731+
p.getHeader().then((h) => {
2732+
var opt = cmd.map.opt || {};
2733+
if (!opt.maxZoom) { opt.maxZoom = h.maxZoom || 20; }
2734+
opt.maxDataZoom = opt.maxDataZoom || 15;
2735+
opt.attribution = opt.attribution || '&copy; Protomaps & OSM';
2736+
if (!opt.paintRules && !opt.labelRules && !opt.backgroundColor && !opt.theme) {
2737+
opt.theme = "light"; // light, dark, white, black, grayscale
2738+
}
2739+
if (h.tileType === 1) {
2740+
opt.url = cmd.map.pmtiles;
2741+
basemaps[cmd.map.name] = protomapsL.leafletLayer(opt);
2742+
}
2743+
else {
2744+
basemaps[cmd.map.name] = pmtiles.leafletRasterLayer(p, opt);
2745+
}
2746+
if (!existsalready) {
2747+
layercontrol.addBaseLayer(basemaps[cmd.map.name],cmd.map.name);
2748+
}
2749+
if (Object.keys(basemaps).length === 1) {
2750+
baselayername = cmd.map.name;
2751+
basemaps[baselayername].addTo(map);
2752+
}
2753+
if (pmtloaded === "") { pmtloaded = cmd.map.name; }
2754+
});
2755+
}
2756+
catch(e) { console.log(e); }
27532757
}
27542758
// Add or swap new minimap layer
27552759
if (cmd.map && cmd.map.hasOwnProperty("minimap")) {

0 commit comments

Comments
 (0)