-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for drawing items in
ui.leaflet
(#3586)
* show drawn layers * avoid circular references when emitting draw events * wait a tick for more event arguments * update documentation * allow hiding drawn items * add demos for editing drawn items and drawing with custom options
- Loading branch information
1 parent
c69db4d
commit 0ad7478
Showing
4 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Remove keysToRemove, functions, and circular references from obj | ||
export function cleanObject(obj, keysToRemove = [], seen = new WeakSet()) { | ||
if (obj === null || typeof obj !== "object") { | ||
return obj; | ||
} | ||
|
||
if (typeof value === "function") { | ||
return undefined; | ||
} | ||
|
||
if (seen.has(obj)) { | ||
return undefined; | ||
} | ||
|
||
seen.add(obj); | ||
|
||
if (Array.isArray(obj)) { | ||
return obj.map((item) => cleanObject(item, keysToRemove, seen)); | ||
} | ||
|
||
return Object.fromEntries( | ||
Object.entries(obj) | ||
.filter(([key, value]) => !keysToRemove.includes(key) && typeof value !== "function" && !seen.has(value)) | ||
.map(([key, value]) => [key, cleanObject(value, keysToRemove, seen)]) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters