From f54fe701e7f48a6b0255219dbf86739e2c11bc9a Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sun, 21 Nov 2021 17:22:39 +0100 Subject: [PATCH] frontend: Fix attributions and reuse map code --- frontend/src/pages/HomePage.tsx | 32 ++++---------------------------- frontend/src/pages/MapPage.tsx | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx index 8642af7..f17239c 100644 --- a/frontend/src/pages/HomePage.tsx +++ b/frontend/src/pages/HomePage.tsx @@ -7,36 +7,12 @@ import {map, switchMap} from 'rxjs/operators' import api from 'api' import {Stats, Page} from 'components' -import {useConfig, MapSource} from 'config' import {TrackListItem} from './TracksPage' +import {RoadsMap} from './MapPage' import styles from './HomePage.module.scss' import 'ol/ol.css' -import {obsRoads} from '../mapstyles' -import ReactMapGl from 'react-map-gl' - -function WelcomeMap({mapSource}: {mapSource: MapSource}) { - const mapStyle = React.useMemo(() => obsRoads(mapSource), [mapSource]) - const config = useConfig() - const [viewport, setViewport] = React.useState({ - longitude: 0, - latitude: 0, - zoom: 0, - }) - - React.useEffect(() => { - if (config?.mapHome) { - setViewport(config.mapHome) - } - }, [config]) - - return ( -
- -
- ) -} function MostRecentTrack() { const track: Track | null = useObservable( @@ -67,14 +43,14 @@ function MostRecentTrack() { } export default function HomePage() { - const {obsMapSource: mapSource} = useConfig() || {} - return ( - {mapSource ? : null} +
+ +
diff --git a/frontend/src/pages/MapPage.tsx b/frontend/src/pages/MapPage.tsx index b5bd8c9..2459ed0 100644 --- a/frontend/src/pages/MapPage.tsx +++ b/frontend/src/pages/MapPage.tsx @@ -9,9 +9,9 @@ import styles from './MapPage.module.scss' import 'ol/ol.css' import {obsRoads} from '../mapstyles' -import ReactMapGl from 'react-map-gl' +import ReactMapGl, {AttributionControl } from 'react-map-gl' -function BigMap({mapSource, config}: {mapSource: string ,config: Config}) { +function RoadsMapInner({mapSource, config}: {mapSource: string ,config: Config}) { const mapStyle = React.useMemo(() => mapSource && obsRoads(mapSource), [mapSource]) const [viewport, setViewport] = React.useState({ longitude: 0, @@ -30,22 +30,34 @@ function BigMap({mapSource, config}: {mapSource: string ,config: Config}) { } return ( -
- -
+ + © OpenStreetMap contributors', + '© OpenMapTiles', + '© OpenBikeSensor', + ]} /> + ) } -export default function MapPage() { +export function RoadsMap(props) { const config = useConfig() || {} if (!config) return null; const {obsMapSource: mapSource} = config if (!mapSource) return null; + return ( + + ) +} + +export default function MapPage() { return ( - +
+ +
) }