JustFly1984 / react-google-maps-api

React Google Maps API
MIT License
1.78k stars 437 forks source link

How to listen `onDragEnd` and `onClick`(extend polygon) events using `DrawingManager #3149

Closed ultimateakash closed 1 year ago

ultimateakash commented 1 year ago

Please provide an explanation of the issue

How to listen onDragEnd and onClick(extend polygon) events using DrawingManager as we have on Polygon

Your Environment

os: windows 11

node --version: 14.17.3

react version: 17.0.2

@react-google-maps/api: 2.12.0

How does it behave?

I need to edit and drag the polygon after drawing on the map. I have tried with addListener and its working

    const onOverlayComplete = ($overlayEvent) => {
        overlayRef.current = $overlayEvent.overlay;
        drawingManagerRef.current.setDrawingMode(null); 
        google.maps.event.addListener(overlayRef.current, 'dragend', handlePolygonEvents);
        google.maps.event.addListener(overlayRef.current.getPath(), 'insert_at', handlePolygonEvents);
        google.maps.event.addListener(overlayRef.current.getPath(), 'remove_at', handlePolygonEvents);
        google.maps.event.addListener(overlayRef.current.getPath(), 'set_at', handlePolygonEvents);
    }

but I have checked the documentation for DrawingManager, there is no way to handle the above events. please help. https://react-google-maps-api-docs.netlify.app/#drawingmanager