Skip to content

Commit

Permalink
Merge pull request #2 from TurtIeSocks/add-mount-cbs
Browse files Browse the repository at this point in the history
Add mount cbs
  • Loading branch information
TurtIeSocks authored Aug 29, 2022
2 parents 5b66474 + 3a4900c commit 93ac7b4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ interface GeomanProps extends GeomanHandlers {
pathOptions?: L.PathOptions // See Leaflet PathOptions link above
eventDebugFn?: EventDebugFn // optional function that can be used to debug events, such as `console.log`
lang?: string // See lang options link above
onMount?: () => void // callback that runs after it mounts to the DOM
onUnmount?: () => void // callback that runs after it unmounts
}
```

Expand Down
2 changes: 2 additions & 0 deletions example/Geoman.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export default function Geoman({ geojson, setGeojson }: Props) {
continueDrawing: true,
editable: false,
}}
// onMount={() => L.PM.setOptIn(true)}
// onUnmount={() => L.PM.setOptIn(false)}
eventDebugFn={console.log}
onCreate={handleChange}
onChange={handleChange}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-leaflet-geoman-v2",
"version": "0.2.0",
"version": "0.2.1",
"description": "React wrapper for the leaflet-geoman plugin",
"repository": "https://github.com/TurtIeSocks/react-leaflet-geoman",
"author": "TurtIeSocks <58572875+TurtIeSocks@users.noreply.github.com>",
Expand Down
4 changes: 4 additions & 0 deletions src/GeomanControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default function GeomanControls({
pathOptions = {},
lang = 'en',
eventDebugFn,
onMount,
onUnmount,
...handlers
}: GeomanProps): null {
const [mounted, setMounted] = useState(false)
Expand All @@ -40,10 +42,12 @@ export default function GeomanControls({
...globalOptions,
})
map.pm.setLang(lang)
if (onMount) onMount()
setMounted(true)
}
return () => {
map.pm.removeControls()
if (onUnmount) onUnmount()
setMounted(false)
}
}, [options, globalOptions, pathOptions, lang, !map])
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export interface GeomanProps extends GeomanHandlers {
globalOptions?: PM.GlobalOptions
pathOptions?: PathOptions
eventDebugFn?: EventDebugFn
onMount?: () => void
onUnmount?: () => void
lang?:
| 'cz'
| 'da'
Expand Down

0 comments on commit 93ac7b4

Please sign in to comment.