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

add react-leaflet documentation #155

Closed
jrhizor opened this issue Apr 7, 2023 · 1 comment
Closed

add react-leaflet documentation #155

jrhizor opened this issue Apr 7, 2023 · 1 comment

Comments

@jrhizor
Copy link

jrhizor commented Apr 7, 2023

I imagine many new users for PMTiles on Leaflet these days are using React.

It took me a bit of time to figure out how to set up reading mvt files in react-leaflet but it turned out to be kind of simple. I'd appreciate if you added an example to https://protomaps.com/docs/frontends/leaflet that works with the CDN setup in the docs to save other new users some time.

Here's what I ended up with:

npm install react-leaflet protomaps 
npm install --save-dev @types/react-leaflet

and

import React from "react"
import {MapContainer, useMap} from "react-leaflet";
import {leafletLayer} from "protomaps";

function MapLoader() {
    const map = useMap();

    const layer = leafletLayer({url:'https://CLOUDFLARE_SUBDOMAIN/FILENAME/{z}/{x}/{y}.mvt'});
    layer.addTo(map);

    return null;
}

const MyMap: React.FC = () => {
    return (
        <MapContainer
            center={[0, 0]}
            zoom={14}
            scrollWheelZoom={true}
            style={{height: "500px", width: "500px"}}
        >
            <MapLoader />
        </MapContainer>
    );
}

export default MyMap
@bdon
Copy link
Member

bdon commented Apr 11, 2023

Thanks for the example! I'm reluctant to add this because whilereact-leaflet , react-map-gl etc are popular they are only relevant to Leaflet/MapLibre and not anything protomaps or vector tile related directly. So most users would be better served by consulting separate documentation for frameworks that wrap leaflet or maplibre.

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

No branches or pull requests

2 participants