1
0
Fork 0
blog/src/components/atoms/ExifMap.tsx

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-05-22 14:38:19 +02:00
import React, { ReactElement, useState } from 'react'
2021-03-21 20:36:18 +01:00
import { Map } from 'pigeon-maps'
2019-05-02 21:11:52 +02:00
import Marker from 'pigeon-marker'
2021-03-13 04:11:44 +01:00
import useDarkMode from '../../hooks/useDarkMode'
2019-05-02 21:11:52 +02:00
2021-05-23 13:38:15 +02:00
const mapbox =
2021-12-02 19:23:17 +01:00
(mapboxId: string) => (x: string, y: string, z: string, dpr: number) =>
2021-05-23 13:38:15 +02:00
`https://api.mapbox.com/styles/v1/mapbox/${mapboxId}/tiles/256/${z}/${x}/${y}${
dpr >= 2 ? '@2x' : ''
}?access_token=${process.env.GATSBY_MAPBOX_ACCESS_TOKEN}`
2019-05-02 21:11:52 +02:00
const providers = {
2019-11-06 21:58:41 +01:00
light: mapbox('light-v10'),
dark: mapbox('dark-v10')
2019-05-02 21:11:52 +02:00
}
2019-10-02 13:35:50 +02:00
export default function ExifMap({
gps
}: {
gps: { latitude: number; longitude: number }
2020-05-22 14:38:19 +02:00
}): ReactElement {
2021-03-13 04:11:44 +01:00
const { value } = useDarkMode()
2019-10-15 01:47:42 +02:00
const isDarkMode = value
2019-10-02 13:35:50 +02:00
const [zoom, setZoom] = useState(12)
2019-05-02 21:11:52 +02:00
2019-10-02 13:35:50 +02:00
const zoomIn = () => {
setZoom(Math.min(zoom + 4, 20))
2019-05-02 21:11:52 +02:00
}
2019-10-02 13:35:50 +02:00
const { latitude, longitude } = gps
return (
<Map
center={[latitude, longitude]}
zoom={zoom}
2021-12-02 19:23:17 +01:00
height={220}
2019-10-15 01:47:42 +02:00
dprs={[1, 2]}
2019-10-02 13:35:50 +02:00
attribution={false}
2019-10-03 19:18:01 +02:00
provider={isDarkMode ? providers['dark'] : providers['light']}
2019-10-02 13:35:50 +02:00
metaWheelZoom={true}
metaWheelZoomWarning={'META+wheel to zoom'}
>
<Marker anchor={[latitude, longitude]} payload={1} onClick={zoomIn} />
</Map>
)
2019-05-02 21:11:52 +02:00
}