I have some code by which I am checking places or coordinates inside in polygons or not. The problem is it may have 10000 places or more which is getting performance issue and map is getting slow. Please find my code below:
places.forEach(p => {
this.isInsidePolygons(p.latitude, p.longitude)
})
isInsidePolygons(latitude: number, longitude: number): boolean {
let isInsidePolygon = false;
var coordinate = OlHelper.transformToEPSG3857([Number(longitude), Number(latitude)]);
var shapes = this.getShapes();
for (let i = 0; i < shapes.length; i++) {
let features = shapes[i].getSource().getFeatures();
if (!features || features.length == 0) continue;
for (let j = 0; j < features.length; j++) {
var geometry = features[j].getGeometry();
isInsidePolygon = geometry.intersectsCoordinate(coordinate);
if (isInsidePolygon) break;
}
if (isInsidePolygon) break;
}
return isInsidePolygon;
}
getShapes(): ol.layer.Vector[] {
var shapes = [];
this.MapControl.getLayers().forEach((layer) => {
if (layer instanceof ol.layer.Vector) shapes.push(layer);
});
return shapes;
}
Is it possible to check all places are inside polygons in openlayers in a single check instead of looping for each one?