From bd9f868b74b1b05d95023a03d322f4e0bcb8d4b2 Mon Sep 17 00:00:00 2001 From: jmacura Date: Tue, 27 Feb 2024 00:15:08 +0100 Subject: [PATCH] fix(cesium): Make OSM layer visible from zoom=1 refs #4750 --- .../src/hscesium-layers.service.ts | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/projects/hslayers-cesium/src/hscesium-layers.service.ts b/projects/hslayers-cesium/src/hscesium-layers.service.ts index 4045ae42c0..62e43eb389 100644 --- a/projects/hslayers-cesium/src/hscesium-layers.service.ts +++ b/projects/hslayers-cesium/src/hscesium-layers.service.ts @@ -183,7 +183,7 @@ export class HsCesiumLayersService { if (this.viewer.isDestroyed()) { return; } - if (this.hsConfig.default_layers !== undefined) { + if (this.hsConfig.default_layers) { for (const l of this.hsConfig.default_layers.filter((l) => l)) { this.processOlLayer(l); } @@ -197,7 +197,7 @@ export class HsCesiumLayersService { const map = await this.hsMapService.loaded(); map.getLayers().forEach((lyr: Layer) => { const cesiumLayer = this.findCesiumLayer(lyr); - if (cesiumLayer == undefined) { + if (!cesiumLayer) { this.processOlLayer(lyr); } }); @@ -407,26 +407,27 @@ export class HsCesiumLayersService { const cesium_layer = await this.convertOlToCesiumProvider( lyr as Layer, ); - if (cesium_layer) { - if (this.HsUtilsService.instOf(cesium_layer, ImageryLayer)) { - this.linkOlLayerToCesiumLayer( - lyr as Layer, - cesium_layer as ImageryLayer, + if (!cesium_layer) { + return; + } + if (this.HsUtilsService.instOf(cesium_layer, ImageryLayer)) { + this.linkOlLayerToCesiumLayer( + lyr as Layer, + cesium_layer as ImageryLayer, + ); + this.viewer.imageryLayers.add(cesium_layer); + } else if ( + (this.HsUtilsService.instOf(cesium_layer, GeoJsonDataSource) || + this.HsUtilsService.instOf(cesium_layer, KmlDataSource)) && + this.viewer.dataSources + ) { + this.viewer.dataSources.add(cesium_layer); + //TODO: Point clicked, Datasources extents, Composition extents shall be also synced + if (getTitle(lyr as Layer) != 'Point clicked') { + this.linkOlSourceToCesiumDatasource( + (lyr as VectorLayer).getSource(), + cesium_layer, ); - this.viewer.imageryLayers.add(cesium_layer); - } else if ( - (this.HsUtilsService.instOf(cesium_layer, GeoJsonDataSource) || - this.HsUtilsService.instOf(cesium_layer, KmlDataSource)) && - this.viewer.dataSources - ) { - this.viewer.dataSources.add(cesium_layer); - //TODO: Point clicked, Datasources extents, Composition extents shall be also synced - if (getTitle(lyr as Layer) != 'Point clicked') { - this.linkOlSourceToCesiumDatasource( - (lyr as VectorLayer).getSource(), - cesium_layer, - ); - } } } } @@ -439,7 +440,7 @@ export class HsCesiumLayersService { if (this.HsUtilsService.instOf(layerSource, OSM)) { return new ImageryLayer(new OpenStreetMapImageryProvider({}), { show: olLayer.getVisible(), - minimumTerrainLevel: getMinimumTerrainLevel(olLayer) || 15, + minimumTerrainLevel: getMinimumTerrainLevel(olLayer) || 1, }); } else if (this.HsUtilsService.instOf(layerSource, XYZ)) { return new ImageryLayer( @@ -471,13 +472,10 @@ export class HsCesiumLayersService { async createVectorDataSource( ol_lyr: VectorLayer, ): Promise { - if ( - ol_lyr.getSource().getFormat() && - this.HsUtilsService.instOf(ol_lyr.getSource().getFormat(), KML) - ) { + if (this.HsUtilsService.instOf(ol_lyr?.getSource()?.getFormat(), KML)) { if (this.HsUtilsService.isFunction(ol_lyr.getSource().getUrl())) { this.hsLog.warn( - 'FeatureUrlFunction is currently not supported in synchronizing features from Ol layer to Cesium', + 'FeatureUrlFunction is currently not supported in synchronizing features from OL layer to Cesium', ); return; } @@ -489,7 +487,7 @@ export class HsCesiumLayersService { }); } else { const new_source = new GeoJsonDataSource(getTitle(ol_lyr)); - //link to cesium layer will be set also for OL layers source object, when this function returns. + //link to Cesium layer will be set also for OL layers source object, when this function returns. this.ol2CsMappings.push({ olObject: ol_lyr, csObject: new_source,