@@ -16,7 +16,7 @@ import { isProjectionAvailable } from '../../../../utils/ProjectionUtils';
1616import { getRequestConfigurationByUrl } from '../../../../utils/SecurityUtils' ;
1717import { updateUrlParams } from '../../../../utils/URLUtils' ;
1818
19- function create ( options ) {
19+ function getSource ( options ) {
2020 let sources = [ ] ;
2121 let sourceOptions = { } ;
2222 if ( options . sources && options . sources . length > 0 ) {
@@ -32,17 +32,27 @@ function create(options) {
3232 } ;
3333 } ) ;
3434 }
35+ return new GeoTIFF ( {
36+ convertToRGB : 'auto' , // CMYK, YCbCr, CIELab, and ICCLab images will automatically be converted to RGB
37+ sourceOptions,
38+ sources,
39+ wrapX : true
40+ } ) ;
41+ }
42+
43+ function create ( options ) {
44+ // GeoTIFF sources fetch eagerly on creation (unlike WMS, which loads on demand),
45+ // so `visible: false` won't prevent requests. Skip creating hidden layers;
46+ // `update` recreates them when they become visible.
47+ if ( options . visibility === false ) {
48+ return null ;
49+ }
3550 const layerOl = new TileLayer ( {
3651 msId : options . id ,
3752 style : get ( options , 'style.body' ) ,
3853 opacity : options . opacity !== undefined ? options . opacity : 1 ,
39- visible : options . visibility ,
40- source : new GeoTIFF ( {
41- convertToRGB : 'auto' , // CMYK, YCbCr, CIELab, and ICCLab images will automatically be converted to RGB
42- sourceOptions,
43- sources,
44- wrapX : true
45- } ) ,
54+ visible : true ,
55+ source : getSource ( options ) ,
4656 enablePickFeatures : true ,
4757 zIndex : options . zIndex ,
4858 minResolution : options . minResolution ,
@@ -55,6 +65,12 @@ function create(options) {
5565Layers . registerType ( 'cog' , {
5666 create,
5767 update ( layer , newOptions , oldOptions , map ) {
68+ if ( ! layer && newOptions . visibility !== false ) {
69+ return create ( newOptions , map ) ;
70+ }
71+ if ( ! layer ) {
72+ return null ;
73+ }
5874 if ( newOptions . srs !== oldOptions . srs
5975 || ! isEqual ( newOptions . style , oldOptions . style )
6076 || ! isEqual ( newOptions . security , oldOptions . security )
0 commit comments