Skip to content

Commit

Permalink
App in stable state
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBroersma committed Nov 23, 2023
1 parent a571a05 commit d2150e4
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 56 deletions.
7 changes: 7 additions & 0 deletions App/prettier.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: false,
singleQuote: true,
arrowParens: 'always',
trailingComma: 'all',
tabWidth: 2,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"type": "Feature",
"stac_version": "1.0.0",
"id": "eapa-mapbox-time-2010",
"properties": {
"deltares:item_key": "time-2010",
"deltares:paint": {
"fill-color": [
"interpolate",
["linear"],
["get", "time-2010"],
0,
"rgba(59, 217, 90, 0.3)",
277.5,
"rgba(245, 188, 66, 0.3)",
555,
"rgba(217, 59, 59, 0.3)"
]
},
"deltares:type": "fill",
"deltares:stations": "locationId",
"deltares:onclick": {},
"time": 2010,
"datetime": "2023-11-07T13:34:44.212216Z"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-180.0, -90.0],
[180.0, -90.0],
[180.0, 90.0],
[-180.0, 90.0],
[-180.0, -90.0]
]
]
},
"links": [
{
"rel": "collection",
"href": "../collection.json",
"type": "application/json",
"title": "Land Subsidence Threat"
},
{
"rel": "root",
"href": "../../catalog.json",
"type": "application/json",
"title": "GlobalCoastalAtlas STAC Catalog"
},
{
"rel": "parent",
"href": "../collection.json",
"type": "application/json",
"title": "Land Subsidence Threat"
}
],
"assets": {
"mapbox": {
"href": "mapbox://global-data-viewer.Global_TLS_eapa",
"title": "Point locations",
"description": "Mapbox url",
"type": "vector",
"source": "Global_TLS_eapa",
"roles": ["mapbox"]
}
},
"bbox": [-180, -90, 180, 90],
"stac_extensions": [
"https://raw.githubusercontent.com/openearth/coclicodata/main/json-schema/schema.json"
],
"collection": "sub_threat"
}
112 changes: 59 additions & 53 deletions app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
<script setup lang="ts">
import { MapboxMap, MapboxLayer } from "@studiometa/vue-mapbox-gl";
import "mapbox-gl/dist/mapbox-gl.css";
import { MapboxMap, MapboxLayer } from '@studiometa/vue-mapbox-gl'
import 'mapbox-gl/dist/mapbox-gl.css'
import itemShape from '../../STAC/data/current/sub_threat/epsi-mapbox/epsi-mapbox-time-2010.json'
import catalogShape from '../../STAC/data/current/catalog.json'
import collectionShape from '../../STAC/data/current/sub_threat/collection.json'
type ItemType = typeof itemShape
type CatalogType = typeof catalogShape
type CollectionType = typeof collectionShape
let {
public: { mapboxToken, stacRoot },
} = useRuntimeConfig();
} = useRuntimeConfig()
let catalogPath = `${stacRoot}/catalog.json`;
let catalogPath = `${stacRoot}/catalog.json`
let { data: catalogJson } = await useFetch(catalogPath);
let { data: catalogJson } = await useFetch<CatalogType>(catalogPath)
let catalog = catalogJson.value;
let catalog = catalogJson.value
let childrenLinks = catalog.links.filter((link) => link.rel === "child");
let childrenLinks = catalog?.links.filter(link => link.rel === 'child') ?? []
let collections = (
await Promise.all(
childrenLinks.map(async (childLink) => {
let { data } = await useFetch(`${stacRoot}/${childLink.href}`);
return data.value;
})
childrenLinks.map(async childLink => {
let { data } = await useFetch<CollectionType>(
`${stacRoot}/${childLink.href}`,
)
return data.value
}),
)
).filter((collection) => collection.links.some((link) => link.rel === "item"));
).filter(collection => collection?.links.some(link => link.rel === 'item'))
let activeCollectionId = ref(collections[0].id);
let activeCollectionId = ref(collections[0]?.id)
let activeCollection = computed(() => {
return collections.find(
(collection) => collection.id === activeCollectionId.value
);
});
collection => collection?.id === activeCollectionId.value,
)
})
let summaries = computed(() => {
let newSummaries = {
...(activeCollection.value.summaries ??
activeCollection.value["cube:dimensions"] ??
{}),
};
delete newSummaries.lat;
delete newSummaries.lon;
return newSummaries;
});
return Object.entries(
activeCollection.value?.['cube:variables'] || {},
).filter(([key, value]) => {
return value.type !== 'data'
})
})
// let { data: activeCollection } = await useFetch(currentCollectionPath);
Expand All @@ -52,9 +58,9 @@ let variables = ref(
return {
...acc,
[key]: values[0],
};
}, {} as Record<string, string>)
);
}
}, {} as Record<string, string>),
)
watchEffect(
() => {
Expand All @@ -63,42 +69,42 @@ watchEffect(
return {
...acc,
[key]: values[0],
};
}
},
{} as Record<string, string>
);
{} as Record<string, string>,
)
},
{ flush: "pre" }
);
{ flush: 'pre' },
)
let activeItemUrl = computed(() => {
if (!activeCollection.value) return;
if (!activeCollection.value) return
let foundLink =
activeCollection.value.links
.filter((l) => l.rel === "item")
.find((link) => {
.filter(l => l.rel === 'item')
.find(link => {
return Object.entries(variables.value).every(
([key, value]) => link.properties?.[key] === value
);
}) ?? activeCollection.value.links.filter((l) => l.rel === "item")[0];
([key, value]) => link.properties?.[key] === value,
)
}) ?? activeCollection.value.links.filter(l => l.rel === 'item')[0]
return foundLink?.href;
});
return foundLink?.href
})
let { data } = await useAsyncData(
() =>
$fetch(`${stacRoot}/${activeCollectionId.value}/${activeItemUrl.value}`),
{ watch: [activeItemUrl] }
);
{ watch: [activeItemUrl] },
)
let geojson = computed(() => {
// let item = JSON.parse(data.value);
let item = data.value;
let item = data.value
if (!item?.assets) return {};
if (!item?.assets) return {}
let { mapbox } = item.assets;
let { properties } = item;
let { mapbox } = item.assets
let { properties } = item
// if (visual) {
// return {
Expand All @@ -114,15 +120,15 @@ let geojson = computed(() => {
return {
id: item.id,
type: properties["deltares:type"],
type: properties['deltares:type'],
source: {
type: mapbox.type,
url: mapbox.href,
},
"source-layer": mapbox.source,
paint: properties["deltares:paint"],
};
});
'source-layer': mapbox.source,
paint: properties['deltares:paint'],
}
})
</script>

<template>
Expand Down
4 changes: 1 addition & 3 deletions app/server/routes/stac/[...].ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export default defineEventHandler(async (event) => {

if (!path) throw new Error("No path provided");

let json = await fs.readFile(
`${process.cwd()}/../stac_folder/current/${path}`
);
let json = await fs.readFile(`${process.cwd()}/../STAC/data/current/${path}`);

return json;
});

0 comments on commit d2150e4

Please sign in to comment.