|
|
@@ -64,6 +64,9 @@ import { useRegion } from 'src/contexts/RegionContext';
|
|
|
import { useGetListDareQuery } from '@api/myDARE';
|
|
|
import { useConnection } from 'src/contexts/ConnectionContext';
|
|
|
import RegionPopup from 'src/components/RegionPopup';
|
|
|
+import { point } from '@turf/turf';
|
|
|
+import { booleanPointInPolygon } from '@turf/turf';
|
|
|
+import { area } from '@turf/turf';
|
|
|
const defaultUserAvatar = require('assets/icon-user-share-location-solid.png');
|
|
|
|
|
|
const generateFilter = (ids: number[]) => {
|
|
|
@@ -644,6 +647,7 @@ const UsersMapScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
if (type === 'blank') return;
|
|
|
try {
|
|
|
const { screenPointX, screenPointY } = event.properties;
|
|
|
+ const [lng, lat] = event.geometry?.coordinates;
|
|
|
|
|
|
const { features } = await mapRef.current.queryRenderedFeaturesAtPoint(
|
|
|
[screenPointX, screenPointY],
|
|
|
@@ -652,7 +656,28 @@ const UsersMapScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
);
|
|
|
|
|
|
if (features?.length) {
|
|
|
- const region = features[0];
|
|
|
+ let region = features[0];
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (typeof lng === 'number' && typeof lat === 'number') {
|
|
|
+ const p = point([lng, lat]);
|
|
|
+
|
|
|
+ const inside = features
|
|
|
+ .filter(
|
|
|
+ (f) => f?.geometry?.type === 'Polygon' || f?.geometry?.type === 'MultiPolygon'
|
|
|
+ )
|
|
|
+ .filter((f) => booleanPointInPolygon(p, f as any));
|
|
|
+
|
|
|
+ const best = inside.slice().sort((a, b) => area(a as any) - area(b as any))[0];
|
|
|
+
|
|
|
+ if (best) {
|
|
|
+ region = best;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('region detection failed', e);
|
|
|
+ }
|
|
|
+
|
|
|
if (selectedRegion === region.properties?.id) return;
|
|
|
|
|
|
let db = type === 'regions' ? db1 : type === 'countries' ? db3 : db2;
|