Skip to content

Commit fbf7b24

Browse files
authored
Merge pull request #3322 from azrv/develop
Add `onEdit` to Polygon
2 parents b768d0a + 70d8c38 commit fbf7b24

File tree

1 file changed

+15
-0
lines changed
  • packages/react-google-maps-api/src/components/drawing

1 file changed

+15
-0
lines changed

packages/react-google-maps-api/src/components/drawing/Polygon.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export interface PolygonProps {
113113
onLoad?: ((polygon: google.maps.Polygon) => void) | undefined
114114
/** This callback is called when the component unmounts. It is called with the polygon instance. */
115115
onUnmount?: ((polygon: google.maps.Polygon) => void) | undefined
116+
/** This callback is called when the components editing is finished */
117+
onEdit?: ((polygon: google.maps.Polygon) => void) | undefined
116118
}
117119

118120
function PolygonFunctional({
@@ -135,6 +137,7 @@ function PolygonFunctional({
135137
onDrag,
136138
onLoad,
137139
onUnmount,
140+
onEdit,
138141
}: PolygonProps): null {
139142
const map = useContext<google.maps.Map | null>(MapContext)
140143

@@ -207,6 +210,18 @@ function PolygonFunctional({
207210
}
208211
}, [onDblClick])
209212

213+
useEffect(() => {
214+
if (instance) {
215+
google.maps.event.addListener(instance.getPath(), 'insert_at', () => {
216+
onEdit?.(instance)
217+
});
218+
219+
google.maps.event.addListener(instance.getPath(), 'set_at', () => {
220+
onEdit?.(instance)
221+
});
222+
}
223+
}, [instance, onEdit])
224+
210225
useEffect(() => {
211226
if (instance && onDragEnd) {
212227
if (dragendListener !== null) {

0 commit comments

Comments
 (0)