Skip to content

Commit

Permalink
add missing example configuration for diplan prod
Browse files Browse the repository at this point in the history
  • Loading branch information
warm-coolguy committed Feb 28, 2025
1 parent 121e789 commit d771cad
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 58 deletions.
11 changes: 11 additions & 0 deletions packages/clients/diplan/example/dev/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ export default {
extent: [
248651.73157077, 5227198.20287631, 928366.12236557, 6118661.62507136,
],
diplan: {
mergeToMultiGeometries: true,
validateGeoJson: true,
metaServices: [
{
id: flurstuecke,
propertyNames: ['land', 'gemarkung', 'regbezirk', 'kreis', 'gemeinde'],
aggregationMode: 'unequal',
},
],
},
locales: [
{
type: 'de',
Expand Down
15 changes: 0 additions & 15 deletions packages/clients/diplan/example/polar-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,6 @@ <h2>Informationen aus Kartenklient</h2>
<td id="subscribed-draw">uninitialized</td>
<td>Die hergestellte Zeichnung als GeoJSON (ohne diplanspezifische Metainformationen und Modifikationen).</td>
</tr>
<tr>
<td><code>plugin/...</code></td>
<td id="subscribed-a">uninitialized</td>
<td>Platz für weitere Beispiele</td>
</tr>
<tr>
<td><code>plugin/...</code></td>
<td id="subscribed-b">uninitialized</td>
<td>Platz für weitere Beispiele</td>
</tr>
<tr>
<td><code>plugin/...</code></td>
<td id="subscribed-c">uninitialized</td>
<td>Platz für weitere Beispiele</td>
</tr>
</tbody>
</table>
</section>
Expand Down
30 changes: 28 additions & 2 deletions packages/clients/diplan/example/polar-ui/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export default (client, layerConf, config) => {
* https://dataport.github.io/polar/docs/diplan/client-diplan.html
*/

// TODO expand example bindings

const actionPlus = document.getElementById('action-plus')
const actionMinus = document.getElementById('action-minus')
const actionToast = document.getElementById('action-toast')
Expand Down Expand Up @@ -100,6 +98,15 @@ export default (client, layerConf, config) => {
actionLasso.onclick = () =>
mapInstance.$store.dispatch('plugin/draw/setMode', 'lasso')

const htmlRevisedDrawExport = document.getElementById(
'subscribed-revised-draw-export'
)
const htmlRevisionInProgress = document.getElementById(
'subscribed-revision-in-progress'
)
const htmlSimpleGeometryValidity = document.getElementById(
'subscribed-simple-geometry-validity'
)
const htmlZoom = document.getElementById('subscribed-zoom')
const htmlGfi = document.getElementById('subscribed-gfi')
const htmlExportA = document.getElementById('subscribed-export-a')
Expand Down Expand Up @@ -128,6 +135,25 @@ export default (client, layerConf, config) => {
mapInstance.subscribe('plugin/draw/featureCollection', (geojson) => {
htmlDraw.innerHTML = JSON.stringify(geojson, null, 2)
})
mapInstance.subscribe('diplan/revisedDrawExport', (revisedDrawExport) => {
htmlRevisedDrawExport.innerHTML = JSON.stringify(
revisedDrawExport,
null,
2
)
})
mapInstance.subscribe(
'diplan/revisionInProgress',
(revisionInProgress) => {
htmlRevisionInProgress.innerHTML = revisionInProgress
}
)
mapInstance.subscribe(
'diplan/simpleGeometryValidity',
(simpleGeometryValidity) => {
htmlSimpleGeometryValidity.innerHTML = simpleGeometryValidity
}
)

window.mapInstance = mapInstance
})
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/diplan/src/store/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const diplanModule: PolarModule<DiplanState, DiplanGetters> = {

if (getters.configuration.metaServices.length) {
try {
await enrichWithMetaServices(
revisedFeatureCollection.features = await enrichWithMetaServices(
revisedFeatureCollection,
rootGetters.map,
getters.configuration.metaServices,
Expand Down
83 changes: 43 additions & 40 deletions packages/clients/diplan/src/store/utils/enrichWithMetaServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@polar/lib-get-features'
import { rawLayerList } from '@masterportal/masterportalapi'
import { booleanIntersects } from '@turf/boolean-intersects'
import { MetaService } from '../../types'
import { GeometryType, MetaService } from '../../types'

const reader = new GeoJSON()

Expand Down Expand Up @@ -58,48 +58,51 @@ const aggregateProperties = (

/** @throws */
export const enrichWithMetaServices = (
featureCollection: FeatureCollection,
featureCollection: FeatureCollection<GeometryType>,
map: Map,
metaServices: MetaService[],
signal: AbortSignal
) =>
): Promise<GeoJsonFeature<GeometryType>[]> =>
Promise.all(
featureCollection.features.map((feature) =>
Promise.all(
metaServices.map(({ id, propertyNames, aggregationMode }) =>
getVectorFeaturesByFeatureRequest({
feature: reader.readFeature(JSON.stringify(feature)) as Feature,
fetchLayerId: id,
projectionCode: map.getView().getProjection().getCode(),
signal,
})
.then((response) =>
rawLayerList.getLayerWhere({ id }).typ === 'WFS'
? parseWfsResponse(response, undefined, false)
: (response.json() as Promise<FeatureCollection>)
)
.then((featuresFromBbox) => {
const applicableProperties = featuresFromBbox.features
.filter((featureFromBbox) =>
booleanIntersects(featureFromBbox, feature)
)
.map(({ properties }) => properties)

const aggregatedProperties = aggregateProperties(
applicableProperties,
propertyNames,
aggregationMode
featureCollection.features.map(async (feature) => ({
...feature,
properties: {
...feature.properties,
metaProperties: {
...(feature.properties?.metaProperties || {}),
...Object.fromEntries(
await Promise.all(
metaServices.map(({ id, propertyNames, aggregationMode }) =>
getVectorFeaturesByFeatureRequest({
feature: reader.readFeature(
JSON.stringify(feature)
) as unknown as Feature,
fetchLayerId: id,
projectionCode: map.getView().getProjection().getCode(),
signal,
})
.then((response) =>
rawLayerList.getLayerWhere({ id }).typ === 'WFS'
? parseWfsResponse(response, undefined, false)
: (response.json() as Promise<FeatureCollection>)
)
.then((featuresFromBbox) => {
const applicableProperties = featuresFromBbox.features
.filter((featureFromBbox) =>
booleanIntersects(featureFromBbox, feature)
)
.map(({ properties }) => properties)
const aggregatedProperties = aggregateProperties(
applicableProperties,
propertyNames,
aggregationMode
)
return [id, aggregatedProperties]
})
)

feature.properties = {
...feature.properties,
metaProperties: {
...(feature.properties?.metaProperties || {}),
[id]: aggregatedProperties,
},
}
})
)
)
)
)
),
},
},
}))
)

0 comments on commit d771cad

Please sign in to comment.