File tree Expand file tree Collapse file tree 6 files changed +8589
-16
lines changed
Expand file tree Collapse file tree 6 files changed +8589
-16
lines changed Original file line number Diff line number Diff line change 22
33import 'leaflet/dist/leaflet.css'
44import type { PropsWithChildren } from 'react'
5- import { MapContainer , type MapContainerProps , TileLayer } from 'react-leaflet'
5+ import { MapContainer , type MapContainerProps } from 'react-leaflet'
6+ import TileLayer from './tile-layer'
67
78export type MapProps = MapContainerProps & PropsWithChildren
89
@@ -15,16 +16,13 @@ export default function Map({
1516} : MapProps ) {
1617 return (
1718 < MapContainer
19+ { ...mapProps }
20+ maxZoom = { 16 } // Maximum zoom level provided by Protomaps
1821 center = { center }
1922 zoom = { zoom }
2023 className = { className }
21- { ...mapProps }
2224 >
23- < TileLayer
24- attribution = '<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
25- url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
26- className = "dark:hue-rotate-180 dark:invert dark:contrast-[.90] dark:brightness-90"
27- />
25+ < TileLayer />
2826 { children }
2927 </ MapContainer >
3028 )
Original file line number Diff line number Diff line change 1+ import '@maplibre/maplibre-gl-leaflet'
2+ import L from 'leaflet'
3+ import { useTheme } from 'next-themes'
4+ import { useEffect , useRef } from 'react'
5+ import { useMap } from 'react-leaflet'
6+
7+ export default function TileLayer ( ) {
8+ const map = useMap ( )
9+ const { resolvedTheme } = useTheme ( )
10+ const glRef = useRef < L . MaplibreGL > (
11+ L . maplibreGL ( {
12+ style : `/map-styles/${ resolvedTheme } .json` ,
13+ } ) ,
14+ )
15+
16+ useEffect ( ( ) => {
17+ const maplibreMap = glRef . current . getMaplibreMap ( )
18+
19+ if ( ! maplibreMap ) {
20+ glRef . current . addTo ( map )
21+
22+ map . attributionControl
23+ . addAttribution (
24+ '<a href="https://datawan.id">Datawan</a> | <a href="https://github.com/protomaps/basemaps">Protomaps</a> © <a href="https://openstreetmap.org">OpenStreetMap</a>' ,
25+ )
26+ . setPrefix ( '<a href="https://leafletjs.com">Leaflet</a>' )
27+
28+ return
29+ }
30+
31+ // Update the style when the theme changes
32+ maplibreMap . setStyle ( `/map-styles/${ resolvedTheme } .json` )
33+ } , [ map , resolvedTheme ] )
34+
35+ return null
36+ }
Original file line number Diff line number Diff line change 2929 "node" : " >=18.17"
3030 },
3131 "dependencies" : {
32+ "@maplibre/maplibre-gl-leaflet" : " ^0.0.22" ,
3233 "@next/env" : " ^15.0.2" ,
3334 "@radix-ui/react-alert-dialog" : " ^1.1.2" ,
3435 "@radix-ui/react-dialog" : " ^1.1.2" ,
You can’t perform that action at this time.
0 commit comments