Fix bugs with intersectionWith

This commit is contained in:
Pieter Vander Vennet 2021-12-22 00:43:00 +01:00
parent 741564471c
commit 7ca7612960

View file

@ -14,7 +14,7 @@ export interface ExtraFuncParams {
*/ */
getFeaturesWithin: (layerId: string, bbox: BBox) => any[][], getFeaturesWithin: (layerId: string, bbox: BBox) => any[][],
memberships: RelationsTracker memberships: RelationsTracker
getFeatureById: (id:string) => any getFeatureById: (id: string) => any
} }
/** /**
@ -80,11 +80,12 @@ class IntersectionFunc implements ExtraFunction {
_f(params: ExtraFuncParams, feat) { _f(params: ExtraFuncParams, feat) {
return (...layerIds: string[]) => { return (...layerIds: string[]) => {
const result: { feat: any, intersections: [number,number][] }[] = [] const result: { feat: any, intersections: [number, number][] }[] = []
const bbox = BBox.get(feat) const bbox = BBox.get(feat)
for (const layerId of layerIds) { for (const layerId of layerIds) {
console.log("Calculating the intersection with layer ", layerId)
const otherLayers = params.getFeaturesWithin(layerId, bbox) const otherLayers = params.getFeaturesWithin(layerId, bbox)
if (otherLayers === undefined) { if (otherLayers === undefined) {
continue; continue;
@ -96,7 +97,10 @@ class IntersectionFunc implements ExtraFunction {
for (const otherFeature of tile) { for (const otherFeature of tile) {
const intersections = GeoOperations.LineIntersections(feat, otherFeature) const intersections = GeoOperations.LineIntersections(feat, otherFeature)
result.push({feat, intersections}) if(intersections.length === 0){
continue
}
result.push({feat: otherFeature, intersections})
} }
} }
} }
@ -332,6 +336,7 @@ class GetParsed implements ExtraFunction {
_name = "get" _name = "get"
_doc = "Gets the property of the feature, parses it (as JSON) and returns it. Might return 'undefined' if not defined, null, ..." _doc = "Gets the property of the feature, parses it (as JSON) and returns it. Might return 'undefined' if not defined, null, ..."
_args = ["key"] _args = ["key"]
_f(params, feat) { _f(params, feat) {
return key => { return key => {
const value = feat.properties[key] const value = feat.properties[key]