From 45bf08744f57f5e8747de1dbbe8780b5f0b32e82 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 24 Jun 2021 13:50:35 +0200 Subject: [PATCH] Fix isInside for multipolygons which are marked as polygon --- Logic/GeoOperations.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Logic/GeoOperations.ts b/Logic/GeoOperations.ts index 40cba5435..31cb88ad2 100644 --- a/Logic/GeoOperations.ts +++ b/Logic/GeoOperations.ts @@ -151,27 +151,31 @@ export class GeoOperations { const x: number = pointCoordinate[0]; const y: number = pointCoordinate[1]; + for (let i = 0; i < feature.geometry.coordinates.length; i++) { + let poly = feature.geometry.coordinates[i]; - let poly = feature.geometry.coordinates[0]; + let inside = false; + for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) { + const coori = poly[i]; + const coorj = poly[j]; - var inside = false; - for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) { - const coori = poly[i]; - const coorj = poly[j]; + const xi = coori[0]; + const yi = coori[1]; + const xj = coorj[0]; + const yj = coorj[1]; - const xi = coori[0]; - const yi = coori[1]; - const xj = coorj[0]; - const yj = coorj[1]; - - const intersect = ((yi > y) != (yj > y)) - && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - if (intersect) { - inside = !inside; + const intersect = ((yi > y) != (yj > y)) + && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); + if (intersect) { + inside = !inside; + } + } + if (inside) { + return true; } } - return inside; + return false; }; static lengthInMeters(feature: any) {