Commit 9558fd27 authored by Luna Riegel's avatar Luna Riegel
Browse files

Add loading from catalog for placement files

parent 5a38e4d7
import { ToolboxType, WindowSlot, NotificationType } from '@vcmap/ui';
import { Cesium3DTileStyle, Math as CMath, Ellipsoid, Cartesian3, ConstantProperty, Transforms, HeadingPitchRoll, Cesium3DTileset, Matrix4 } from '@vcmap-cesium/engine';
import {
Cesium3DTileStyle,
Math as CMath,
Ellipsoid,
Cartesian3,
ConstantProperty,
Transforms,
HeadingPitchRoll,
Cesium3DTileset,
Matrix4,
EntityCollection
} from '@vcmap-cesium/engine';
import { AbstractInteraction, EventType } from '@vcmap/core';
import { name, version, mapVersion } from '../package.json';
import BIMOptions, { bimOptionsId } from './upload.vue';
......@@ -104,7 +115,7 @@ function saveObjects() {
position: [wgs84X, wgs84Y, height],
heading: heading,
scale: m.model.model.scale.getValue(),
fromCatalog: m.fromCatalog,
fromCatalog: m.model.fromCatalog.valueOf(),
});
}
outputObject.placedObjects = outputArray;
......@@ -355,19 +366,22 @@ export default function smartVillagesPlugin(config, baseUrl) {
}
}
if (objectUrl === undefined) {
console.log("From Catalog:" + loadingObject.fromCatalog);
if (loadingObject.fromCatalog === true){
// TODO: Fetch from catalog
objectUrl = loadingObject.uri;
// Load the model into memory
loadCatalogModel(objectUrl).catch(e => {
const model = await loadCatalogModel(loadingObject.name).catch(e => {
console.error(e);
app.notifier.add({
type: NotificationType.ERROR,
message: "Katalogobject: " + loadingObject.name + " konnte nicht geladenen werden. Konfiguration konnte nicht vollständig geladen werden.",
});
return undefined;
});
return;
if (model === undefined) {
return;
} else {
objectUrl = model.url;
}
}else {
app.notifier.add({
type: NotificationType.ERROR,
......@@ -386,8 +400,8 @@ export default function smartVillagesPlugin(config, baseUrl) {
uri: objectUrl,
scale: loadingObject.scale,
show: true,
fromCatalog: loadingObject.fromCatalog,
},
fromCatalog: loadingObject.fromCatalog,
});
const roll = new HeadingPitchRoll();
hpRollMap.set(model, roll);
......
......@@ -16,7 +16,7 @@
<vcs-button
v-for="entry in entries"
:key="entry.title"
@click="fetchCatalogueModel(entry.model)"
@click="placeCatalogModel(entry.model)"
class="p-0 mx-1 my-0 border gc-2"
style="width: auto; height: auto; margin-left: 1rem; margin-bottom: 1px;"
variant="filled"
......@@ -129,17 +129,17 @@ let setupModelFunction = undefined;
let app = undefined;
let projectStateObject = undefined;
async function loadCataloguesFromConfig(config) {
async function loadCatalogsFromConfig(config) {
const configJson = JSON.parse(JSON.stringify(config));
const catalogues = Object.values(configJson.objectCatalogues);
for (const cat of catalogues) {
const catJson = await retrieveCatalogueJson(cat.url);
const catJson = await retrieveCatalogJson(cat.url);
if (!catJson) continue;
const category = cat.category.toString();
const linkPrefix = cat.url.replace(/\/[^/]*catalog\.json$/, '/');
const entries = getCatalogueEntries(catJson, linkPrefix);
const entries = getCatalogEntries(catJson, linkPrefix);
if (!objLib.value[category]) {
objLib.value[category] = entries;
......@@ -151,7 +151,7 @@ async function loadCataloguesFromConfig(config) {
}
async function retrieveCatalogueJson(link) {
async function retrieveCatalogJson(link) {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 5000);
......@@ -173,7 +173,7 @@ async function retrieveCatalogueJson(link) {
}
}
function getCatalogueEntries(json, linkPrefix) {
function getCatalogEntries(json, linkPrefix) {
const part = {};
......@@ -209,7 +209,7 @@ function getCatalogueEntries(json, linkPrefix) {
return part;
}
async function retrieveCatalogModel(modelLink){
async function placeCatalogModel(modelLink){
loadCatalogModel(modelLink).then(model => {
const catModel = model;
const x = window.innerWidth / 2;
......@@ -230,9 +230,9 @@ async function retrieveCatalogModel(modelLink){
export async function loadCatalogModel(modelLink){
return new Promise( (resolve, reject) => {
if(preloadedModels.value[modelLink] != null){
// Model is already in memory
resolve(preloadedModels.value[modelLink]);
} else{
//Todo: parse model from catalog
const loader = new GLTFLoader();
loader.load(
modelLink,
......@@ -433,8 +433,7 @@ function uploadModel() {
const dialog = ref(false);
setupModelFunction = setupModel;
projectStateObject = pluginState;
// loadCataloguesFromConfig(config).then(response => {console.log(objLib);});
onMounted(()=>loadCataloguesFromConfig(config).then(response => {console.log(objLib)}));
onMounted(()=>loadCatalogsFromConfig(config).then(response => {console.log(objLib)}));
return {
draggable,
selectable,
......@@ -528,8 +527,8 @@ function uploadModel() {
loadModel() {
uploadModel();
},
fetchCatalogueModel(modelLink) {
retrieveCatalogModel(modelLink);
placeCatalogModel(modelLink) {
placeCatalogModel(modelLink);
},
loadConfiguration() {
loadObjects(app);
......
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