From 82f3e051311cb923d7ab78d8f6c3ac119206aae6 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 219eadc936..0d86cae8c2 100644 --- a/projects/hslayers-cesium/src/hscesium-layers.service.ts +++ b/projects/hslayers-cesium/src/hscesium-layers.service.ts @@ -185,7 +185,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); } @@ -199,7 +199,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); } }); @@ -409,26 +409,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, - ); - } } } } @@ -441,7 +442,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( @@ -473,13 +474,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; } @@ -491,7 +489,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,