@@ -180,16 +180,12 @@ Oskari.clazz.define('Oskari.mapframework.mapmodule.Tiles3DLayerPlugin',
180
180
if ( ! this . getMapModule ( ) . getSupports3D ( ) ) {
181
181
return ;
182
182
}
183
- const options = layer . getOptions ( ) || { } ;
184
- const { ionAssetId, ionAssetServer, ionAccessToken } = options ;
185
-
186
- const url = ionAssetId
187
- ? Cesium . IonResource . fromAssetId ( ionAssetId , { server : ionAssetServer , accessToken : ionAccessToken } )
188
- : layer . getLayerUrl ( ) ;
189
-
190
- this . __addTileset ( layer , url , options ) ;
183
+ // moved to own func because of async/await requirement
184
+ this . __addTileset ( layer ) ;
191
185
} ,
192
- __addTileset : async function ( layer , url , options = { } ) {
186
+ __addTileset : async function ( layer ) {
187
+ const options = layer . getOptions ( ) || { } ;
188
+ const url = await this . __getURL ( layer , options ) ;
193
189
// Common settings for the dynamicScreenSpaceError optimization
194
190
// copied from Cesium.Cesium3DTileset api doc:
195
191
// https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html
@@ -208,6 +204,21 @@ Oskari.clazz.define('Oskari.mapframework.mapmodule.Tiles3DLayerPlugin',
208
204
// store reference to layers
209
205
this . setOLMapLayers ( layer . getId ( ) , tileset ) ;
210
206
} ,
207
+ __getURL : async function ( layer , options ) {
208
+ const { ionAssetId, ionAssetServer, ionAccessToken } = options ;
209
+ if ( ! ionAssetId ) {
210
+ return layer . getLayerUrl ( ) ;
211
+ }
212
+ const ionResourceOpts = { } ;
213
+ if ( ionAssetServer ) {
214
+ // check truthy, we might have empty string defined and Cesium only checks for null/undefined for defaulting.
215
+ ionResourceOpts . server = ionAssetServer ;
216
+ }
217
+ if ( ionAccessToken ) {
218
+ ionResourceOpts . accessToken = ionAccessToken ;
219
+ }
220
+ return Cesium . IonResource . fromAssetId ( ionAssetId , ionResourceOpts ) ;
221
+ } ,
211
222
/**
212
223
* Called when layer details are updated (for example by the admin functionality)
213
224
* @param {Oskari.mapframework.domain.AbstractLayer } layer new layer details
0 commit comments