@wasto/cms-components 1.5.10 → 1.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -47
- package/dist/index.d.mts +181 -51
- package/dist/index.d.ts +181 -51
- package/dist/index.js +3614 -3015
- package/dist/index.mjs +3021 -2418
- package/package.json +12 -2
- package/src/components/announcement-modal/AnnouncementModal.tsx +183 -183
- package/src/components/article/Article.tsx +21 -21
- package/src/components/article/ArticleCard.tsx +81 -81
- package/src/components/article/ArticleExcerpts.tsx +80 -80
- package/src/components/article/ArticleList.tsx +114 -114
- package/src/components/article/ArticleMarkdown.tsx +170 -170
- package/src/components/article/ArticleReaderModal.tsx +93 -93
- package/src/components/article/ArticleSingle.tsx +57 -57
- package/src/components/bottom-tab/BottomTab.tsx +392 -392
- package/src/components/button/Button.tsx +154 -154
- package/src/components/challenge/Badges.tsx +84 -84
- package/src/components/challenge/BadgesModal.tsx +166 -166
- package/src/components/challenge/Challenge.tsx +380 -380
- package/src/components/challenge/ChallengeModal.tsx +231 -231
- package/src/components/challenge/ChallengeVignette.tsx +249 -249
- package/src/components/challenge/ChallengesModal.tsx +243 -243
- package/src/components/challenge/QuizModal.tsx +381 -381
- package/src/components/challenge/ResultModal.tsx +144 -144
- package/src/components/chat/Chat.tsx +928 -928
- package/src/components/collection-calendar/CollectionCalendar.tsx +274 -274
- package/src/components/columns/Columns.tsx +33 -33
- package/src/components/consignes-modal/ConsignesModal.tsx +267 -267
- package/src/components/content-inset/ContentInset.tsx +33 -33
- package/src/components/header/Header.tsx +415 -391
- package/src/components/image/Image.tsx +15 -15
- package/src/components/image/ImageFrame.tsx +102 -102
- package/src/components/image/ImageMedia.tsx +31 -31
- package/src/components/image/ImageUrl.tsx +30 -30
- package/src/components/locations-map/LocationSheet.tsx +417 -417
- package/src/components/locations-map/LocationsMap.native.tsx +260 -260
- package/src/components/locations-map/LocationsMap.tsx +13 -13
- package/src/components/locations-map/LocationsMap.web.tsx +10 -10
- package/src/components/locations-map/LocationsMapShell.tsx +546 -527
- package/src/components/locations-map/LocationsMapView.tsx +108 -108
- package/src/components/locations-map/LocationsMapView.web.tsx +331 -331
- package/src/components/nav-button/NavButton.tsx +59 -59
- package/src/components/next-collection/NextCollection.tsx +636 -621
- package/src/components/notifications/NotificationsScreen.tsx +247 -247
- package/src/components/page/Page.tsx +102 -64
- package/src/components/parapraph/Paragraph.tsx +67 -67
- package/src/components/profile/ProfileScreen.tsx +236 -236
- package/src/components/push/PushTokenRegistrar.tsx +47 -0
- package/src/components/recycling-info/RecyclingInfo.tsx +189 -189
- package/src/components/safe-area/OptionalSafeAreaProvider.tsx +17 -17
- package/src/components/search/Search.tsx +320 -320
- package/src/components/select-street-modal/SelectStreetModal.tsx +475 -475
- package/src/components/title/Title.tsx +100 -100
- package/src/components/vision/Vision.tsx +447 -447
- package/src/components/vision/VisionActionCard.tsx +117 -117
- package/src/components/vision/VisionCapture.tsx +30 -30
- package/src/components/vision/VisionTapOverlay.tsx +122 -122
- package/src/contexts/AnnouncementsContext.tsx +171 -171
- package/src/contexts/AppDataContext.tsx +458 -0
- package/src/contexts/ChallengesContext.tsx +182 -182
- package/src/contexts/HeaderConfigContext.tsx +29 -0
- package/src/contexts/LocalContext.tsx +227 -227
- package/src/contexts/ThemeContext.tsx +37 -37
- package/src/contexts/WastoContext.tsx +132 -127
- package/src/helpers/blogPost.ts +72 -72
- package/src/helpers/generateQuizQuestions.ts +247 -247
- package/src/helpers/getContrastColor.ts +18 -18
- package/src/helpers/haptics.ts +20 -20
- package/src/helpers/hoursSchedule.ts +230 -230
- package/src/helpers/htmlContentToMarkdown.ts +114 -114
- package/src/helpers/layout.ts +54 -54
- package/src/helpers/loadLinearGradient.ts +22 -22
- package/src/helpers/mapLocations.ts +170 -0
- package/src/helpers/maquetteTheme.ts +76 -76
- package/src/helpers/markdownUnderlinePlugin.ts +32 -32
- package/src/helpers/nextCollection.ts +122 -0
- package/src/helpers/normalizeWasteTypeRecyclingInfo.ts +80 -80
- package/src/helpers/publicMediaUrl.ts +8 -8
- package/src/helpers/resolveApiAssetUrl.ts +21 -21
- package/src/helpers/systemRoutes.ts +7 -7
- package/src/helpers/themeStyles.ts +114 -114
- package/src/helpers/ttlCache.ts +41 -0
- package/src/helpers/useSafeAreaPadding.ts +14 -14
- package/src/hooks/useBadges.ts +100 -100
- package/src/hooks/useBlogPosts.ts +109 -105
- package/src/hooks/useChallenges.ts +110 -110
- package/src/hooks/useCities.ts +56 -56
- package/src/hooks/useCityAnnouncements.ts +118 -118
- package/src/hooks/useCollectionCalendar.ts +421 -421
- package/src/hooks/useColumns.ts +19 -19
- package/src/hooks/useConsignes.ts +62 -62
- package/src/hooks/useLocations.ts +120 -248
- package/src/hooks/useNextCollection.ts +163 -238
- package/src/hooks/useRecyclingInfo.ts +90 -90
- package/src/hooks/useWastoClient.ts +16 -16
- package/src/index.ts +161 -142
- package/src/navigation/NavigationContext.tsx +56 -56
- package/src/push/registerExpoPushToken.ts +133 -0
- package/src/sentry/initSentry.ts +120 -120
- package/src/types/Theme.ts +72 -72
- package/src/types/css-modules.d.ts +1 -1
|
@@ -1,260 +1,260 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Camera,
|
|
3
|
-
GeoJSONSource,
|
|
4
|
-
Layer,
|
|
5
|
-
Map,
|
|
6
|
-
type CameraRef,
|
|
7
|
-
type GeoJSONSourceRef,
|
|
8
|
-
type PressEventWithFeatures,
|
|
9
|
-
} from "@maplibre/maplibre-react-native";
|
|
10
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
11
|
-
import { StyleSheet, View, type NativeSyntheticEvent } from "react-native";
|
|
12
|
-
import {
|
|
13
|
-
LOCATION_CATEGORY_META,
|
|
14
|
-
REUNION_CENTER,
|
|
15
|
-
isValidLatLon,
|
|
16
|
-
type LocationCategory,
|
|
17
|
-
type MapLocation,
|
|
18
|
-
} from "../../hooks/useLocations";
|
|
19
|
-
import type { LocationsMapViewProps } from "./LocationsMapView";
|
|
20
|
-
import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
|
|
21
|
-
|
|
22
|
-
export type { LocationsMapProps };
|
|
23
|
-
|
|
24
|
-
const MAP_STYLE = "https://tiles.openfreemap.org/styles/liberty";
|
|
25
|
-
const CLUSTER_RADIUS = 56;
|
|
26
|
-
const CLUSTER_MAX_ZOOM = 16;
|
|
27
|
-
const ZOOM_MIN = 8;
|
|
28
|
-
const ZOOM_MAX = 18;
|
|
29
|
-
const FIT_PADDING = { top: 48, right: 48, bottom: 48, left: 48 };
|
|
30
|
-
|
|
31
|
-
function toGeoJson(locations: MapLocation[]): GeoJSON.FeatureCollection {
|
|
32
|
-
return {
|
|
33
|
-
type: "FeatureCollection",
|
|
34
|
-
features: locations.map((loc) => ({
|
|
35
|
-
type: "Feature",
|
|
36
|
-
geometry: { type: "Point", coordinates: [loc.lon, loc.lat] },
|
|
37
|
-
properties: {
|
|
38
|
-
id: loc.id,
|
|
39
|
-
color: LOCATION_CATEGORY_META[loc.category as LocationCategory].color,
|
|
40
|
-
},
|
|
41
|
-
})),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function boundsFromLocations(locations: MapLocation[]): [number, number, number, number] | null {
|
|
46
|
-
if (locations.length === 0) return null;
|
|
47
|
-
let west = locations[0]!.lon;
|
|
48
|
-
let east = locations[0]!.lon;
|
|
49
|
-
let south = locations[0]!.lat;
|
|
50
|
-
let north = locations[0]!.lat;
|
|
51
|
-
for (const loc of locations) {
|
|
52
|
-
west = Math.min(west, loc.lon);
|
|
53
|
-
east = Math.max(east, loc.lon);
|
|
54
|
-
south = Math.min(south, loc.lat);
|
|
55
|
-
north = Math.max(north, loc.lat);
|
|
56
|
-
}
|
|
57
|
-
const pad = west === east && south === north ? 0.01 : 0;
|
|
58
|
-
return [west - pad, south - pad, east + pad, north + pad];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function isClusterFeature(feature: GeoJSON.Feature): boolean {
|
|
62
|
-
const props = feature.properties ?? {};
|
|
63
|
-
return props.cluster === true || typeof props.point_count === "number";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function NativeMapCanvas({
|
|
67
|
-
locations,
|
|
68
|
-
center,
|
|
69
|
-
selectedId,
|
|
70
|
-
onSelect,
|
|
71
|
-
}: LocationsMapViewProps) {
|
|
72
|
-
const cameraRef = useRef<CameraRef>(null);
|
|
73
|
-
const sourceRef = useRef<GeoJSONSourceRef>(null);
|
|
74
|
-
const [mapReady, setMapReady] = useState(false);
|
|
75
|
-
|
|
76
|
-
const safeCenter = useMemo(() => {
|
|
77
|
-
if (isValidLatLon(center.lat, center.lon)) return center;
|
|
78
|
-
return REUNION_CENTER;
|
|
79
|
-
}, [center]);
|
|
80
|
-
|
|
81
|
-
const validLocations = useMemo(
|
|
82
|
-
() => locations.filter((loc) => isValidLatLon(loc.lat, loc.lon)),
|
|
83
|
-
[locations],
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const geojson = useMemo(() => toGeoJson(validLocations), [validLocations]);
|
|
87
|
-
|
|
88
|
-
const locationById = useMemo(() => {
|
|
89
|
-
const byId: Record<string, MapLocation> = {};
|
|
90
|
-
for (const loc of validLocations) byId[loc.id] = loc;
|
|
91
|
-
return byId;
|
|
92
|
-
}, [validLocations]);
|
|
93
|
-
|
|
94
|
-
const fitToLocations = useCallback(() => {
|
|
95
|
-
const bounds = boundsFromLocations(validLocations);
|
|
96
|
-
if (!bounds) return;
|
|
97
|
-
cameraRef.current?.fitBounds(bounds, { duration: 400, padding: FIT_PADDING });
|
|
98
|
-
}, [validLocations]);
|
|
99
|
-
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (!mapReady) return;
|
|
102
|
-
fitToLocations();
|
|
103
|
-
}, [mapReady, fitToLocations]);
|
|
104
|
-
|
|
105
|
-
const onMapLoaded = useCallback(() => {
|
|
106
|
-
setMapReady(true);
|
|
107
|
-
}, []);
|
|
108
|
-
|
|
109
|
-
const onSourcePress = useCallback(
|
|
110
|
-
async (event: NativeSyntheticEvent<PressEventWithFeatures>) => {
|
|
111
|
-
if (typeof event.stopPropagation === "function") {
|
|
112
|
-
event.stopPropagation();
|
|
113
|
-
}
|
|
114
|
-
const feature = event.nativeEvent.features[0];
|
|
115
|
-
if (!feature) return;
|
|
116
|
-
|
|
117
|
-
if (isClusterFeature(feature)) {
|
|
118
|
-
const clusterId = Number(feature.properties?.cluster_id);
|
|
119
|
-
const coords =
|
|
120
|
-
feature.geometry.type === "Point"
|
|
121
|
-
? (feature.geometry.coordinates as [number, number])
|
|
122
|
-
: event.nativeEvent.lngLat;
|
|
123
|
-
try {
|
|
124
|
-
const expansion =
|
|
125
|
-
Number.isFinite(clusterId)
|
|
126
|
-
? await sourceRef.current?.getClusterExpansionZoom(clusterId)
|
|
127
|
-
: undefined;
|
|
128
|
-
const zoom = Math.min(
|
|
129
|
-
ZOOM_MAX,
|
|
130
|
-
typeof expansion === "number" && Number.isFinite(expansion)
|
|
131
|
-
? expansion
|
|
132
|
-
: 14,
|
|
133
|
-
);
|
|
134
|
-
cameraRef.current?.easeTo({
|
|
135
|
-
center: coords,
|
|
136
|
-
zoom,
|
|
137
|
-
duration: 400,
|
|
138
|
-
easing: "ease",
|
|
139
|
-
});
|
|
140
|
-
} catch {
|
|
141
|
-
/* ignore native cluster lookup errors */
|
|
142
|
-
}
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const id = feature.properties?.id;
|
|
147
|
-
const loc = typeof id === "string" ? locationById[id] : undefined;
|
|
148
|
-
if (loc) onSelect(loc);
|
|
149
|
-
},
|
|
150
|
-
[locationById, onSelect],
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
const selectedKey = selectedId ?? "";
|
|
154
|
-
|
|
155
|
-
return (
|
|
156
|
-
<View style={styles.container}>
|
|
157
|
-
<Map
|
|
158
|
-
style={styles.map}
|
|
159
|
-
mapStyle={MAP_STYLE}
|
|
160
|
-
onDidFinishLoadingMap={onMapLoaded}
|
|
161
|
-
>
|
|
162
|
-
<Camera
|
|
163
|
-
ref={cameraRef}
|
|
164
|
-
initialViewState={{
|
|
165
|
-
zoom: 10,
|
|
166
|
-
center: [safeCenter.lon, safeCenter.lat],
|
|
167
|
-
}}
|
|
168
|
-
minZoom={ZOOM_MIN}
|
|
169
|
-
maxZoom={ZOOM_MAX}
|
|
170
|
-
/>
|
|
171
|
-
{mapReady && validLocations.length > 0 ? (
|
|
172
|
-
<GeoJSONSource
|
|
173
|
-
id="locations"
|
|
174
|
-
ref={sourceRef}
|
|
175
|
-
data={geojson}
|
|
176
|
-
cluster
|
|
177
|
-
clusterRadius={CLUSTER_RADIUS}
|
|
178
|
-
clusterMaxZoom={CLUSTER_MAX_ZOOM}
|
|
179
|
-
onPress={onSourcePress}
|
|
180
|
-
>
|
|
181
|
-
<Layer
|
|
182
|
-
id="locations-clusters"
|
|
183
|
-
type="circle"
|
|
184
|
-
filter={["has", "point_count"]}
|
|
185
|
-
paint={{
|
|
186
|
-
"circle-color": [
|
|
187
|
-
"step",
|
|
188
|
-
["get", "point_count"],
|
|
189
|
-
"#34d399",
|
|
190
|
-
15,
|
|
191
|
-
"#10b981",
|
|
192
|
-
50,
|
|
193
|
-
"#059669",
|
|
194
|
-
],
|
|
195
|
-
"circle-radius": [
|
|
196
|
-
"step",
|
|
197
|
-
["get", "point_count"],
|
|
198
|
-
18,
|
|
199
|
-
15,
|
|
200
|
-
24,
|
|
201
|
-
50,
|
|
202
|
-
32,
|
|
203
|
-
],
|
|
204
|
-
"circle-stroke-color": "#ffffff",
|
|
205
|
-
"circle-stroke-width": 2,
|
|
206
|
-
}}
|
|
207
|
-
/>
|
|
208
|
-
<Layer
|
|
209
|
-
id="locations-cluster-count"
|
|
210
|
-
type="symbol"
|
|
211
|
-
filter={["has", "point_count"]}
|
|
212
|
-
layout={{
|
|
213
|
-
"text-field": ["get", "point_count_abbreviated"],
|
|
214
|
-
"text-font": ["Noto Sans Regular"],
|
|
215
|
-
"text-size": 12,
|
|
216
|
-
"text-allow-overlap": true,
|
|
217
|
-
}}
|
|
218
|
-
paint={{ "text-color": "#ffffff" }}
|
|
219
|
-
/>
|
|
220
|
-
<Layer
|
|
221
|
-
id="locations-points"
|
|
222
|
-
type="circle"
|
|
223
|
-
filter={["!", ["has", "point_count"]]}
|
|
224
|
-
paint={{
|
|
225
|
-
"circle-radius": [
|
|
226
|
-
"case",
|
|
227
|
-
["==", ["get", "id"], selectedKey],
|
|
228
|
-
12,
|
|
229
|
-
8,
|
|
230
|
-
],
|
|
231
|
-
"circle-color": ["get", "color"],
|
|
232
|
-
"circle-stroke-color": [
|
|
233
|
-
"case",
|
|
234
|
-
["==", ["get", "id"], selectedKey],
|
|
235
|
-
"#111827",
|
|
236
|
-
"#ffffff",
|
|
237
|
-
],
|
|
238
|
-
"circle-stroke-width": 2,
|
|
239
|
-
}}
|
|
240
|
-
/>
|
|
241
|
-
</GeoJSONSource>
|
|
242
|
-
) : null}
|
|
243
|
-
</Map>
|
|
244
|
-
</View>
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function LocationsMap(props: LocationsMapProps) {
|
|
249
|
-
return <LocationsMapShell {...props} MapCanvas={NativeMapCanvas} />;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const styles = StyleSheet.create({
|
|
253
|
-
container: {
|
|
254
|
-
flex: 1,
|
|
255
|
-
minHeight: 220,
|
|
256
|
-
},
|
|
257
|
-
map: {
|
|
258
|
-
flex: 1,
|
|
259
|
-
},
|
|
260
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
Camera,
|
|
3
|
+
GeoJSONSource,
|
|
4
|
+
Layer,
|
|
5
|
+
Map,
|
|
6
|
+
type CameraRef,
|
|
7
|
+
type GeoJSONSourceRef,
|
|
8
|
+
type PressEventWithFeatures,
|
|
9
|
+
} from "@maplibre/maplibre-react-native";
|
|
10
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
11
|
+
import { StyleSheet, View, type NativeSyntheticEvent } from "react-native";
|
|
12
|
+
import {
|
|
13
|
+
LOCATION_CATEGORY_META,
|
|
14
|
+
REUNION_CENTER,
|
|
15
|
+
isValidLatLon,
|
|
16
|
+
type LocationCategory,
|
|
17
|
+
type MapLocation,
|
|
18
|
+
} from "../../hooks/useLocations";
|
|
19
|
+
import type { LocationsMapViewProps } from "./LocationsMapView";
|
|
20
|
+
import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
|
|
21
|
+
|
|
22
|
+
export type { LocationsMapProps };
|
|
23
|
+
|
|
24
|
+
const MAP_STYLE = "https://tiles.openfreemap.org/styles/liberty";
|
|
25
|
+
const CLUSTER_RADIUS = 56;
|
|
26
|
+
const CLUSTER_MAX_ZOOM = 16;
|
|
27
|
+
const ZOOM_MIN = 8;
|
|
28
|
+
const ZOOM_MAX = 18;
|
|
29
|
+
const FIT_PADDING = { top: 48, right: 48, bottom: 48, left: 48 };
|
|
30
|
+
|
|
31
|
+
function toGeoJson(locations: MapLocation[]): GeoJSON.FeatureCollection {
|
|
32
|
+
return {
|
|
33
|
+
type: "FeatureCollection",
|
|
34
|
+
features: locations.map((loc) => ({
|
|
35
|
+
type: "Feature",
|
|
36
|
+
geometry: { type: "Point", coordinates: [loc.lon, loc.lat] },
|
|
37
|
+
properties: {
|
|
38
|
+
id: loc.id,
|
|
39
|
+
color: LOCATION_CATEGORY_META[loc.category as LocationCategory].color,
|
|
40
|
+
},
|
|
41
|
+
})),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function boundsFromLocations(locations: MapLocation[]): [number, number, number, number] | null {
|
|
46
|
+
if (locations.length === 0) return null;
|
|
47
|
+
let west = locations[0]!.lon;
|
|
48
|
+
let east = locations[0]!.lon;
|
|
49
|
+
let south = locations[0]!.lat;
|
|
50
|
+
let north = locations[0]!.lat;
|
|
51
|
+
for (const loc of locations) {
|
|
52
|
+
west = Math.min(west, loc.lon);
|
|
53
|
+
east = Math.max(east, loc.lon);
|
|
54
|
+
south = Math.min(south, loc.lat);
|
|
55
|
+
north = Math.max(north, loc.lat);
|
|
56
|
+
}
|
|
57
|
+
const pad = west === east && south === north ? 0.01 : 0;
|
|
58
|
+
return [west - pad, south - pad, east + pad, north + pad];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isClusterFeature(feature: GeoJSON.Feature): boolean {
|
|
62
|
+
const props = feature.properties ?? {};
|
|
63
|
+
return props.cluster === true || typeof props.point_count === "number";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function NativeMapCanvas({
|
|
67
|
+
locations,
|
|
68
|
+
center,
|
|
69
|
+
selectedId,
|
|
70
|
+
onSelect,
|
|
71
|
+
}: LocationsMapViewProps) {
|
|
72
|
+
const cameraRef = useRef<CameraRef>(null);
|
|
73
|
+
const sourceRef = useRef<GeoJSONSourceRef>(null);
|
|
74
|
+
const [mapReady, setMapReady] = useState(false);
|
|
75
|
+
|
|
76
|
+
const safeCenter = useMemo(() => {
|
|
77
|
+
if (isValidLatLon(center.lat, center.lon)) return center;
|
|
78
|
+
return REUNION_CENTER;
|
|
79
|
+
}, [center]);
|
|
80
|
+
|
|
81
|
+
const validLocations = useMemo(
|
|
82
|
+
() => locations.filter((loc) => isValidLatLon(loc.lat, loc.lon)),
|
|
83
|
+
[locations],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const geojson = useMemo(() => toGeoJson(validLocations), [validLocations]);
|
|
87
|
+
|
|
88
|
+
const locationById = useMemo(() => {
|
|
89
|
+
const byId: Record<string, MapLocation> = {};
|
|
90
|
+
for (const loc of validLocations) byId[loc.id] = loc;
|
|
91
|
+
return byId;
|
|
92
|
+
}, [validLocations]);
|
|
93
|
+
|
|
94
|
+
const fitToLocations = useCallback(() => {
|
|
95
|
+
const bounds = boundsFromLocations(validLocations);
|
|
96
|
+
if (!bounds) return;
|
|
97
|
+
cameraRef.current?.fitBounds(bounds, { duration: 400, padding: FIT_PADDING });
|
|
98
|
+
}, [validLocations]);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!mapReady) return;
|
|
102
|
+
fitToLocations();
|
|
103
|
+
}, [mapReady, fitToLocations]);
|
|
104
|
+
|
|
105
|
+
const onMapLoaded = useCallback(() => {
|
|
106
|
+
setMapReady(true);
|
|
107
|
+
}, []);
|
|
108
|
+
|
|
109
|
+
const onSourcePress = useCallback(
|
|
110
|
+
async (event: NativeSyntheticEvent<PressEventWithFeatures>) => {
|
|
111
|
+
if (typeof event.stopPropagation === "function") {
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
}
|
|
114
|
+
const feature = event.nativeEvent.features[0];
|
|
115
|
+
if (!feature) return;
|
|
116
|
+
|
|
117
|
+
if (isClusterFeature(feature)) {
|
|
118
|
+
const clusterId = Number(feature.properties?.cluster_id);
|
|
119
|
+
const coords =
|
|
120
|
+
feature.geometry.type === "Point"
|
|
121
|
+
? (feature.geometry.coordinates as [number, number])
|
|
122
|
+
: event.nativeEvent.lngLat;
|
|
123
|
+
try {
|
|
124
|
+
const expansion =
|
|
125
|
+
Number.isFinite(clusterId)
|
|
126
|
+
? await sourceRef.current?.getClusterExpansionZoom(clusterId)
|
|
127
|
+
: undefined;
|
|
128
|
+
const zoom = Math.min(
|
|
129
|
+
ZOOM_MAX,
|
|
130
|
+
typeof expansion === "number" && Number.isFinite(expansion)
|
|
131
|
+
? expansion
|
|
132
|
+
: 14,
|
|
133
|
+
);
|
|
134
|
+
cameraRef.current?.easeTo({
|
|
135
|
+
center: coords,
|
|
136
|
+
zoom,
|
|
137
|
+
duration: 400,
|
|
138
|
+
easing: "ease",
|
|
139
|
+
});
|
|
140
|
+
} catch {
|
|
141
|
+
/* ignore native cluster lookup errors */
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const id = feature.properties?.id;
|
|
147
|
+
const loc = typeof id === "string" ? locationById[id] : undefined;
|
|
148
|
+
if (loc) onSelect(loc);
|
|
149
|
+
},
|
|
150
|
+
[locationById, onSelect],
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const selectedKey = selectedId ?? "";
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<View style={styles.container}>
|
|
157
|
+
<Map
|
|
158
|
+
style={styles.map}
|
|
159
|
+
mapStyle={MAP_STYLE}
|
|
160
|
+
onDidFinishLoadingMap={onMapLoaded}
|
|
161
|
+
>
|
|
162
|
+
<Camera
|
|
163
|
+
ref={cameraRef}
|
|
164
|
+
initialViewState={{
|
|
165
|
+
zoom: 10,
|
|
166
|
+
center: [safeCenter.lon, safeCenter.lat],
|
|
167
|
+
}}
|
|
168
|
+
minZoom={ZOOM_MIN}
|
|
169
|
+
maxZoom={ZOOM_MAX}
|
|
170
|
+
/>
|
|
171
|
+
{mapReady && validLocations.length > 0 ? (
|
|
172
|
+
<GeoJSONSource
|
|
173
|
+
id="locations"
|
|
174
|
+
ref={sourceRef}
|
|
175
|
+
data={geojson}
|
|
176
|
+
cluster
|
|
177
|
+
clusterRadius={CLUSTER_RADIUS}
|
|
178
|
+
clusterMaxZoom={CLUSTER_MAX_ZOOM}
|
|
179
|
+
onPress={onSourcePress}
|
|
180
|
+
>
|
|
181
|
+
<Layer
|
|
182
|
+
id="locations-clusters"
|
|
183
|
+
type="circle"
|
|
184
|
+
filter={["has", "point_count"]}
|
|
185
|
+
paint={{
|
|
186
|
+
"circle-color": [
|
|
187
|
+
"step",
|
|
188
|
+
["get", "point_count"],
|
|
189
|
+
"#34d399",
|
|
190
|
+
15,
|
|
191
|
+
"#10b981",
|
|
192
|
+
50,
|
|
193
|
+
"#059669",
|
|
194
|
+
],
|
|
195
|
+
"circle-radius": [
|
|
196
|
+
"step",
|
|
197
|
+
["get", "point_count"],
|
|
198
|
+
18,
|
|
199
|
+
15,
|
|
200
|
+
24,
|
|
201
|
+
50,
|
|
202
|
+
32,
|
|
203
|
+
],
|
|
204
|
+
"circle-stroke-color": "#ffffff",
|
|
205
|
+
"circle-stroke-width": 2,
|
|
206
|
+
}}
|
|
207
|
+
/>
|
|
208
|
+
<Layer
|
|
209
|
+
id="locations-cluster-count"
|
|
210
|
+
type="symbol"
|
|
211
|
+
filter={["has", "point_count"]}
|
|
212
|
+
layout={{
|
|
213
|
+
"text-field": ["get", "point_count_abbreviated"],
|
|
214
|
+
"text-font": ["Noto Sans Regular"],
|
|
215
|
+
"text-size": 12,
|
|
216
|
+
"text-allow-overlap": true,
|
|
217
|
+
}}
|
|
218
|
+
paint={{ "text-color": "#ffffff" }}
|
|
219
|
+
/>
|
|
220
|
+
<Layer
|
|
221
|
+
id="locations-points"
|
|
222
|
+
type="circle"
|
|
223
|
+
filter={["!", ["has", "point_count"]]}
|
|
224
|
+
paint={{
|
|
225
|
+
"circle-radius": [
|
|
226
|
+
"case",
|
|
227
|
+
["==", ["get", "id"], selectedKey],
|
|
228
|
+
12,
|
|
229
|
+
8,
|
|
230
|
+
],
|
|
231
|
+
"circle-color": ["get", "color"],
|
|
232
|
+
"circle-stroke-color": [
|
|
233
|
+
"case",
|
|
234
|
+
["==", ["get", "id"], selectedKey],
|
|
235
|
+
"#111827",
|
|
236
|
+
"#ffffff",
|
|
237
|
+
],
|
|
238
|
+
"circle-stroke-width": 2,
|
|
239
|
+
}}
|
|
240
|
+
/>
|
|
241
|
+
</GeoJSONSource>
|
|
242
|
+
) : null}
|
|
243
|
+
</Map>
|
|
244
|
+
</View>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function LocationsMap(props: LocationsMapProps) {
|
|
249
|
+
return <LocationsMapShell {...props} MapCanvas={NativeMapCanvas} />;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const styles = StyleSheet.create({
|
|
253
|
+
container: {
|
|
254
|
+
flex: 1,
|
|
255
|
+
minHeight: 220,
|
|
256
|
+
},
|
|
257
|
+
map: {
|
|
258
|
+
flex: 1,
|
|
259
|
+
},
|
|
260
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
/** Explicit `.web` — Metro platform extensions were not applied for this nested import. */
|
|
3
|
-
import { LocationsMapView } from "./LocationsMapView.web";
|
|
4
|
-
import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
|
|
5
|
-
|
|
6
|
-
export type { LocationsMapProps };
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Web MapLibre canvas. Native uses `LocationsMap.native.tsx` instead of this file.
|
|
10
|
-
*/
|
|
11
|
-
export function LocationsMap(props: LocationsMapProps): ReactNode {
|
|
12
|
-
return <LocationsMapShell {...props} MapCanvas={LocationsMapView} />;
|
|
13
|
-
}
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** Explicit `.web` — Metro platform extensions were not applied for this nested import. */
|
|
3
|
+
import { LocationsMapView } from "./LocationsMapView.web";
|
|
4
|
+
import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
|
|
5
|
+
|
|
6
|
+
export type { LocationsMapProps };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Web MapLibre canvas. Native uses `LocationsMap.native.tsx` instead of this file.
|
|
10
|
+
*/
|
|
11
|
+
export function LocationsMap(props: LocationsMapProps): ReactNode {
|
|
12
|
+
return <LocationsMapShell {...props} MapCanvas={LocationsMapView} />;
|
|
13
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { LocationsMapView } from "./LocationsMapView";
|
|
3
|
-
import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
|
|
4
|
-
|
|
5
|
-
export type { LocationsMapProps };
|
|
6
|
-
|
|
7
|
-
/** Web entry: ensures MapLibre `.web` canvas (not the pin-only fallback). */
|
|
8
|
-
export function LocationsMap(props: LocationsMapProps): ReactNode {
|
|
9
|
-
return <LocationsMapShell {...props} MapCanvas={LocationsMapView} />;
|
|
10
|
-
}
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { LocationsMapView } from "./LocationsMapView";
|
|
3
|
+
import { LocationsMapShell, type LocationsMapProps } from "./LocationsMapShell";
|
|
4
|
+
|
|
5
|
+
export type { LocationsMapProps };
|
|
6
|
+
|
|
7
|
+
/** Web entry: ensures MapLibre `.web` canvas (not the pin-only fallback). */
|
|
8
|
+
export function LocationsMap(props: LocationsMapProps): ReactNode {
|
|
9
|
+
return <LocationsMapShell {...props} MapCanvas={LocationsMapView} />;
|
|
10
|
+
}
|