Skip to content

Commit

Permalink
Shovels in some cesium wasm and uses await for assetId URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakarFin committed Nov 6, 2024
1 parent b387079 commit cd27426
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
29 changes: 20 additions & 9 deletions bundles/mapping/tiles3d/plugin/Tiles3DLayerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,12 @@ Oskari.clazz.define('Oskari.mapframework.mapmodule.Tiles3DLayerPlugin',
if (!this.getMapModule().getSupports3D()) {
return;
}
const options = layer.getOptions() || {};
const { ionAssetId, ionAssetServer, ionAccessToken } = options;

const url = ionAssetId
? Cesium.IonResource.fromAssetId(ionAssetId, { server: ionAssetServer, accessToken: ionAccessToken })
: layer.getLayerUrl();

this.__addTileset(layer, url, options);
// moved to own func because of async/await requirement
this.__addTileset(layer);
},
__addTileset: async function (layer, url, options = {}) {
__addTileset: async function (layer) {
const options = layer.getOptions() || {};
const url = await this.__getURL(layer, options);
// Common settings for the dynamicScreenSpaceError optimization
// copied from Cesium.Cesium3DTileset api doc:
// https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html
Expand All @@ -208,6 +204,21 @@ Oskari.clazz.define('Oskari.mapframework.mapmodule.Tiles3DLayerPlugin',
// store reference to layers
this.setOLMapLayers(layer.getId(), tileset);
},
__getURL: async function (layer, options) {
const { ionAssetId, ionAssetServer, ionAccessToken } = options;
if (!ionAssetId) {
return layer.getLayerUrl();
}
const ionResourceOpts = {};
if (ionAssetServer) {
// check truthy, we might have empty string defined and Cesium only checks for null/undefined for defaulting.
ionResourceOpts.server = ionAssetServer;
}
if (ionAccessToken) {
ionResourceOpts.accessToken = ionAccessToken;
}
return Cesium.IonResource.fromAssetId(ionAssetId, ionResourceOpts);
},
/**
* Called when layer details are updated (for example by the admin functionality)
* @param {Oskari.mapframework.domain.AbstractLayer} layer new layer details
Expand Down
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ module.exports = (env, argv) => {
.forEach(possibleSrcPath => {
plugins.push(new CopywebpackPlugin([
{ from: path.join(__dirname, possibleSrcPath, '../Source/Assets'), to: cesiumTarget + '/Assets' },
// This is not available under Build folder:
// - oskari-frontend/node_modules/@cesium/engine/Source/ThirdParty/draco_decoder.wasm
{ from: path.join(__dirname, possibleSrcPath, '../Source/ThirdParty'), to: cesiumTarget + '/ThirdParty' },
{ from: path.join(__dirname, possibleSrcPath, 'Workers'), to: cesiumTarget + '/Workers' },
// { from: path.join(__dirname, possibleSrcPath, 'Widgets'), to: cesiumTarget + '/Widgets' },
// copy Cesium's minified third-party scripts
Expand Down

0 comments on commit cd27426

Please sign in to comment.