Skip to content

Commit 00f334f

Browse files
committed
hardcode WFS support for lasso interaction (WIP)
1 parent 501ef82 commit 00f334f

File tree

2 files changed

+60
-48
lines changed

2 files changed

+60
-48
lines changed

packages/clients/diplan/example/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ export default {
102102
{
103103
id: flurstuecke,
104104
},
105+
{
106+
id: xplanwfs,
107+
},
105108
],
106109
measureOptions: {
107110
metres: true,

packages/plugins/Draw/src/store/createInteractions/createLassoInteractions.ts

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { MapConfig, PolarActionContext } from '@polar/lib-custom-types'
66
import { Dispatch } from 'vuex'
77
import { Feature, Map } from 'ol'
88
import { Polygon } from 'ol/geom'
9-
import { getWfsFeatures } from '@polar/lib-get-features'
9+
import { parseWfsResponse } from '@polar/lib-get-features/wfs/parse'
1010
import { FeatureCollection, Feature as GeoJsonFeature } from 'geojson'
11+
import VectorLayer from 'ol/layer/Vector'
12+
import VectorSource from 'ol/source/Vector'
1113
import { DrawGetters, DrawState } from '../../types'
1214

1315
const loaderKey = 'drawLasso'
@@ -63,64 +65,56 @@ const getLassoRequests = (
6365
lassoIds.reduce((accumulator, id) => {
6466
const serviceDefinition = rawLayerList.getLayerWhere({ id })
6567

66-
// TODO add WFS support
67-
// getWfsFeatures(null, serviceDefinition.url, ) FILTER-ONLY atm
68+
const source = (
69+
map
70+
.getLayers()
71+
.getArray()
72+
.find((layer) => layer.get('id') === id) as VectorLayer
73+
)?.getSource?.()
74+
if (!(source instanceof VectorSource)) {
75+
console.warn(
76+
`@polar/plugin-draw: Layer with ID "${id}" configured for 'lasso', but it has no vector source. The layer does probably not hold any vector data.`
77+
)
78+
}
6879

6980
const [codeName, codeNumber] = map
7081
.getView()
7182
.getProjection()
7283
.getCode()
7384
.split(':')
7485

75-
const url = [
76-
serviceDefinition.url,
77-
'collections',
78-
serviceDefinition.collection,
79-
`items?f=json&limit=100&bbox=${lasso
80-
.getGeometry()
81-
?.getExtent()}&bbox-crs=http://www.opengis.net/def/crs/${codeName}/0/${codeNumber}&crs=http://www.opengis.net/def/crs/${codeName}/0/${codeNumber}`,
82-
].join('/')
86+
// TODO use ol/source/Vector::getFeaturesInExtent instead? not easy to ensure data was loaded in extent
87+
88+
if (!['OAF', 'WFS'].includes(serviceDefinition.typ)) {
89+
throw new Error('AAAAAAAAAAAAAAAAAAAA')
90+
}
91+
92+
const url =
93+
serviceDefinition.typ === 'OAF'
94+
? [
95+
serviceDefinition.url,
96+
'collections',
97+
serviceDefinition.collection,
98+
`items?f=json&limit=100&bbox=${lasso
99+
.getGeometry()
100+
?.getExtent()}&bbox-crs=http://www.opengis.net/def/crs/${codeName}/0/${codeNumber}&crs=http://www.opengis.net/def/crs/${codeName}/0/${codeNumber}`,
101+
].join('/')
102+
: `${serviceDefinition.url}${[
103+
`?service=${serviceDefinition.typ}`,
104+
`version=${serviceDefinition.version}`,
105+
`request=GetFeature`,
106+
`srsName=${map.getView().getProjection().getCode()}`,
107+
`typeName=${serviceDefinition.featureType}`,
108+
`bbox=${lasso.getGeometry()?.getExtent()},${map
109+
.getView()
110+
.getProjection()
111+
.getCode()}`,
112+
].join('&')}`
83113

84114
accumulator.push(fetch(url))
85115
return accumulator
86116
}, [] as Promise<Response>[])
87117

88-
/*
89-
TODO use snippet to confirm the layer type worked on
90-
const source = (
91-
map
92-
.getLayers()
93-
.getArray()
94-
.find((layer) => layer.get('id') === layerId) as VectorLayer
95-
)?.getSource?.()
96-
if (source instanceof VectorSource) {
97-
accumulator.push(new Snap({ source }))
98-
} else {
99-
console.warn(
100-
`@polar/plugin-draw: Layer with ID "${layerId}" configured for 'snapTo', but it has no source to snap to. The layer does probably not hold any vector data.`
101-
)
102-
}
103-
*/
104-
105-
const handleSettledRequests = (
106-
resolutions: PromiseSettledResult<Response>[],
107-
dispatch: Dispatch
108-
) =>
109-
Promise.all(
110-
(
111-
resolutions.filter((promiseSettledResult) => {
112-
if (promiseSettledResult.status === 'rejected') {
113-
console.error(promiseSettledResult.reason)
114-
// TODO toast
115-
return false
116-
}
117-
return true
118-
}) as PromiseFulfilledResult<Response>[]
119-
).map(
120-
async (resolution) => (await resolution.value.json()) as FeatureCollection
121-
)
122-
)
123-
124118
const handleFulfilledRequests = (
125119
featureCollections: FeatureCollection[],
126120
dispatch: Dispatch
@@ -162,7 +156,22 @@ export default function ({
162156
}
163157
Promise.allSettled(requests)
164158
.then((settledRequests) =>
165-
handleSettledRequests(settledRequests, dispatch)
159+
Promise.all(
160+
(
161+
settledRequests.filter((promiseSettledResult) => {
162+
if (promiseSettledResult.status === 'rejected') {
163+
console.error(promiseSettledResult.reason)
164+
// TODO toast
165+
return false
166+
}
167+
return true
168+
}) as PromiseFulfilledResult<Response>[]
169+
).map(async (resolution, index) =>
170+
rawLayerList.getLayerWhere({ id: lassoIds[index] }).typ === 'WFS'
171+
? await parseWfsResponse(resolution.value, undefined, false)
172+
: ((await resolution.value.json()) as FeatureCollection)
173+
)
174+
)
166175
)
167176
.then((fulfilledRequests) =>
168177
handleFulfilledRequests(fulfilledRequests, dispatch)

0 commit comments

Comments
 (0)