Description
When using TerraDrawPolygonMode with TerraDrawGoogleMapsAdapter, the first click after completing a polygon (via double-click) is sometimes not registered. The user has to click twice to start drawing the next polygon.
This issue is intermittent - sometimes the first click works, sometimes it doesn't. The same behavior occurs on the first click after activating polygon mode.
Environment
- terra-draw: 1.19.0
- terra-draw-google-maps-adapter: 1.1.0
- @vis.gl/react-google-maps (React wrapper)
- Tested on:
- macOS + Safari ✓ (issue present)
- Windows + Chrome ✓ (issue present)
Steps to Reproduce
- Initialize TerraDraw with Google Maps adapter and polygon mode
- Wait for
ready event before setting mode (as per docs)
- Set mode to
polygon
- Draw a polygon and complete it with double-click
- Immediately try to start drawing another polygon by clicking on the map
- First click is sometimes ignored - polygon doesn't start drawing
- Second click works and starts the new polygon
Expected Behavior
Every click after completing a polygon should register and start drawing a new polygon (when in polygon mode).
Actual Behavior
First click after completing a polygon (or after activating polygon mode) is sometimes ignored. The mode state shows started instead of transitioning to drawing.
Debug Information
Console logs show:
[PolygonTool] finish event, polygon completed
[PolygonTool] Mode state after finish: started
[PolygonTool] MAP CLICK - mode: polygon state: started ← Click registered by Google Maps but not processed by Terra Draw
[PolygonTool] MAP CLICK - mode: polygon state: drawing ← Second click works
The Google Maps click event fires, but Terra Draw doesn't process it. The getModeState() remains started instead of changing to drawing.
Minimal Reproduction Code
const draw = new TerraDraw({
adapter: new TerraDrawGoogleMapsAdapter({
map,
lib: google.maps,
coordinatePrecision: 9
}),
modes: [
new TerraDrawPolygonMode({
pointerDistance: 20,
})
]
});
draw.start();
draw.on('ready', () => {
draw.setMode('polygon');
});
draw.on('finish', (id) => {
console.log('Polygon finished, state:', draw.getModeState());
// State is 'started', ready for next polygon
// But first click is sometimes ignored
});
Possible Cause
The issue might be related to:
1. Timing between double-click finish event and next single click
2. Internal state not fully reset after polygon completion
3. Event handling conflict between OverlayView and Google Maps click events
Workaround Attempts
- Tried calling setMode('select') then setMode('polygon') after finish - didn't help
- Tried increasing timeout before mode reset - didn't help
- Issue persists regardless of time waited between polygon completion and next click
Description
When using
TerraDrawPolygonModewithTerraDrawGoogleMapsAdapter, the first click after completing a polygon (via double-click) is sometimes not registered. The user has to click twice to start drawing the next polygon.This issue is intermittent - sometimes the first click works, sometimes it doesn't. The same behavior occurs on the first click after activating polygon mode.
Environment
Steps to Reproduce
readyevent before setting mode (as per docs)polygonExpected Behavior
Every click after completing a polygon should register and start drawing a new polygon (when in polygon mode).
Actual Behavior
First click after completing a polygon (or after activating polygon mode) is sometimes ignored. The mode state shows
startedinstead of transitioning todrawing.Debug Information
Console logs show:
[PolygonTool] finish event, polygon completed
[PolygonTool] Mode state after finish: started
[PolygonTool] MAP CLICK - mode: polygon state: started ← Click registered by Google Maps but not processed by Terra Draw
[PolygonTool] MAP CLICK - mode: polygon state: drawing ← Second click works
The Google Maps
clickevent fires, but Terra Draw doesn't process it. ThegetModeState()remainsstartedinstead of changing todrawing.Minimal Reproduction Code