import * as turf from '@turf/turf'; import { Feature } from '@turf/turf'; interface RegionData { type?: string; name?: string; crs?: { type: string; properties: { name: string; }; }; features?: any; } export const findRegionInDataset = (dataset: RegionData, point: turf.helpers.Position | turf.helpers.Point | turf.helpers.Feature): Feature | undefined => { return dataset.features.find((region: any) => { const coordinates = region?.geometry?.coordinates; const type = region?.geometry?.type; if (!Array.isArray(coordinates) || coordinates.length === 0) { return false; } try { const polygon: any = type === 'Polygon' ? turf.polygon(coordinates) : turf.multiPolygon(coordinates); return turf.booleanPointInPolygon(point, polygon); } catch (error) { console.error('Error creating polygon:', error); return false; } }); }; export const calculateMapRegion = (bounds: turf.BBox): any => { const padding = 1; return { latitude: (bounds[1] + bounds[3]) / 2, longitude: (bounds[0] + bounds[2]) / 2, latitudeDelta: Math.abs(bounds[3] - bounds[1]) + padding, longitudeDelta: Math.abs(bounds[2] - bounds[0]) + padding, }; };