Skip to content

[Bug] First click after finishing polygon not registering (Google Maps adapter) #720

@oliveres

Description

@oliveres

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

  1. Initialize TerraDraw with Google Maps adapter and polygon mode
  2. Wait for ready event before setting mode (as per docs)
  3. Set mode to polygon
  4. Draw a polygon and complete it with double-click
  5. Immediately try to start drawing another polygon by clicking on the map
  6. First click is sometimes ignored - polygon doesn't start drawing
  7. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Google Maps JS APIRelated to the Google Maps AdapterbugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions