@hastehaul/common 2.13.0 → 2.14.0
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/build/utils/utils.d.ts +7 -1
- package/build/utils/utils.js +33 -9
- package/package.json +1 -1
package/build/utils/utils.d.ts
CHANGED
@@ -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<
|
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 {};
|
package/build/utils/utils.js
CHANGED
@@ -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
|
91
|
+
for (const feature of geojson.features) {
|
71
92
|
const geometry = feature.geometry;
|
72
93
|
if (geometry.type === 'Polygon') {
|
73
|
-
|
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
|
-
|
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
|
-
|
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
|
}
|