Skip to content

Commit 7a34d6e

Browse files
authored
Merge pull request #228 from Dataport/fix/separate-stacked-drawings
fix that drawings on top of each other were glued
2 parents e57ba87 + f42e696 commit 7a34d6e

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

packages/plugins/Draw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Feature: Add new configuration parameter `measureOptions` to allow users to select a measurement mode when drawing a feature. This way, a length / area in the selected unit is added to the drawn feature.
77
- Fix: Update initial value of `drawMode` to a selectable value if the default `Point` is not a drawable option.
88
- Fix: Adjust type `DrawGetters` regarding its keys `selectableDrawModes` and `selectableModes` to correctly reflect that they represent objects.
9+
- Fix: Stacked geometries can be separated with the "Edit" operation again. [Thanks to mike-000](https://github.com/openlayers/openlayers/issues/16593#issuecomment-2624257614).
910
- Chore: Add `@polar/core` as a dependency as the component `RadioCard.vue` has been moved from this package to `@polar/core`.
1011

1112
## 2.0.0

packages/plugins/Draw/src/store/actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ export const makeActions = () => {
130130
getters: { selectedFeature },
131131
rootGetters: { map },
132132
}) {
133-
interactions.forEach((interaction) => map.removeInteraction(interaction))
133+
interactions.forEach(
134+
(interaction) =>
135+
// @ts-expect-error | "un on removal" riding piggyback as _onRemove
136+
map.removeInteraction(interaction) && interaction._onRemove?.()
137+
)
134138
if (interactions.some((interaction) => interaction instanceof Select)) {
135139
if (selectedFeature && selectedFeature.get('text') === '') {
136140
// text nodes without text are considered deleted

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
import { Modify, Select, Snap } from 'ol/interaction'
22
import Interaction from 'ol/interaction/Interaction'
33
import { PolarActionContext } from '@polar/lib-custom-types'
4+
import { Collection, Feature, Map, MapBrowserEvent } from 'ol'
45
import { CreateInteractionsPayload, DrawGetters, DrawState } from '../../types'
56

7+
const createModify = (
8+
map: Map,
9+
drawLayer: CreateInteractionsPayload['drawLayer']
10+
) => {
11+
let active = false
12+
const features: Collection<Feature> = new Collection()
13+
const modify = new Modify({ features })
14+
modify.on('modifystart', () => {
15+
active = true
16+
})
17+
modify.on('modifyend', () => {
18+
active = false
19+
})
20+
21+
const localSelector = (e: MapBrowserEvent<UIEvent>) => {
22+
if (!active) {
23+
map.forEachFeatureAtPixel(
24+
e.pixel,
25+
(f) => {
26+
if (f !== features.item(0)) {
27+
features.setAt(0, f as Feature)
28+
}
29+
return true
30+
},
31+
{
32+
layerFilter: (l) => l === drawLayer,
33+
}
34+
)
35+
}
36+
}
37+
38+
map.on('pointermove', localSelector)
39+
// @ts-expect-error | "un on removal" riding piggyback as _onRemove
40+
modify._onRemove = () => map.un('pointermove', localSelector)
41+
42+
return modify
43+
}
44+
645
export default function (
7-
{ commit, dispatch, getters }: PolarActionContext<DrawState, DrawGetters>,
46+
{
47+
commit,
48+
dispatch,
49+
getters,
50+
rootGetters,
51+
}: PolarActionContext<DrawState, DrawGetters>,
852
{ drawSource, drawLayer }: CreateInteractionsPayload
953
): Interaction[] {
1054
const { drawMode } = getters
@@ -40,7 +84,7 @@ export default function (
4084
})
4185

4286
return [
43-
new Modify({ source: drawSource }),
87+
createModify(rootGetters.map, drawLayer),
4488
new Snap({ source: drawSource }),
4589
select,
4690
]

0 commit comments

Comments
 (0)