Persist bearing & pitch
This commit is contained in:
@@ -8,10 +8,12 @@ import { MdFullscreen, MdRadar, MdWbShade } from 'react-icons/md';
|
|||||||
import { useMapbox } from '@app/hooks/mapbox';
|
import { useMapbox } from '@app/hooks/mapbox';
|
||||||
import { useAppDispatch, useAppSelector } from '@app/hooks/redux';
|
import { useAppDispatch, useAppSelector } from '@app/hooks/redux';
|
||||||
import {
|
import {
|
||||||
|
setBearing,
|
||||||
setExaggeration,
|
setExaggeration,
|
||||||
setHillShade,
|
setHillShade,
|
||||||
setLatLng,
|
setLatLng,
|
||||||
setMapStyle,
|
setMapStyle,
|
||||||
|
setPitch,
|
||||||
setZoom,
|
setZoom,
|
||||||
} from '@core/slices/mapSlice';
|
} from '@core/slices/mapSlice';
|
||||||
import { Card, IconButton } from '@meshtastic/components';
|
import { Card, IconButton } from '@meshtastic/components';
|
||||||
@@ -32,6 +34,8 @@ export const Map = (): JSX.Element => {
|
|||||||
const map = useMapbox(mapRef, mapState.accessToken, {
|
const map = useMapbox(mapRef, mapState.accessToken, {
|
||||||
center: mapState.latLng,
|
center: mapState.latLng,
|
||||||
zoom: mapState.zoom,
|
zoom: mapState.zoom,
|
||||||
|
bearing: mapState.bearing,
|
||||||
|
pitch: mapState.pitch,
|
||||||
style: mapState.style.url,
|
style: mapState.style.url,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -117,6 +121,12 @@ export const Map = (): JSX.Element => {
|
|||||||
map?.on('zoomend', (e) => {
|
map?.on('zoomend', (e) => {
|
||||||
dispatch(setZoom(e.target.getZoom()));
|
dispatch(setZoom(e.target.getZoom()));
|
||||||
});
|
});
|
||||||
|
map?.on('rotate', (e) => {
|
||||||
|
dispatch(setBearing(e.target.getBearing()));
|
||||||
|
});
|
||||||
|
map?.on('pitch', (e) => {
|
||||||
|
dispatch(setPitch(e.target.getPitch()));
|
||||||
|
});
|
||||||
}, [dispatch, map, updateNodes, mapState.exaggeration]);
|
}, [dispatch, map, updateNodes, mapState.exaggeration]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import { createSlice } from '@reduxjs/toolkit';
|
|||||||
interface MapState {
|
interface MapState {
|
||||||
latLng: mapboxgl.LngLat;
|
latLng: mapboxgl.LngLat;
|
||||||
zoom: number;
|
zoom: number;
|
||||||
|
bearing: number;
|
||||||
|
pitch: number;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
style: MapStyle;
|
style: MapStyle;
|
||||||
hillShade: boolean;
|
hillShade: boolean;
|
||||||
@@ -17,6 +19,8 @@ interface MapState {
|
|||||||
const initialState: MapState = {
|
const initialState: MapState = {
|
||||||
latLng: new mapboxgl.LngLat(-77.0305, 38.8868),
|
latLng: new mapboxgl.LngLat(-77.0305, 38.8868),
|
||||||
zoom: 9,
|
zoom: 9,
|
||||||
|
bearing: 0,
|
||||||
|
pitch: 0,
|
||||||
accessToken:
|
accessToken:
|
||||||
'pk.eyJ1Ijoic2FjaGF3IiwiYSI6ImNrNW9meXozZjBsdW0zbHBjM2FnNnV6cmsifQ.3E4n8eFGD9ZOFo-XDVeZnQ',
|
'pk.eyJ1Ijoic2FjaGF3IiwiYSI6ImNrNW9meXozZjBsdW0zbHBjM2FnNnV6cmsifQ.3E4n8eFGD9ZOFo-XDVeZnQ',
|
||||||
style:
|
style:
|
||||||
@@ -37,6 +41,12 @@ export const mapSlice = createSlice({
|
|||||||
setZoom: (state, action: PayloadAction<number>) => {
|
setZoom: (state, action: PayloadAction<number>) => {
|
||||||
state.zoom = action.payload;
|
state.zoom = action.payload;
|
||||||
},
|
},
|
||||||
|
setBearing: (state, action: PayloadAction<number>) => {
|
||||||
|
state.bearing = action.payload;
|
||||||
|
},
|
||||||
|
setPitch: (state, action: PayloadAction<number>) => {
|
||||||
|
state.pitch = action.payload;
|
||||||
|
},
|
||||||
setMapStyle(state, action: PayloadAction<MapStyle>) {
|
setMapStyle(state, action: PayloadAction<MapStyle>) {
|
||||||
state.style = action.payload;
|
state.style = action.payload;
|
||||||
},
|
},
|
||||||
@@ -52,6 +62,8 @@ export const mapSlice = createSlice({
|
|||||||
export const {
|
export const {
|
||||||
setLatLng,
|
setLatLng,
|
||||||
setZoom,
|
setZoom,
|
||||||
|
setBearing,
|
||||||
|
setPitch,
|
||||||
setMapStyle,
|
setMapStyle,
|
||||||
setHillShade,
|
setHillShade,
|
||||||
setExaggeration,
|
setExaggeration,
|
||||||
|
|||||||
Reference in New Issue
Block a user