-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add snap operations, add function outline
- Loading branch information
1 parent
e1575a2
commit d232c50
Showing
1 changed file
with
31 additions
and
4 deletions.
There are no files selected for viewing
35 changes: 31 additions & 4 deletions
35
packages/clients/diplan/src/store/geoEditing/cutPolygons.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
) | ||
} |