Skip to content

Commit

Permalink
add snap operations, add function outline
Browse files Browse the repository at this point in the history
  • Loading branch information
warm-coolguy committed Feb 28, 2025
1 parent e1575a2 commit d232c50
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions packages/clients/diplan/src/store/geoEditing/cutPolygons.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
import { PolarActionContext } from '@polar/lib-custom-types'
import Draw from 'ol/interaction/Draw'
import { getSnaps } from '@polar/plugin-draw'
import Snap from 'ol/interaction/Snap'
import VectorSource from 'ol/source/Vector'
import Feature from 'ol/Feature'
import { DiplanGetters, DiplanState } from '../../types'

export const cutPolygons = ({
dispatch,
rootGetters,
}: PolarActionContext<DiplanState, DiplanGetters>) => {
dispatch('plugin/draw/setMode', 'none', { root: true })

const draw = new Draw({ type: 'LineString' })
const drawSource: VectorSource = rootGetters['plugin/draw/drawSource']

// TODO draw.on drawend → get draw source, modify polygons
const draw = new Draw({ type: 'LineString' })

// TODO get Snap interactions
draw.on('drawend', (e) => {
const cutLine = e.feature
const features = drawSource.getFeatures()
const nextFeatures = features.reduce((accumulator, feature) => {
// TODO cut feature with line if it's a polygon, add multiple features thereafter
console.error(cutLine)
accumulator.push(feature)
return accumulator
}, [] as Feature[])
drawSource.clear()
drawSource.addFeatures(nextFeatures)
})

dispatch('plugin/draw/setInteractions', [draw], { root: true })
dispatch(
'plugin/draw/setInteractions',
[
draw,
...getSnaps(
rootGetters.map,
rootGetters.configuration?.draw?.snapTo || []
),
new Snap({ source: drawSource }),
],
{ root: true }
)
}

0 comments on commit d232c50

Please sign in to comment.