Skip to content

Commit 4457490

Browse files
authored
refactor: switch many examples to TypeScript (#469)
* refactor: switch many examples to ts * style: remove debugging * fix: use Page in FollowUserLocationRenderMode * style: remove unused prop
1 parent 77701aa commit 4457490

35 files changed

+1178
-1437
lines changed

packages/examples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"@react-native-masked-view/masked-view": "^0.3.1",
1717
"@react-navigation/native": "^6.1.8",
1818
"@react-navigation/stack": "^6.3.25",
19+
"@rneui/base": "^4.0.0-rc.8",
20+
"@rneui/themed": "^4.0.0-rc.8",
1921
"@turf/along": "^6.5.0",
2022
"@turf/bbox-polygon": "^6.5.0",
2123
"@turf/distance": "^6.5.0",
@@ -26,10 +28,8 @@
2628
"debounce": "^2.0.0",
2729
"fbjs": "^3.0.5",
2830
"moment": "^2.30.1",
29-
"prop-types": "^15.7.2",
3031
"react": "18.2.0",
3132
"react-native": "0.74.6",
32-
"react-native-elements": "^3.4.3",
3333
"react-native-gesture-handler": "~2.16.1",
3434
"react-native-reanimated": "~3.10.1",
3535
"react-native-safe-area-context": "4.10.5",
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import MapLibreGL, { LineLayerStyle } from "@maplibre/maplibre-react-native";
2+
import { Feature, LineString, Point } from "geojson";
3+
import React, { useEffect, useState } from "react";
4+
5+
import sheet from "../../styles/sheet";
6+
import RouteSimulator from "../../utils/RouteSimulator";
7+
import Page from "../common/Page";
8+
import PulseCircleLayer from "../common/PulseCircleLayer";
9+
10+
const ROUTE_FEATURE: Feature<LineString> = {
11+
type: "Feature",
12+
geometry: {
13+
type: "LineString",
14+
coordinates: [
15+
[8.070566386917108, 53.295365558646694],
16+
[13.37432488261203, 52.50503393836857],
17+
[7.218077210609579, 50.98270036522064],
18+
[13.652081261390094, 49.583747114745165],
19+
[8.1694637345079, 47.9516814815924],
20+
],
21+
},
22+
properties: {},
23+
};
24+
25+
const layerStyles: {
26+
route: LineLayerStyle;
27+
progress: LineLayerStyle;
28+
} = {
29+
route: {
30+
lineColor: "white",
31+
lineCap: "round",
32+
lineWidth: 3,
33+
lineOpacity: 0.84,
34+
},
35+
progress: {
36+
lineColor: "#314ccd",
37+
lineWidth: 3,
38+
},
39+
};
40+
41+
export default function AnimateCircleAlongLine() {
42+
const [currentPoint, setCurrentPoint] =
43+
useState<Feature<Point, { distance: number; nearestIndex: number }>>();
44+
45+
useEffect(() => {
46+
const routeSimulator = new RouteSimulator(ROUTE_FEATURE);
47+
48+
routeSimulator.addListener(
49+
(point: Feature<Point, { distance: number; nearestIndex: number }>) => {
50+
setCurrentPoint(point);
51+
},
52+
);
53+
54+
routeSimulator.start();
55+
56+
return () => {
57+
routeSimulator.stop();
58+
};
59+
}, []);
60+
61+
const renderProgressLine = () => {
62+
if (!currentPoint) {
63+
return null;
64+
}
65+
66+
const { nearestIndex } = currentPoint.properties;
67+
const coords = ROUTE_FEATURE.geometry.coordinates.filter(
68+
(c, i) => i <= nearestIndex,
69+
);
70+
coords.push(currentPoint.geometry.coordinates);
71+
72+
if (coords.length < 2) {
73+
return null;
74+
}
75+
76+
const lineString: LineString = { type: "LineString", coordinates: coords };
77+
78+
return (
79+
<MapLibreGL.Animated.ShapeSource id="progressSource" shape={lineString}>
80+
{/* @ts-ignore */}
81+
<MapLibreGL.Animated.LineLayer
82+
id="progress-line"
83+
style={layerStyles.progress}
84+
aboveLayerID="route-line"
85+
/>
86+
</MapLibreGL.Animated.ShapeSource>
87+
);
88+
};
89+
90+
return (
91+
<Page>
92+
<MapLibreGL.MapView style={sheet.matchParent}>
93+
<MapLibreGL.Camera
94+
defaultSettings={{
95+
bounds: {
96+
ne: [-3.419709, 44.452929],
97+
sw: [25.309539, 55.766941],
98+
},
99+
}}
100+
/>
101+
102+
<MapLibreGL.ShapeSource id="route-source" shape={ROUTE_FEATURE}>
103+
<MapLibreGL.LineLayer id="route-line" style={layerStyles.route} />
104+
</MapLibreGL.ShapeSource>
105+
106+
{currentPoint && <PulseCircleLayer shape={currentPoint} />}
107+
108+
{renderProgressLine()}
109+
</MapLibreGL.MapView>
110+
</Page>
111+
);
112+
}

packages/examples/src/examples/Animations/DriveTheLine.js

Lines changed: 0 additions & 227 deletions
This file was deleted.

0 commit comments

Comments
 (0)