Skip to content

Commit fe20876

Browse files
committed
Move style to env, manage marker visibility with map events
1 parent 289910f commit fe20876

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ declare module '@env' {
33
export const GTFS_API_GATEWAY_KEY: string;
44
export const WEBSOCKET_GATEWAY_URL: string;
55
export const MAPBOX_ACCESS_TOKEN: string;
6+
export const MAPBOX_STYLE_URL: string;
67
}

src/components/Map.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,42 @@ import React, { FC } from 'react';
22
import { StyleSheet } from 'react-native';
33
import MapboxGL from '@react-native-mapbox-gl/maps';
44
import { Coordinate } from 'interfaces';
5-
import { MAPBOX_ACCESS_TOKEN } from '@env';
5+
import { MAPBOX_ACCESS_TOKEN, MAPBOX_STYLE_URL } from '@env';
66

77
type Props = {
88
centerCoordinate: Coordinate;
99
zoomLevel: number;
1010
pitch: number;
1111
children: any;
12+
onRegionWillChange?: () => void;
13+
onRegionDidChange?: () => void;
1214
};
1315

1416
MapboxGL.setAccessToken(MAPBOX_ACCESS_TOKEN);
1517

16-
const ANIMATION_DURATION = 1500;
17-
const styleURL = 'mapbox://styles/jurevans/ckx09yl8v07tm14rupxmhhz3o';
18-
18+
const ANIMATION_DURATION = 1000;
1919
const styles = StyleSheet.create({
2020
map: {
2121
flex: 1,
2222
},
2323
});
2424

25-
const Map: FC<Props> = ({ centerCoordinate, zoomLevel, pitch, children }) => {
25+
const Map: FC<Props> = ({
26+
centerCoordinate,
27+
zoomLevel,
28+
pitch,
29+
onRegionWillChange,
30+
onRegionDidChange,
31+
children,
32+
}) => {
2633
return (
2734
<MapboxGL.MapView
28-
styleURL={styleURL}
35+
styleURL={MAPBOX_STYLE_URL || MapboxGL.StyleURL.Dark}
2936
pitchEnabled={true}
3037
logoEnabled={false}
3138
compassEnabled={true}
39+
onRegionWillChange={onRegionWillChange}
40+
onRegionDidChange={onRegionDidChange}
3241
style={styles.map}>
3342
<MapboxGL.Camera
3443
zoomLevel={zoomLevel}

src/screens/map/MapScreen.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { StopTimeCallback } from 'components/StopTime';
2323
const DEFAULT_COORD: Coordinate = [-73.94594865587045, 40.7227534777328];
2424
const DEFAULT_ZOOM = 11;
2525
const STOP_ZOOM = 15;
26-
const ANIMATION_DURATION = 1500;
2726

2827
interface ShapeVars {
2928
shapeId: string;
@@ -83,8 +82,6 @@ const MapScreen: FC = () => {
8382
stopId: stopId,
8483
}),
8584
);
86-
setMarkerVisible(false);
87-
setTimeout(() => setMarkerVisible(true), ANIMATION_DURATION);
8885
},
8986
[dispatch],
9087
);
@@ -95,7 +92,7 @@ const MapScreen: FC = () => {
9592
centerCoordinate: stop?.geom.coordinates || DEFAULT_COORD,
9693
zoomLevel: STOP_ZOOM,
9794
}));
98-
}, [stop?.geom.coordinates]);
95+
}, [stop]);
9996

10097
const shapeLayerId = `line-layer-${trip?.feedIndex}:${trip?.tripId}`;
10198

@@ -105,7 +102,9 @@ const MapScreen: FC = () => {
105102
<Map
106103
centerCoordinate={centerCoordinate}
107104
zoomLevel={zoomLevel}
108-
pitch={pitch}>
105+
pitch={pitch}
106+
onRegionWillChange={() => setMarkerVisible(false)}
107+
onRegionDidChange={() => setMarkerVisible(true)}>
109108
{stop?.geom && isMarkerVisible && (
110109
<StopMarker
111110
feedIndex={stop.feedIndex}

0 commit comments

Comments
 (0)