@hastehaul/common 2.13.0 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,5 +8,11 @@ export declare function formatDatetimeToHumanReadable(datetime: Date, format?: s
8
8
  export declare function generateIdentifier(messageContent: string): string;
9
9
  export declare function getValueFromSettings(settings: Setting[], key: string, envVar?: string, defaultValue?: any): any;
10
10
  export declare function loadAsset(relativePath: string): Promise<string | null>;
11
- export declare function isPointInGeoJSON(latLng: string | any[], fileName: string): Promise<any>;
11
+ export declare function isPointInGeoJSON(latLng: string | any[], fileName: string): Promise<{
12
+ isInside: boolean;
13
+ properties: any;
14
+ } | {
15
+ isInside: null;
16
+ properties: null;
17
+ }>;
12
18
  export {};
@@ -59,29 +59,53 @@ function loadAsset(relativePath) {
59
59
  }
60
60
  });
61
61
  }
62
+ // export async function isPointInGeoJSONw(latLng: string | any[], fileName: string) {
63
+ // try {
64
+ // if(latLng.length === 0) return false
65
+ // const geoJsonData = await loadAsset(fileName);
66
+ // const geojson = JSON.parse(geoJsonData!);
67
+ // const points = point([latLng[1], latLng[0]]);
68
+ // const isInside = geojson.features.some((feature: { geometry: any; }) => {
69
+ // const geometry = feature.geometry;
70
+ // if (geometry.type === 'Polygon') {
71
+ // return booleanPointInPolygon(points, polygon(geometry.coordinates));
72
+ // } else if (geometry.type === 'MultiPolygon') {
73
+ // return geometry.coordinates.some((poly: Position[][]) => booleanPointInPolygon(points, polygon(poly)));
74
+ // }
75
+ // return false;
76
+ // });
77
+ // return isInside;
78
+ // } catch (error) {
79
+ // console.error(`Error checking point in GeoJSON: ${error}`);
80
+ // return null;
81
+ // }
82
+ // }
62
83
  function isPointInGeoJSON(latLng, fileName) {
63
84
  return __awaiter(this, void 0, void 0, function* () {
64
85
  try {
65
- if (latLng.length === 0)
66
- return false;
86
+ if (!latLng || latLng.length === 0)
87
+ return { isInside: false, properties: null };
67
88
  const geoJsonData = yield loadAsset(fileName);
68
89
  const geojson = JSON.parse(geoJsonData);
69
90
  const points = (0, helpers_1.point)([latLng[1], latLng[0]]);
70
- const isInside = geojson.features.some((feature) => {
91
+ for (const feature of geojson.features) {
71
92
  const geometry = feature.geometry;
72
93
  if (geometry.type === 'Polygon') {
73
- return (0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(geometry.coordinates));
94
+ if ((0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(geometry.coordinates))) {
95
+ return { isInside: true, properties: feature.properties };
96
+ }
74
97
  }
75
98
  else if (geometry.type === 'MultiPolygon') {
76
- return geometry.coordinates.some((poly) => (0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(poly)));
99
+ if (geometry.coordinates.some((poly) => (0, boolean_point_in_polygon_1.default)(points, (0, helpers_1.polygon)(poly)))) {
100
+ return { isInside: true, properties: feature.properties };
101
+ }
77
102
  }
78
- return false;
79
- });
80
- return isInside;
103
+ }
104
+ return { isInside: false, properties: null };
81
105
  }
82
106
  catch (error) {
83
107
  console.error(`Error checking point in GeoJSON: ${error}`);
84
- return null;
108
+ return { isInside: null, properties: null };
85
109
  }
86
110
  });
87
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",