Skip to content

Commit b5537b7

Browse files
Refactor STAC data structure and enhance frontend functionality
- Updated STAC JSON files for ESL and sediment classification datasets, simplifying properties and enhancing geometry definitions. - Integrated Tailwind CSS into the Nuxt.js configuration for improved styling. - Updated package dependencies, including the addition of @nuxtjs/tailwindcss and lucide-vue-next. - Refactored index.vue to streamline data fetching and improve user interface for dataset selection, including polygon drawing functionality. - Enhanced user experience with clearer dataset availability indicators and improved download options for reports and notebooks.
1 parent 9214026 commit b5537b7

13 files changed

+2380
-1505
lines changed

App/components/CollectionSelector.vue

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<script lang="ts" setup>
2+
import { Eye, EyeOff } from 'lucide-vue-next'
3+
import { CollectionType, LayerLink } from '../types'
4+
import type { Ref } from 'vue'
5+
6+
let { collection, onChangeActive, activeValue } = defineProps<{
7+
collection: CollectionType & { href: string }
8+
activeValue?: LayerLink
9+
onChangeActive(link?: LayerLink): void
10+
}>()
11+
12+
let baseURL = collection.href.replace('/collection.json', '')
13+
14+
let summaries = computed(() => {
15+
return collection?.summaries
16+
})
17+
18+
let propertyOrder = computed(() => Object.keys(summaries.value))
19+
20+
let variables: Ref<Record<string, string | undefined>> = ref({})
21+
22+
function resetVariables() {
23+
variables.value = Object.keys(summaries.value ?? {}).reduce((acc, key) => {
24+
return {
25+
...acc,
26+
[key]: undefined,
27+
}
28+
}, {} as Record<string, string | undefined>)
29+
}
30+
31+
resetVariables()
32+
33+
function getValidOptionsForProperty(property: string) {
34+
if (!variables.value) return []
35+
36+
let currentIndex = propertyOrder.value.indexOf(property)
37+
let relevantProperties = propertyOrder.value.slice(0, currentIndex)
38+
39+
let validItems = collection.links
40+
.filter((link) => link.rel === 'item')
41+
.filter((link) => {
42+
if (!variables.value) return false
43+
return Object.entries(variables.value)
44+
.filter(([key]) => relevantProperties.includes(key))
45+
.every(
46+
([key, option]) =>
47+
!option ||
48+
link.properties?.[key as keyof typeof link.properties] === option,
49+
)
50+
})
51+
52+
return [
53+
...new Set(
54+
validItems.map(
55+
(item) => item?.properties?.[property as keyof typeof item.properties],
56+
),
57+
),
58+
]
59+
}
60+
61+
function selectOption(property: string, option: string) {
62+
if (!variables.value) return
63+
64+
if (variables.value[property] === option) {
65+
variables.value[property] = undefined
66+
} else {
67+
variables.value[property] = option
68+
}
69+
70+
let currentIndex = propertyOrder.value.indexOf(property)
71+
for (let i = currentIndex + 1; i < propertyOrder.value.length; i++) {
72+
let nextProperty = propertyOrder.value[i]
73+
if (!variables.value) break
74+
75+
variables.value[nextProperty] = undefined
76+
77+
let validOptions = getValidOptionsForProperty(nextProperty)
78+
if (validOptions.length === 1) {
79+
variables.value[nextProperty] = validOptions[0]
80+
}
81+
}
82+
}
83+
84+
watchEffect(() => {
85+
if (!summaries.value || !variables.value) return
86+
87+
let foundLink = collection.links
88+
.filter((l) => l.rel === 'item')
89+
.find((link) => {
90+
return Object.entries(variables.value ?? {}).every(
91+
([key, option]) =>
92+
link.properties?.[key as keyof typeof link.properties] === option,
93+
)
94+
})
95+
96+
if (foundLink) {
97+
onChangeActive({
98+
type: 'item',
99+
href: baseURL + '/' + foundLink.href,
100+
})
101+
} else {
102+
onChangeActive(undefined)
103+
}
104+
})
105+
106+
function toggleActive(value: boolean) {
107+
if (!value) {
108+
onChangeActive(undefined)
109+
resetVariables()
110+
} else {
111+
if (summaries.value) {
112+
// do nothing
113+
} else {
114+
const geoserverLink = collection.assets?.['geoserver_link'] as
115+
| { href: string }
116+
| undefined
117+
if (geoserverLink) {
118+
onChangeActive({
119+
type: 'raster',
120+
href: geoserverLink.href,
121+
})
122+
}
123+
}
124+
}
125+
}
126+
</script>
127+
128+
<template>
129+
<div v-if="!summaries">
130+
<div class="flex items-center gap-3 bg-white p-3 shadow">
131+
<button
132+
@click="toggleActive(!activeValue)"
133+
class="size-8 flex items-center justify-center shrink-0 rounded-md hover:bg-gray-100"
134+
>
135+
<Eye class="size-4" v-if="!!activeValue" />
136+
<EyeOff class="size-4" v-if="!activeValue" />
137+
</button>
138+
<div class="text-sm font-medium">{{ collection.title }}</div>
139+
</div>
140+
</div>
141+
<v-expansion-panel v-if="summaries">
142+
<v-expansion-panel-title>
143+
<div class="flex items-center gap-3">
144+
<button
145+
@click.stop="!!activeValue && toggleActive(false)"
146+
class="z-10 size-8 flex items-center justify-center shrink-0 rounded-md hover:bg-gray-100"
147+
>
148+
<Eye class="size-4" v-if="!!activeValue" />
149+
<EyeOff class="size-4" v-if="!activeValue" />
150+
</button>
151+
<div>{{ collection.title }}</div>
152+
</div>
153+
</v-expansion-panel-title>
154+
<v-expansion-panel-text>
155+
<div class="grid grid-flow-row gap-1.5 py-3">
156+
<div
157+
v-for="(options, key) in summaries"
158+
:key="key"
159+
class="empty:hidden"
160+
>
161+
<v-select
162+
:label="key"
163+
:items="getValidOptionsForProperty(key)"
164+
:model-value="variables?.[key]"
165+
@update:model-value="selectOption(key, $event)"
166+
/>
167+
</div>
168+
</div>
169+
</v-expansion-panel-text>
170+
</v-expansion-panel>
171+
</template>

App/components/ItemLayer.vue

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script setup lang="ts">
2+
import { ItemType } from '~/types'
3+
4+
let { href } = defineProps<{
5+
href: string
6+
}>()
7+
8+
let { data: jsonString } = await useFetch<ItemType>(href)
9+
10+
let item = computed(() => JSON.parse(jsonString.value))
11+
</script>
12+
13+
<template>
14+
<RasterLayer :id="item.id" :href="item.assets.visual.href" />
15+
</template>

App/components/Layer.vue

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script setup lang="ts">
2+
import { LayerLink } from '~/types'
3+
4+
let { link } = defineProps<{
5+
link: LayerLink
6+
}>()
7+
</script>
8+
9+
<template>
10+
<ItemLayer v-if="link.type === 'item'" :href="link.href" />
11+
<RasterLayer
12+
v-if="link.type === 'raster'"
13+
:href="link.href"
14+
:id="link.href"
15+
/>
16+
</template>

App/components/RasterLayer.vue

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script setup lang="ts">
2+
import { MapboxLayer } from '@studiometa/vue-mapbox-gl'
3+
4+
let { id, href } = defineProps<{
5+
id: string
6+
href: string
7+
}>()
8+
9+
let layer = computed(() => {
10+
return {
11+
id,
12+
type: 'raster',
13+
source: {
14+
type: 'raster',
15+
tiles: [href],
16+
tileSize: 256,
17+
},
18+
}
19+
})
20+
</script>
21+
22+
<template>
23+
<MapboxLayer v-if="layer" :key="layer.id" :id="layer.id" :options="layer" />
24+
</template>

App/types.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import collectionShape from '../STAC/data/current/sub_threat/collection.json'
2+
import itemShape from '../../STAC/data/current/sub_threat/eapa-mapbox/eapa-mapbox-time-2010.json'
3+
4+
export type CollectionType = typeof collectionShape
5+
export type ItemType = typeof itemShape
6+
7+
export interface ItemLink {
8+
type: 'item'
9+
href: string
10+
}
11+
12+
export interface RasterLink {
13+
type: 'raster'
14+
href: string
15+
}
16+
17+
export type LayerLink = ItemLink | RasterLink
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '@studiometa/vue-mapbox-gl' {
2+
import { DefineComponent } from 'vue'
3+
export const MapboxMap: DefineComponent<any, any, any>
4+
}

0 commit comments

Comments
 (0)