@@ -7,7 +7,12 @@ import { PolarActionContext } from '@polar/lib-custom-types'
7
7
import { Feature } from 'ol'
8
8
import { Polygon } from 'ol/geom'
9
9
import { parseWfsResponse } from '@polar/lib-get-features/wfs/parse'
10
- import { FeatureCollection , Feature as GeoJsonFeature } from 'geojson'
10
+ import {
11
+ FeatureCollection ,
12
+ Feature as GeoJsonFeature ,
13
+ Geometry ,
14
+ GeometryCollection ,
15
+ } from 'geojson'
11
16
import { getVectorFeaturesByFeatureRequest } from '@polar/lib-get-features'
12
17
import { DrawGetters , DrawState } from '../../types'
13
18
@@ -27,22 +32,42 @@ const internalError = () => ({
27
32
const buildAddFeaturesPayload = (
28
33
featureCollections : FeatureCollection [ ] ,
29
34
drawnLasso : Feature
30
- ) => ( {
31
- geoJSON : {
32
- type : 'FeatureCollection' ,
33
- features : featureCollections
34
- . reduce (
35
- ( accumulator , { features } ) => accumulator . concat ( features ) ,
36
- [ ] as GeoJsonFeature [ ]
37
- )
38
- . filter ( ( feature ) =>
39
- booleanContains (
40
- JSON . parse ( new GeoJSON ( ) . writeFeature ( drawnLasso ) ) ,
41
- feature
35
+ ) => {
36
+ const drawnLassoGeoJson = JSON . parse ( new GeoJSON ( ) . writeFeature ( drawnLasso ) )
37
+
38
+ console . error ( featureCollections )
39
+
40
+ return {
41
+ geoJSON : {
42
+ type : 'FeatureCollection' ,
43
+ features : featureCollections
44
+ . reduce (
45
+ ( accumulator , { features } ) => accumulator . concat ( features ) ,
46
+ [ ] as GeoJsonFeature [ ]
42
47
)
43
- ) ,
44
- } ,
45
- } )
48
+ . filter ( ( feature ) => {
49
+ if ( feature . geometry . type . startsWith ( 'Multi' ) ) {
50
+ return (
51
+ // since .type on GeometryCollection doesn't start with 'Multi'
52
+ (
53
+ feature . geometry as Exclude < Geometry , GeometryCollection >
54
+ ) . coordinates . every ( ( partialCoordinates ) =>
55
+ booleanContains ( drawnLassoGeoJson , {
56
+ type : 'Feature' ,
57
+ geometry : {
58
+ type : feature . geometry . type . slice ( 5 ) , // un«Multi»ed
59
+ coordinates : partialCoordinates ,
60
+ } ,
61
+ properties : { } ,
62
+ } )
63
+ )
64
+ )
65
+ }
66
+ return booleanContains ( drawnLassoGeoJson , feature )
67
+ } ) ,
68
+ } ,
69
+ }
70
+ }
46
71
47
72
// should be fine, surrounding method is only unpacking/packing, also see below
48
73
// eslint-disable-next-line max-lines-per-function
0 commit comments