diff options
author | bobzel <zzzman@gmail.com> | 2023-08-27 21:44:25 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2023-08-27 21:44:25 -0400 |
commit | 3f51ab416090a249aab489b3eb21a456b4d42143 (patch) | |
tree | d2b21bbc7e227cdfd4f23a98b96623b36cd3d067 /src/client/views/nodes/MapBox/MapBox.tsx | |
parent | 9d6c7f8100de3a952d20ad41ab20872737cb909e (diff) |
fixed exceptions when delete entities from a Map when it's in the process of unmounting
Diffstat (limited to 'src/client/views/nodes/MapBox/MapBox.tsx')
-rw-r--r-- | src/client/views/nodes/MapBox/MapBox.tsx | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx index 6f552953d..f0106dbbb 100644 --- a/src/client/views/nodes/MapBox/MapBox.tsx +++ b/src/client/views/nodes/MapBox/MapBox.tsx @@ -98,10 +98,13 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps } componentDidMount() { + this._unmounting = false; this.props.setContentView?.(this); } + _unmounting = false; componentWillUnmount(): void { + this._unmounting = true; this.deselectPin(); Object.keys(this._disposers).forEach(key => this._disposers[key]?.()); } @@ -343,10 +346,14 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps Doc.setDocFilter(this.rootDoc, '-linkedTo', Field.toString(DocCast(this.selectedPin.mapPin)), 'removeAll'); const temp = this.selectedPin; - this._bingMap.current.entities.remove(this.map_docToPinMap.get(temp)); + if (!this._unmounting) { + this._bingMap.current.entities.remove(this.map_docToPinMap.get(temp)); + } const newpin = new this.MicrosoftMaps.Pushpin(new this.MicrosoftMaps.Location(temp.latitude, temp.longitude)); this.MicrosoftMaps.Events.addHandler(newpin, 'click', (e: any) => this.pushpinClicked(temp as Doc)); - this._bingMap.current.entities.push(newpin); + if (!this._unmounting) { + this._bingMap.current.entities.push(newpin); + } this.map_docToPinMap.set(temp, newpin); this.selectedPin = undefined; this.bingSearchBarContents = this.rootDoc.map; @@ -488,7 +495,9 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps * Removes pushpin from map render */ deletePushpin = (pinDoc: Doc) => { - this._bingMap.current.entities.remove(this.map_docToPinMap.get(pinDoc)); + if (!this._unmounting) { + this._bingMap.current.entities.remove(this.map_docToPinMap.get(pinDoc)); + } this.map_docToPinMap.delete(pinDoc); this.selectedPin = undefined; }; |