-
Notifications
You must be signed in to change notification settings - Fork 2
/
tpopIdsInsideFeatureCollection.js
58 lines (55 loc) · 1.54 KB
/
tpopIdsInsideFeatureCollection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// @flow
import within from '@turf/within'
import isFinite from 'lodash/isFinite'
import epsg21781to4326 from './epsg21781to4326notReverse'
export default (store: Object, tpops: Array<Object>): Array<number> => {
/**
* data is passed from map.pop.pops OR a view fetched from the server
* so need to filter to data with coordinates first...
*/
let tpopsToUse = tpops.filter(p => {
if (!p.TPopId) return false
if (
p.TPopXKoord &&
isFinite(p.TPopXKoord) &&
p.TPopYKoord &&
isFinite(p.TPopYKoord)
)
return true
if (
p['TPop X-Koordinaten'] &&
isFinite(p['TPop X-Koordinaten']) &&
p['TPop Y-Koordinaten'] &&
isFinite(p['TPop Y-Koordinaten'])
)
return true
return false
})
// ...and account for user friendly field names in views
tpopsToUse = tpopsToUse.map(p => {
if (p['TPop X-Koordinaten'] && p['TPop Y-Koordinaten']) {
p.TPopXKoord = p['TPop X-Koordinaten']
p.TPopYKoord = p['TPop Y-Koordinaten']
}
return p
})
// build an array of geoJson points
const features = tpopsToUse.map(t => ({
type: 'Feature',
properties: {
TPopId: t.TPopId,
},
geometry: {
type: 'Point',
// convert koordinates to wgs84
coordinates: epsg21781to4326(t.TPopXKoord, t.TPopYKoord),
},
}))
const points = {
type: 'FeatureCollection',
features,
}
// let turf check what points are within filter
const result = within(points, store.map.mapFilter.filter)
return result.features.map(r => r.properties.TPopId)
}