fix: draggable pin writeback and click-to-place event collision
Three related bugs in the maplibre reactive signal plumbing: 1. Draggable marker coordinates never updated because dragendHandlerJS queries for hidden inputs matching LngSignal/LatSignal IDs, but Element() never rendered those inputs. Add them after the marker data-effect divs. 2. Click-to-place marker didn't appear until moveend because Element() rendered a bare hidden input for each event signal, colliding with the user's action-bearing input (same data-bind, querySelector finds the bare one first). Remove the internal event inputs — the user provides their own via MapEvent.Input(). 3. The moveend handler dispatched 'input' on ALL data-bind inputs in the wrapper, accidentally triggering event inputs. Add an else-return so only the 5 viewport signal inputs get dispatched.
This commit is contained in:
@@ -140,6 +140,7 @@ func initScript(m *Map) string {
|
||||
`else if(sig===%[4]s)inp.value=map.getZoom();`+
|
||||
`else if(sig===%[5]s)inp.value=map.getBearing();`+
|
||||
`else if(sig===%[6]s)inp.value=map.getPitch();`+
|
||||
`else return;`+
|
||||
`inp.dispatchEvent(new Event('input',{bubbles:true}));`+
|
||||
`});`+
|
||||
`});`,
|
||||
|
||||
@@ -122,11 +122,14 @@ func (m *Map) Element(extra ...h.H) h.H {
|
||||
}
|
||||
}
|
||||
|
||||
// Event listener binding elements
|
||||
for _, ev := range m.events {
|
||||
children = append(children,
|
||||
h.Input(h.Type("hidden"), ev.signal.Bind()),
|
||||
)
|
||||
// Hidden inputs for signal-backed marker position writeback (drag → signal)
|
||||
for _, me := range m.markers {
|
||||
if me.marker.LngSignal != nil && me.marker.LatSignal != nil {
|
||||
children = append(children,
|
||||
h.Input(h.Type("hidden"), me.marker.LngSignal.Bind()),
|
||||
h.Input(h.Type("hidden"), me.marker.LatSignal.Bind()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
children = append(children, extra...)
|
||||
|
||||
Reference in New Issue
Block a user