Skip to content

Commit

Permalink
Support editing local layer names and visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Nov 13, 2024
1 parent 698a788 commit d9f5862
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
39 changes: 37 additions & 2 deletions vue/src/actions/localMapLayers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { state } from "../store";
import { getGeoJSONBounds } from '../utils';
import { FitBoundsEvent } from '../actions/map';

let id = 1;
let _id = 1;

function nextId() {
return id++;
return _id++;
}

function defaultLayerName(layerId: number) {
return `Layer ${layerId}`;
}

export function addLocalMapLayer(feature: GeoJSON.GeoJSON): number {
const id = nextId();
state.localMapFeatureById[id] = {
id,
geojson: feature,
visible: true,
name: defaultLayerName(id),
};
state.localMapFeatureIds.push(id);

Expand All @@ -25,3 +33,30 @@ export function removeLocalMapLayer(id: number) {
delete state.localMapFeatureById[id];
}

export function focusLayer(layerId: number) {
const layer = state.localMapFeatureById[layerId];
if (!layer) return;

const bounds = getGeoJSONBounds(layer.geojson);
FitBoundsEvent.trigger(bounds);
}

export function setLayerVisibility(layerId: number, visible: boolean) {
const layer = state.localMapFeatureById[layerId];
if (!layer) return;

state.localMapFeatureById[layerId] = {
...layer,
visible,
};
}

export function setLayerName(layerId: number, name: string) {
const layer = state.localMapFeatureById[layerId];
if (!layer) return;

state.localMapFeatureById[layerId] = {
...layer,
name: name.trim().length ? name : defaultLayerName(layerId),
};
}
33 changes: 21 additions & 12 deletions vue/src/components/LocalLayers.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { addLocalMapLayer, removeLocalMapLayer } from '../actions/localMapLayers';
import { addLocalMapLayer, focusLayer, removeLocalMapLayer, setLayerName, setLayerVisibility } from '../actions/localMapLayers';
import { state } from '../store';
import { getGeoJSONBounds } from '../utils';
import { FitBoundsEvent } from '../actions/map';
const isLoading = ref(false);
Expand Down Expand Up @@ -51,14 +49,6 @@ function deleteLayer(layerId: number) {
removeLocalMapLayer(layerId);
}
function focusLayer(layerId: number) {
const layer = state.localMapFeatureById[layerId];
if (!layer) return;
const bounds = getGeoJSONBounds(layer.geojson);
FitBoundsEvent.trigger(bounds);
}
const localLayers = computed(() => {
return state.localMapFeatureIds.map(
(id) => state.localMapFeatureById[id],
Expand Down Expand Up @@ -93,8 +83,13 @@ const localLayers = computed(() => {
<v-list-item
v-for="layer in localLayers"
:key="layer.id"
:title="`Layer ${layer.id}`"
>
<v-text-field
variant="underlined"
:placeholder="`Layer ${layer.id}`"
:model-value="layer.name"
@model-value:update="setLayerName(layer.id, $event)"
/>
<template #append>
<v-btn
color="grey-darken-1"
Expand All @@ -110,6 +105,20 @@ const localLayers = computed(() => {
Focus
</v-tooltip>
</v-btn>
<v-btn
color="grey-darken-1"
icon
variant="text"
@click="setLayerVisibility(layer.id, !layer.visible)"
>
<v-icon>{{ layer.visible ? 'mdi-eye' : 'mdi-eye-off' }}</v-icon>
<v-tooltip
activator="parent"
location="bottom"
>
Toggle Visibility
</v-tooltip>
</v-btn>
<v-btn
color="grey-darken-1"
icon
Expand Down

0 comments on commit d9f5862

Please sign in to comment.