Skip to content

Commit

Permalink
Fixes #647 (try 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Oct 18, 2023
1 parent 8737668 commit 9050c5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/client/src/MeasureControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ class MeasureControl extends EventEmitter {
private addSourcesAndLayers() {
const sources = this.getSources();
for (const id in sources) {
this.map.addSource(id, sources[id]);
if (!this.map.getSource(id)) {
this.map.addSource(id, sources[id]);
}
}
for (const layer of measureLayers) {
this.map.addLayer(layer);
if (!this.map.getLayer(layer.id)) {
this.map.addLayer(layer);
}
}
}

Expand Down Expand Up @@ -311,12 +315,13 @@ class MeasureControl extends EventEmitter {
// unregister all event handlers
this.removeEventListeners(this.map);
}
document.body.removeEventListener("keydown", this.onKeyDown);
this.isDestroyed = true;
};

onKeyDown = (e: KeyboardEvent) => {
if (this.isDestroyed) {
throw new Error("MeasureControl is destroyed");
return;
}
if (e.key === "Escape" && this.state === "drawing") {
this.stopEditing();
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/draw/useMapboxGLDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default function useMapboxGLDraw(
useEffect(() => {
if (
mapContext.manager?.map &&
// mapContext.manager.map.loaded() &&
geometryType &&
!disabled &&
!handlerState.current.draw
Expand Down Expand Up @@ -357,6 +358,7 @@ export default function useMapboxGLDraw(
disabled,
preprocessingEndpoint,
preprocessingResults,
// mapContext.manager?.map?.loaded(),
]);

useEffect(() => {
Expand Down

0 comments on commit 9050c5c

Please sign in to comment.