Commit b88f4cbe authored by Luna Riegel's avatar Luna Riegel
Browse files

Add catalogue loading

parent ce996edd
<template> <template>
<v-sheet> <v-sheet>
<VcsFormSection heading="Objektbibliothek">
<template #help>
<p>Objektbibliothek:</p>
<span>Die Objektbibliothek.</span>
</template>
<v-container class="py-1 px-1">
<v-row no-gutters>
<vcs-list
:items="items"
:draggable="draggable"
:selectable="selectable"
:single-select="selectSingle"
:searchable="searchable"
:show-title="showTitle"
:icon="titleIconSrc"
:actions="titleActionsArray"
:title="title"
v-model="selected"
@item-moved="move"
@item-renamed="({ item, newTitle }) => (item.title = newTitle)"
/>
</v-row>
</v-container>
</VcsFormSection>
<VcsFormSection heading="Objektliste"> <VcsFormSection heading="Objektliste">
<template #help> <template #help>
<p>Objektliste:</p> <p>Objektliste:</p>
...@@ -68,30 +92,24 @@ ...@@ -68,30 +92,24 @@
<script> <script>
import { import {
VcsList, Icons,
VcsFormButton, NotificationType,
VcsTextField, VcsFormButton,
Icons, VcsFormSection,
VcsFormSection, VcsList,
NotificationType, VcsTextField,
} from '@vcmap/ui'; VcsTreeview,
import { VcsTreeviewTitle,
VSwitch, } from '@vcmap/ui';
VSheet, import {VCard, VCol, VContainer, VDialog, VForm, VRow, VSheet, VSwitch,} from 'vuetify/components';
VDialog, import {computed, inject, ref} from 'vue';
VCard, import {name} from '../package.json';
VForm,
VContainer,
VRow,
VCol,
} from 'vuetify/components';
import { computed, ref, inject } from 'vue';
import { name } from '../package.json';
import * as THREE from 'three'; import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; import {GLTFLoader} from 'three/addons/loaders/GLTFLoader.js';
import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js'; import {GLTFExporter} from 'three/addons/exporters/GLTFExporter.js';
import { Cartesian2 } from '@vcmap-cesium/engine'; import {Cartesian2} from '@vcmap-cesium/engine';
const objLib = {};
const defaultItems = []; const defaultItems = [];
const items = ref(defaultItems); const items = ref(defaultItems);
...@@ -99,6 +117,68 @@ let setupModelFunction = undefined; ...@@ -99,6 +117,68 @@ let setupModelFunction = undefined;
let app = undefined; let app = undefined;
let projectStateObject = undefined; let projectStateObject = undefined;
async function loadCataloguesFromConfig(config) {
const configJson = JSON.parse(JSON.stringify(config));
const catalogues = configJson.objectCatalogues;
for (let cat of catalogues) {
const catJson = await retrieveCatalogueJson(cat.url);
if (!catJson) continue;
const category = cat.category.toString();
const linkPrefix = cat.url.replace(/\/[^/]*catalog\.json$/, '/');
const entries = getCatalogueEntries(catJson, linkPrefix);
if (!objLib[category]) {
objLib[category] = [entries];
} else {
objLib[category].push(entries);
}
}
}
async function retrieveCatalogueJson(link) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 1000);
try {
const response = await fetch(link, { signal: controller.signal });
if (!response.ok) {
throw new Error(`HTTP error: ${response.status} for catalogue ${link}`);
}
return await response.json();
} catch (error) {
console.error(error);
return null;
} finally {
clearTimeout(timeout);
}
}
function getCatalogueEntries(json, linkPrefix) {
const part = {};
for (let item of json.items) {
const subCat = item.title;
const entries = [];
for (let entry of item.predefinedObjects) {
const info = {
title: entry.title,
icon: linkPrefix + entry.icon,
model: linkPrefix + entry.properties?.olcs_modelUrl,
};
entries.push(info);
}
part[subCat.toString()] = entries;
}
return part;
}
function uploadModel() { function uploadModel() {
// Create an input element // Create an input element
const inputElement = document.createElement("input"); const inputElement = document.createElement("input");
...@@ -206,6 +286,8 @@ function uploadModel() { ...@@ -206,6 +286,8 @@ function uploadModel() {
export default { export default {
name: 'objectList', name: 'objectList',
components: { components: {
VcsTreeview,
VcsTreeviewTitle,
VcsList, VcsList,
VcsFormButton, VcsFormButton,
VcsTextField, VcsTextField,
...@@ -221,7 +303,7 @@ function uploadModel() { ...@@ -221,7 +303,7 @@ function uploadModel() {
}, },
setup() { setup() {
app = inject('vcsApp'); app = inject('vcsApp');
const { pluginState, setupModel, saveObjects, loadObjects } = app.plugins.getByKey(name); const { pluginState, setupModel, saveObjects, loadObjects, config } = app.plugins.getByKey(name);
const draggable = ref(false); const draggable = ref(false);
const selectable = ref(false); const selectable = ref(false);
const searchable = ref(false); const searchable = ref(false);
...@@ -245,7 +327,7 @@ function uploadModel() { ...@@ -245,7 +327,7 @@ function uploadModel() {
const dialog = ref(false); const dialog = ref(false);
setupModelFunction = setupModel; setupModelFunction = setupModel;
projectStateObject = pluginState; projectStateObject = pluginState;
loadCataloguesFromConfig(config).then(response => {console.log(objLib);});
return { return {
draggable, draggable,
selectable, selectable,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment