chore: use editable-edited event to sync changes

This is more unified between markers and paths, and it allows paths to
be synced as soon as they have been drawn (instead of when closing the
edit panel, which created a race condition when changing its properties
that were then synced to other while the feature itself was not).
This commit is contained in:
Yohan Boniface 2025-02-04 16:32:45 +01:00
parent cc2f4ef81f
commit 79352d8a82
2 changed files with 4 additions and 5 deletions

View file

@ -47,6 +47,7 @@ const FeatureMixin = {
addInteractions: function () { addInteractions: function () {
this.on('contextmenu editable:vertex:contextmenu', this.onContextMenu) this.on('contextmenu editable:vertex:contextmenu', this.onContextMenu)
this.on('click', this.onClick) this.on('click', this.onClick)
this.on('editable:edited', this.onCommit)
}, },
onClick: function (event) { onClick: function (event) {
@ -120,7 +121,6 @@ const PointMixin = {
this.feature.edit(event) this.feature.edit(event)
this.feature.pullGeometry() this.feature.pullGeometry()
}) })
this.on('editable:drawing:commit', this.onCommit)
if (!this.feature.isReadOnly()) this.on('mouseover', this._enableDragging) if (!this.feature.isReadOnly()) this.on('mouseover', this._enableDragging)
this.on('mouseout', this._onMouseOut) this.on('mouseout', this._onMouseOut)
}, },
@ -285,7 +285,6 @@ const PathMixin = {
addInteractions: function () { addInteractions: function () {
FeatureMixin.addInteractions.call(this) FeatureMixin.addInteractions.call(this)
this.on('editable:disable', this.onCommit)
this.on('mouseover', this._onMouseOver) this.on('mouseover', this._onMouseOver)
this.on('drag editable:drag', this._onDrag) this.on('drag editable:drag', this._onDrag)
this.on('popupopen', this.highlightPath) this.on('popupopen', this.highlightPath)

View file

@ -124,11 +124,11 @@ def test_websocket_connection_can_sync_polygons(context, asgi_live_server, tilel
map.click(position={"x": 100, "y": 100}) map.click(position={"x": 100, "y": 100})
map.click(position={"x": 100, "y": 100}) map.click(position={"x": 100, "y": 100})
# It is created on peerA, but not yet synced # It is created on peerA, and should be on peerB
expect(a_polygons).to_have_count(1) expect(a_polygons).to_have_count(1)
expect(b_polygons).to_have_count(0) expect(b_polygons).to_have_count(1)
# Escaping the edition syncs # Escaping the edition should not duplicate
peerA.keyboard.press("Escape") peerA.keyboard.press("Escape")
expect(a_polygons).to_have_count(1) expect(a_polygons).to_have_count(1)
expect(b_polygons).to_have_count(1) expect(b_polygons).to_have_count(1)