protomaps / PMTiles

Cloud-optimized + compressed single-file tile archives for vector and raster maps
https://protomaps.com/docs/pmtiles/
BSD 3-Clause "New" or "Revised" License
2.02k stars 118 forks source link

feature: js: lazy loading #17

Closed eddy-geek closed 2 years ago

eddy-geek commented 2 years ago

Currently the loading of the root directory is in the constructor.

This is not desirable when the layer is not the default one, eg when switching between several layers with leaflet Layers Controls, the useless queries may be costly on backend side.

I guess we can start with PMTiles().root ===undefined and load it on first access (at the cost of initial load time)?

(There are also leaflet layer control event if needed)

bdon commented 2 years ago

Agreed, it seems wrong that initializing a PMTiles object will make a network request. Do you want to try a PR?