|
|
@@ -110,6 +110,30 @@ const defaultSeriesIcon = require('assets/series-default.png');
|
|
|
|
|
|
MapLibreRN.Logger.setLogLevel('error');
|
|
|
|
|
|
+const sanitizeNomadsGeoJSON = (
|
|
|
+ collection: GeoJSON.FeatureCollection
|
|
|
+): GeoJSON.FeatureCollection => {
|
|
|
+ const validFeatures = collection.features.filter((feature) => {
|
|
|
+ if (!feature || !feature.geometry || !feature.properties) return false;
|
|
|
+
|
|
|
+ const geom = feature.geometry;
|
|
|
+ if (geom.type !== 'Point') return false;
|
|
|
+
|
|
|
+ const coords = (geom as GeoJSON.Point).coordinates;
|
|
|
+ if (!Array.isArray(coords) || coords.length < 2) return false;
|
|
|
+
|
|
|
+ const [lng, lat] = coords;
|
|
|
+ if (lng == null || lat == null) return false;
|
|
|
+ if (typeof lng !== 'number' || typeof lat !== 'number') return false;
|
|
|
+ if (isNaN(lng) || isNaN(lat)) return false;
|
|
|
+ if (lng < -180 || lng > 180 || lat < -90 || lat > 90) return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ return { type: 'FeatureCollection', features: validFeatures };
|
|
|
+};
|
|
|
+
|
|
|
const generateFilter = (ids: number[]) => {
|
|
|
return ids?.length ? ['any', ...ids.map((id) => ['==', 'id', id])] : ['==', 'id', -1];
|
|
|
};
|
|
|
@@ -470,12 +494,13 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (usersLocation && usersLocation.geojson && showNomads) {
|
|
|
- const filteredNomads: GeoJSON.FeatureCollection = {
|
|
|
+ const rawFiltered: GeoJSON.FeatureCollection = {
|
|
|
type: 'FeatureCollection',
|
|
|
features: usersLocation.geojson.features.filter(
|
|
|
(feature: GeoJSON.Feature) => feature.properties?.id !== +userId
|
|
|
)
|
|
|
};
|
|
|
+ const filteredNomads = sanitizeNomadsGeoJSON(rawFiltered);
|
|
|
|
|
|
if (!nomads || JSON.stringify(filteredNomads) !== JSON.stringify(nomads)) {
|
|
|
setNomads(filteredNomads);
|
|
|
@@ -612,7 +637,7 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
setNomadsFilter({
|
|
|
friends: filterSettings.nomadsFilter ? filterSettings.nomadsFilter.friends : 0,
|
|
|
trusted: filterSettings.nomadsFilter ? filterSettings.nomadsFilter.trusted : 0,
|
|
|
- countries: filterSettings.nomadsFilter ? filterSettings.nomadsFilter.countries : undefined
|
|
|
+ countries: filterSettings.nomadsFilter?.countries ?? []
|
|
|
});
|
|
|
setSeriesFilter(filterSettings.seriesFilter);
|
|
|
}
|
|
|
@@ -720,12 +745,13 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
onSuccess: (data) => {
|
|
|
if (data && data?.geojson) {
|
|
|
setUsersCount(data.geojson.features?.length);
|
|
|
- const filteredNomads: GeoJSON.FeatureCollection = {
|
|
|
+ const rawFiltered: GeoJSON.FeatureCollection = {
|
|
|
type: 'FeatureCollection',
|
|
|
features: data.geojson.features.filter(
|
|
|
(feature: GeoJSON.Feature) => feature.properties?.id !== +userId
|
|
|
)
|
|
|
};
|
|
|
+ const filteredNomads = sanitizeNomadsGeoJSON(rawFiltered);
|
|
|
|
|
|
if (!nomads || JSON.stringify(filteredNomads) !== JSON.stringify(nomads)) {
|
|
|
setNomads(filteredNomads);
|
|
|
@@ -788,8 +814,14 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
]);
|
|
|
}
|
|
|
} else {
|
|
|
- setSeriesVisitedFilter(['any', ...seriesVisited.map((id) => ['==', 'id', id])]);
|
|
|
- setSeriesNotVisitedFilter(['all', ...seriesVisited.map((id) => ['!=', 'id', id])]);
|
|
|
+ setSeriesVisitedFilter(
|
|
|
+ seriesVisited.length
|
|
|
+ ? ['any', ...seriesVisited.map((id) => ['==', 'id', id])]
|
|
|
+ : generateFilter([])
|
|
|
+ );
|
|
|
+ setSeriesNotVisitedFilter(
|
|
|
+ seriesVisited.length ? ['all', ...seriesVisited.map((id) => ['!=', 'id', id])] : ['all']
|
|
|
+ );
|
|
|
}
|
|
|
}, [seriesVisited, seriesFilter]);
|
|
|
|
|
|
@@ -1586,6 +1618,7 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
no_visited: f.properties.no_visited
|
|
|
};
|
|
|
})
|
|
|
+ .filter(Boolean)
|
|
|
.sort((a: any, b: any) => a.visited - b.visited);
|
|
|
|
|
|
SheetManager.show('multiple-series-modal', {
|