@@ -409,22 +409,14 @@ class STACLayer extends LayerGroup {
409409 const errorHandler = ( error ) => this . handleError_ ( error ) ;
410410 const promises = [ ] ;
411411 if ( children ) {
412- promises . push ( this . setChildren ( children ) . catch ( errorHandler ) ) ;
412+ promises . push (
413+ this . setChildren ( children , null , false ) . catch ( errorHandler )
414+ ) ;
413415 }
414416 if ( assets ) {
415- promises . push ( this . setAssets ( assets ) . catch ( errorHandler ) ) ;
416- }
417- if ( promises . length === 0 ) {
418- promises . push ( this . updateLayers_ ( ) . catch ( errorHandler ) ) ;
417+ promises . push ( this . setAssets ( assets , false ) . catch ( errorHandler ) ) ;
419418 }
420- Promise . all ( promises ) . then ( ( ) => {
421- /**
422- * Invoked once all layers are shown on the map.
423- *
424- * @event layersready
425- */
426- return this . dispatch_ ( 'layersready' ) ;
427- } ) ;
419+ Promise . all ( promises ) . then ( ( ) => this . updateLayers ( ) . catch ( errorHandler ) ) ;
428420
429421 /**
430422 * Invoked once the STAC entity is loaded and available.
@@ -923,9 +915,13 @@ class STACLayer extends LayerGroup {
923915 }
924916
925917 /**
926- * @private
918+ * Update the layers shown manually based on the current configuration.
919+ * Usually this doesn't need to be called manually.
920+ * @param {boolean } [emit=true] Whether to emit the `layersready` event once the layers are updated.
921+ * @return {Promise } Resolves once the layers are updated.
922+ * @api
927923 */
928- async updateLayers_ ( ) {
924+ async updateLayers ( emit = true ) {
929925 // Remove old layers
930926 const oldLayers = this . getLayers ( ) ;
931927 for ( let i = oldLayers . getLength ( ) - 1 ; i >= 0 ; i -- ) {
@@ -985,6 +981,9 @@ class STACLayer extends LayerGroup {
985981 data . getMetadata ( 'label:type' ) === 'vector'
986982 ) {
987983 await this . addLabelExtension_ ( ) ;
984+ if ( emit ) {
985+ this . dispatch_ ( 'layersready' ) ;
986+ }
988987 return ;
989988 }
990989 // Show web map links
@@ -1014,6 +1013,9 @@ class STACLayer extends LayerGroup {
10141013 }
10151014 }
10161015 }
1016+ if ( emit ) {
1017+ this . dispatch_ ( 'layersready' ) ;
1018+ }
10171019 }
10181020
10191021 /**
@@ -1072,10 +1074,11 @@ class STACLayer extends LayerGroup {
10721074 /**
10731075 * Update the assets to be rendered.
10741076 * @param {Array<string|Asset>|null } assets The assets to show.
1077+ * @param {boolean } [updateLayers=true] Whether to update the layers right away.
10751078 * @return {Promise } Resolves when all assets are rendered.
10761079 * @api
10771080 */
1078- async setAssets ( assets ) {
1081+ async setAssets ( assets , updateLayers = true ) {
10791082 if ( assets === this . assets_ ) {
10801083 return ;
10811084 }
@@ -1093,7 +1096,9 @@ class STACLayer extends LayerGroup {
10931096 } else {
10941097 this . assets_ = null ;
10951098 }
1096- await this . updateLayers_ ( ) ;
1099+ if ( updateLayers ) {
1100+ await this . updateLayers ( ) ;
1101+ }
10971102 }
10981103
10991104 /**
@@ -1103,10 +1108,11 @@ class STACLayer extends LayerGroup {
11031108 *
11041109 * @param {ItemCollection|Object|Array<STAC|Object>|null } childs The children to show.
11051110 * @param {Options|null } [options=null] Optionally, new STACLayer options for the children. Only applies if `children` are given.
1111+ * @param {boolean } [updateLayers=true] Whether to update the layers right away.
11061112 * @return {Promise } Resolves when all items are rendered.
11071113 * @api
11081114 */
1109- async setChildren ( childs , options = null ) {
1115+ async setChildren ( childs , options = null , updateLayers = true ) {
11101116 if ( childs instanceof ItemCollection ) {
11111117 this . children_ = childs . getAll ( ) ;
11121118 } else if ( isObject ( childs ) && childs . type === 'FeatureCollection' ) {
@@ -1127,7 +1133,9 @@ class STACLayer extends LayerGroup {
11271133 if ( this . children_ && isObject ( options ) ) {
11281134 this . childrenOptions_ = options ;
11291135 }
1130- await this . updateLayers_ ( ) ;
1136+ if ( updateLayers ) {
1137+ await this . updateLayers ( ) ;
1138+ }
11311139 }
11321140
11331141 /**
0 commit comments