Skip to content

Commit

Permalink
Disable interactive layers during street view use
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter York committed Aug 21, 2023
1 parent abd7911 commit 7025328
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/lib/browse/LayerControls.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { interactiveMapLayersEnabled } from "../../stores";
import { BaselayerSwitcher, CollapsibleCard } from "../common";
import StreetViewController from "../common/StreetViewController.svelte";
import { CheckboxGroup } from "../govuk";
Expand Down Expand Up @@ -51,6 +52,9 @@
<CensusOutputAreaLayerControl />
<ImdLayerControl />
</CollapsibleCard>
<StreetViewController displayEnableButton={true} />
<StreetViewController
displayEnableButton={true}
bind:isInactive={$interactiveMapLayersEnabled}
/>
<BaselayerSwitcher {style} />
</CollapsibleCard>
7 changes: 7 additions & 0 deletions src/lib/common/InteractiveLayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
} from "maplibre-gl";
import { createEventDispatcher, onDestroy, onMount } from "svelte";
import { map } from "../../stores";
import { interactiveMapLayersEnabled } from "../../stores";
const dispatch = createEventDispatcher<{
click: MapGeoJSONFeature;
Expand Down Expand Up @@ -63,6 +64,9 @@
}
function onMouseMove(e: MapLayerMouseEvent) {
if(!$interactiveMapLayersEnabled) {
return;
}
let features = e.features ?? [];
if (features.length == 0) {
return;
Expand Down Expand Up @@ -118,6 +122,9 @@
}
function onClick(e: MapLayerMouseEvent) {
if(!$interactiveMapLayersEnabled) {
return;
}
let features = e.features ?? [];
if (features.length > 0) {
// Same problem as onMouseMove -- every overlapping InteractiveLayer will
Expand Down
22 changes: 13 additions & 9 deletions src/lib/common/StreetViewController.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import { getRoadLayerHelpers, type LayerHelper } from "../maplibre";
import CollapsibleCard from "./CollapsibleCard.svelte";
export let displayEnableButton: boolean = false;
export let escapeKeyExits: boolean = false;
const roadLayerHelpers: Array<LayerHelper> = getRoadLayerHelpers();
let isActive: boolean;
export let isInactive: boolean;
export const handleMapClickEvent = (e: MapMouseEvent) => {
if (isActive) {
if (!isInactive) {
let lon = e.lngLat.lng;
let lat = e.lngLat.lat;
if ($userSettings.streetViewImagery == "google") {
Expand All @@ -32,7 +32,7 @@
};
export function enableStreetView() {
isActive = true;
isInactive = false;
$map.on("click", handleMapClickEvent);
const cursorStyle = `url(${cameraCursorUrl}), auto`;
console.log(cursorStyle);
Expand All @@ -43,7 +43,7 @@
}
export function disableStreetView() {
isActive = false;
isInactive = true;
$map.off("click", handleMapClickEvent);
$map.getCanvas().style.cursor = "inherit";
roadLayerHelpers.forEach((roadLayerHelper) => {
Expand All @@ -53,7 +53,7 @@
</script>

{#if displayEnableButton}
{#if !isActive}
{#if isInactive}
<SecondaryButton on:click={enableStreetView}>
Enable Street View
</SecondaryButton>
Expand All @@ -63,7 +63,7 @@
</SecondaryButton>
{/if}
{/if}
{#if isActive}
{#if !isInactive}
<Radio
legend="Source"
id="streetViewImagery"
Expand All @@ -75,7 +75,7 @@
/>

<CollapsibleCard label="Help">
<ul >
<ul>
<li>
<b>Click</b>
on the map to open a new tab with a 3rd-party imagery provider
Expand All @@ -88,7 +88,11 @@
</li>
{/if}
<li>
Cursor by <a href="https://icon-icons.com/icon/screenshot-cursor-camera/100181">Luc Chaissac</a>
Cursor by <a
href="https://icon-icons.com/icon/screenshot-cursor-camera/100181"
>
Luc Chaissac
</a>
</li>
</ul>
</CollapsibleCard>
Expand Down
2 changes: 2 additions & 0 deletions src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export const currentMode: Writable<Mode> = writable("edit-attribute");
// This is used to represent whether a tool is in use for the purpose of disabling buttons such as clear all
export const isAToolInUse: Writable<boolean> = writable(false);

export const interactiveMapLayersEnabled: Writable<boolean> = writable(true);

// All feature IDs must:
//
// - be unique
Expand Down

0 comments on commit 7025328

Please sign in to comment.