Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enable PMTile protocol support #186

Open
micheal-w-wells opened this issue Sep 19, 2024 · 4 comments
Open

Feature: Enable PMTile protocol support #186

micheal-w-wells opened this issue Sep 19, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@micheal-w-wells
Copy link

micheal-w-wells commented Sep 19, 2024

@mapcomponents/react-maplibre version:

Feature description

PMTile vector sources can be rendered

Example

<MlPMTileLayer or MlVectorTileLayer

Summary

For react devs using maplibre your library is a clear win, however some of us are using pmtile files and its not super intuitive to add a new protocol just yet

@cioddi cioddi added the enhancement New feature or request label Sep 19, 2024
@cioddi
Copy link
Member

cioddi commented Sep 19, 2024

In my opinion the useAddProtocol hook provides the required functionality to work well with the pmtiles package.
We are using pmtiles too in our MapComponents application.
iirc there have been some issues with Github pages (where all the examples are hosted) and byte range requests, which are required for pmtiles to work.

The example from pmtiles can be easily adapted to work with MapComponents though.
https://github.com/protomaps/PMTiles/blob/main/js/examples/maplibre.html

// This line should be outside of your react component
let protocol = new pmtiles.Protocol();

// This line inside your react component
useAddProtocol({
    protocol: 'pmtiles',
    handler: protocol.tile
});

// In the JSX
<MlVectorTileLayer url={'pmtiles://https://URL_TO_YOUR_PMTILES/{z}/{x}/{y}'} />

If you provide an example that is not working now, we can take a look at it.

@micheal-w-wells
Copy link
Author

micheal-w-wells commented Sep 19, 2024

Thanks very much for the help! Your example is very straight forward, but I don't seem to be able to get it to work. If you checkout https://github.com/bcgov/WetpaddlersV2/tree/issue_example that branch, and cd app && nvm use 20 && npm install && npm run dev you can run the app and you should see some blue circles on the west coast of North America (BC to be more specific). The commented out 'old way' of adding the PMTile layer is in a hook near the top of the file.

EDIT: This branch got a bit closer, but gives a 'invalid PMTile URL error: issue_example_2

@cioddi
Copy link
Member

cioddi commented Sep 20, 2024

I have created a pull request for your repo that fixes the implementation.
PMTiles URL was missing ZXY placeholders. I have now also added them in the example above.

bcgov/WetpaddlersV2#39

The examples in the pmtiles repo are working too though. The props object passed to the protocol handler in the pmtiles repo examples has a type property with the value json, in all of my implementations it has the value arrayBuffer. I do not know yet how that is determined.

@micheal-w-wells
Copy link
Author

Thank you again for the help and insight!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants