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.07k stars 121 forks source link

add react-map-gl documentation #163

Closed tordans closed 1 year ago

tordans commented 1 year ago

It would be great to have a dedicated example for how to add PMTiles to ReactMapGL.

I added some learnings at https://github.com/visgl/react-map-gl/discussions/2165 but there is some room for improvement.

In general, there are two things that make this example different from a regular Maplibre GL JS implementation: (a) until https://github.com/visgl/react-map-gl/issues/2161 is resolved, the main Types for ReactMapGL are Mapbox, which does not support addProtocol. (b) The component structure/pattern gives it a great native React feel but makes it a bit harder to find the right place to add the addProtocol so that React rendering cycles know about PMTiles at the right time.

bdon commented 1 year ago

There's some overlap with #155 here. I think a bit of extra docs related to react is worth it because of the unclear lifecycle and where addProtocol needs to happen, specific to MapLibre.

bdon commented 1 year ago

@tordans I added a "Usage in React" section here: https://protomaps.com/docs/frontends/maplibre#usage-in-react which describes how to use addProtocol on the maplibre object in a root-level hook. Because you pass that same reference to maplibre into react-map-gl I think we don't need any changes to react-map-gl at all.

Full working example sandbox with react-map-gl: https://codesandbox.io/s/black-dream-oycvf2?file=/src/App.js

bdon commented 1 year ago

I'm going to close this for now - please reopen if you encounter other issues!

tordans commented 5 months ago

Full working example sandbox with react-map-gl: https://codesandbox.io/s/black-dream-oycvf2?file=/src/App.js

In case someone comes here … this is what the sandbox looks like when using the <Source>/<Layer> components by react map gl: https://codesandbox.io/p/sandbox/blissful-dewdney-cxdcx7?file=%2Fsrc%2FApp.js%3A19%2C11

bdon commented 5 months ago

@tordans can you make that public?

tordans commented 5 months ago

@tordans can you make that public?

Sorry. It should be public now. https://codesandbox.io/p/sandbox/react-map-gl-example-using-pmtiles-cxdcx7?file=%2Fsrc%2FApp.js%3A4%2C38