protomaps / PMTiles

Cloud-optimized + compressed single-file tile archives for vector and raster maps

Home Page:https://protomaps.com/docs/pmtiles/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to use PMtiles without Node or CDN?

nuclearsecrecy opened this issue · comments

My site is built in native JS and not Node, so porting it into a Node environment would be a huge undertaking.

Currently I have it deployed to a Cloudflare CDN but I am a little concerned that the number of Workers needed is going to potentially cost money. (Currently it is over 100 per user, and I get about 15-20K users per day, so that adds up.)

Is there an easy drop-in way to use pmtiles in my existing code without using Node or a CDN? I am using Maplibre to render the map.

OK, I figured it out — this page gives an example of how to do this. I have other issues getting it to work, but that will be for a separate post!

Yes, you use maplibre addProtocol which is just an es6 module for the browser. https://docs.protomaps.com/pmtiles/maplibre

the number of Workers needed is going to potentially cost money

Yes, workers always cost money, but the unit prices are low - a site that serves 20k users per day I'd guess would cost between $10-50 a month on a cloudflare bill

Thank you, yes, this was the conclusion I came to. I was able to get the ES6 module working, but it seemed much slower, and I had issues getting Cloudflare to cache the query results (if I turned on caching for .pmtiles files, it did not work — the tiles failed to download correctly).

This is by-the-by, but I think the documentation re: Cloudflare pricing on the PMTiles site has an important error in it. It says:

Cloudflare Workers is $5 USD per month with 10 million requests a day, plus $0.50 per additional million.

The main issue is that I think it is 10 million free per month, not per day (a big difference — if only it was per day, it would be practically free even for a very large site!). (There are additional complexities depending on the pricing scheme and so on as well, so I might suggest adding, "plus a potential charge for CPU usage, depending on your pricing plan" to the sentence).

Separately, my calculations so far suggest that the new Standard model (which becomes mandatory next year) is cheaper than the Bundled model that the docs suggest. The Standard model charges less for requests, but adds on a charge for CPU usage, but the CPU usage by the PMTiles Worker is so low that it still works out to be cheaper. E.g., my projection for this month is that I might have about 83 million total requests and around 66 million ms of CPU time, which works out to be $27.65 (includes the $5 Worker subscription fee) on the Standard model, whereas on the Bundled model it is $41.55. Even with more pessimistic assumptions about how much the CPU time might add up, within the range of what kinds of times have been used so far (admittedly only 48 hours of data) it is still always cheaper than the Bundled model (and all of these costs are several multiplies cheaper than a hosted tile sharing service, even one provided at a great discount). I am very impressed.

if I turned on caching for .pmtiles files, it did not work — the tiles failed to download correctly

Correct, the "free" Cloudflare CDN does not cache Range (206) responses by design.

Cloudflare pricing on the PMTiles site has an important error in it.

Yes, let me fix that. The docs are out of date since all the pricing should move to the "Standard" instead of the Bundled pricing model, which should indeed be cheaper.

Those costs for the traffic look in line with my expectations.