-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.tsx
More file actions
89 lines (76 loc) · 1.94 KB
/
Copy pathApp.tsx
File metadata and controls
89 lines (76 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import MapView from "react-native-better-clustering";
import { StatusBar } from "expo-status-bar";
import { useMemo } from "react";
import { StyleSheet, View } from "react-native";
import { Marker } from "react-native-maps";
const POLAND_BOUNDS = {
minLat: 49.0,
maxLat: 54.8,
minLng: 14.1,
maxLng: 24.1,
} as const;
const INITIAL_REGION = {
latitude: 50.0647,
longitude: 19.945,
latitudeDelta: 0.3,
longitudeDelta: 0.3,
};
interface MapPoint {
id: string;
latitude: number;
longitude: number;
}
function randomInRange(min: number, max: number): number {
return Math.random() * (max - min) + min;
}
function generatePoints(count: number): MapPoint[] {
const points: MapPoint[] = [];
for (let i = 0; i < count; i++) {
points.push({
id: String(i),
latitude: randomInRange(POLAND_BOUNDS.minLat, POLAND_BOUNDS.maxLat),
longitude: randomInRange(POLAND_BOUNDS.minLng, POLAND_BOUNDS.maxLng),
});
}
return points;
}
function getRandomLatitude(min = 48, max = 56) {
return Math.random() * (max - min) + min;
}
function getRandomLongitude(min = 14, max = 24) {
return Math.random() * (max - min) + min;
}
function generateRandomPoints(count: number): MapPoint[] {
return Array.from({ length: count }, () => ({
id: String(Math.random()),
latitude: getRandomLatitude(),
longitude: getRandomLongitude(),
}));
}
export default function App() {
const points = useMemo(() => generatePoints(2000), []);
return (
<View style={styles.container}>
<StatusBar style="dark" />
<MapView style={styles.map} initialRegion={INITIAL_REGION}>
{points.map((point) => (
<Marker
key={point.id}
coordinate={{
latitude: point.latitude,
longitude: point.longitude,
}}
/>
))}
</MapView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
map: {
flex: 1,
},
});