Skip to content

Commit

Permalink
Clean up the speed limit layer when closing a route
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed May 16, 2023
1 parent 0fdbf37 commit ec8f871
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib/forms/RouteInfoLayers.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { onDestroy } from "svelte";
import {
emptyGeojson,
overwriteSource,
Expand Down Expand Up @@ -26,6 +27,7 @@
let speedLimitSteps = [30, 40, 50];
let source = "speed-limits";
let speedLimitLayer = "speed-limits";
// TODO Also draw a quantized legend
const colorBySpeedLimit: DataDrivenPropertyValueSpecification<string> = [
"step",
Expand All @@ -46,11 +48,20 @@
data: emptyGeojson(),
});
overwriteLayer($map, {
id: "speed-limits",
id: speedLimitLayer,
source,
...drawLine(colorBySpeedLimit, lineWidth, 1.0),
});
onDestroy(() => {
if ($map.getLayer(speedLimitLayer)) {
$map.removeLayer(speedLimitLayer);
}
if ($map.getSource(source)) {
$map.removeSource(source);
}
});
// TODO Disable the button until RouteInfo is loaded and ready?
async function changeLayer() {
if (layer == "none") {
Expand Down

0 comments on commit ec8f871

Please sign in to comment.