-
-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Description
Hello,
I'm encountering an issue with implementing offline map functionality using multiple tile sources.
My intended behavior is for the map to use an online tile source when an internet connection is available and automatically fall back to a local server source when offline.
While the local server itself appears to be working, the map tiles are not displaying correctly. Instead, the layers seem to be overlapping each other, resulting in a blank or incomplete map.
Thank you for your help, and for your work on this fantastic project!
Server
I began by creating and downloading several PMTiles files. These are being served locally using the pmtiles serve . command, with Nginx acting as the reverse proxy.
To validate the server setup, I successfully tested the tile endpoints. The local URLs, structured as http://127.0.0.1/pmtile-1/{z}/{x}/{y}.mvt and http://127.0.0.1/pmtile-2/{z}/{x}/{y}.mvt, correctly return vector tile data with HTTP 200 (Success) or 204 (No Content) status codes.
Client
Following that, I created a custom layer within the react-leaflet framework, defined as follows:
import { leafletLayer } from "protomaps-leaflet";
import { useEffect } from "react";
import { useMap } from "react-leaflet";
export const ProtomapsTileLayer = () => {
const map = useMap();
const sources = {
"": {
url: "https://data.source.coop/protomaps/openstreetmap/v4.pmtiles",
},
pmtiles-1: {
url: "http://127.0.0.1/pmtiles-1/{z}/{x}/{y}.mvt",
},
pmtiles-2: {
url: "http://127.0.0.1/pmtiles-2/{z}/{x}/{y}.mvt"",
},
pmtiles-3: {
url: "http://127.0.0.1/pmtiles-3/{z}/{x}/{y}.mvt"",
},
};
useEffect(() => {
const protomapsLayer = leafletLayer({
sources: sources,
flavor: "light",
lang: "en",
});
protomapsLayer.addTo(map);
return () => {
map.removeLayer(protomapsLayer);
};
}, [map]);
return null;
};Here's how I use MapContainer:
<MapContainer
ref={mapRef}
className="h-100 w-100"
...
>
<ProtomapsTileLayer/>
...
</MapContainer>