Fix isInside for multipolygons which are marked as polygon

This commit is contained in:
pietervdvn 2021-06-24 13:50:35 +02:00
parent 651d987386
commit 45bf08744f

View file

@ -151,27 +151,31 @@ export class GeoOperations {
const x: number = pointCoordinate[0]; const x: number = pointCoordinate[0];
const y: number = pointCoordinate[1]; 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; const xi = coori[0];
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) { const yi = coori[1];
const coori = poly[i]; const xj = coorj[0];
const coorj = poly[j]; const yj = coorj[1];
const xi = coori[0]; const intersect = ((yi > y) != (yj > y))
const yi = coori[1]; && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
const xj = coorj[0]; if (intersect) {
const yj = coorj[1]; inside = !inside;
}
const intersect = ((yi > y) != (yj > y)) }
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi); if (inside) {
if (intersect) { return true;
inside = !inside;
} }
} }
return inside; return false;
}; };
static lengthInMeters(feature: any) { static lengthInMeters(feature: any) {