fix mounting and destroying issues

This commit is contained in:
vcoppe
2024-07-13 11:42:21 +02:00
parent 46bafa9fff
commit b8e03cf947
8 changed files with 92 additions and 30 deletions

View File

@@ -54,15 +54,14 @@
if (selectedItem && selectedItem.getFileId() === fileId) {
selectedItem = null;
}
} else if ($map !== controls.map) {
controls.updateMap($map);
}
});
// add controls for new files
$fileObservers.forEach((file, fileId) => {
if (!routingControls.has(fileId)) {
routingControls.set(
fileId,
new RoutingControls(get(map), fileId, file, popup, popupElement)
);
routingControls.set(fileId, new RoutingControls($map, fileId, file, popup, popupElement));
}
});
}
@@ -92,6 +91,9 @@
onDestroy(() => {
$map?.off('click', createFileWithPoint);
routingControls.forEach((controls) => controls.destroy());
routingControls.clear();
});
</script>

View File

@@ -135,6 +135,10 @@ export class RoutingControls {
this.fileUnsubscribe();
}
updateMap(map: mapboxgl.Map) {
this.map = map;
}
createAnchor(point: TrackPoint, segment: TrackSegment, trackIndex: number, segmentIndex: number): AnchorWithMarker {
let element = document.createElement('div');
element.className = `h-3 w-3 rounded-full bg-white border-2 border-black cursor-pointer`;