opoto / wtracks

Online track editor for outdoor activities
https://opoto.github.io/wtracks
Apache License 2.0
84 stars 25 forks source link

PMTiles format support #21

Closed eddy-geek closed 2 years ago

eddy-geek commented 2 years ago

PMTiles is a single-file archive format for tiled data. A PMTiles archive can be hosted on a commodity storage platform such as S3, and enables low-cost, zero-maintenance map applications that are "serverless" - free of a custom tile backend or third party provider.

As such, I believe it fits well with WTracks serverless frontend :-) I may also work on COGeo support in the future, but PMTiles is much lighter.

One issue with this simple integration is that a single HEAD request is made at each page load, because of wtracks.js#L2042 calling into pmtiles.js#L48.

A current limitation is that PMTiles (or WMTS) can't be added as overlays. Do you see an issue with separating type: "overlay" into it own overlay: true field in the future?

opoto commented 2 years ago

Looks interesting! Thanks for this contribution. The map editor (map.html/js) should be updated to support this new map type. Could you look at it? I agree that "overlay" could be a map attribute instead of a map type.

opoto commented 2 years ago

Following 1e0e89e, overlay is now a map attribue

eddy-geek commented 2 years ago

One issue with this simple integration is that a single HEAD request is made at each page load, because of wtracks.js#L2042 calling into pmtiles.js#L48.

Apparently this is not done if the map is not displayed, so I hid the maps by default.

The map editor (map.html/js) should be updated to support this new map type. Could you look at it?

Done. My current hosting for the maps is quite slow (not supporting http/2), but that'll have to do. Ready for review.

opoto commented 2 years ago

Thanks! This is a great new feature. 2 questions:

opoto commented 2 years ago

One issue with this simple integration is that a single HEAD request is made at each page load, because of wtracks.js#L2042 calling into pmtiles.js#L48.

Apparently this is not done if the map is not displayed, so I hid the maps by default.

Correct, when map is "hidden" then the tile provider is not created.

eddy-geek commented 2 years ago

Are you owning the s3 buckets hosting the sample files? They will not be deleted soon? We should only include these maps in the defaults if their availability is stable enough.

Yes I am owning the hosting, and plan on maintaining it (which may include moving to a faster provider if I can keep costs in check. in that case I would PR before :)) FYI I also got the author's permission for the Bugianen map.

I noticed that pmtiles created with https://protomaps.com/docs/getting-started are not compatible with this PR (they use pbf format instead of jpg). Any chance to support this format too?

Good point. I am indeed not using Vector tiles, but is is supported by the lib, through integration with maplibre-gl, done in pmtiles.js addProtocol.

A sample is here:

        <script src="https://unpkg.com/maplibre-gl@1.14.1-rc.2/dist/maplibre-gl.js" crossorigin="anonymous"></script>
        <script>
            pmtiles.addProtocol(maplibregl)
            var map = new maplibregl.Map({ ... })

Integration with leaflet seems available, so we'd need to tie all this together. I'll check with upstream if they can help with an example for the maplibre-gl-leaflet + pmtiles part.

By the way, what is your stance on when to load such dependencies from the external world eg unpkg vs copying in .js/? You seem to do a bit of both currently.