From 83ad1545d6caaec17de26b3ad089c9bf96081847 Mon Sep 17 00:00:00 2001 From: "stuart.woodman" Date: Tue, 15 Oct 2024 15:51:20 +1100 Subject: [PATCH 1/2] Shifted code so all resource types zoom to initialBbox on layer load. --- .../lib/service/cesium-map/cs-map.service.ts | 26 +++++++++++++- .../src/lib/service/wms/cs-wms.service.ts | 36 ++----------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/projects/portal-core-ui/src/lib/service/cesium-map/cs-map.service.ts b/projects/portal-core-ui/src/lib/service/cesium-map/cs-map.service.ts index 79ead6b..9f8b2f9 100644 --- a/projects/portal-core-ui/src/lib/service/cesium-map/cs-map.service.ts +++ b/projects/portal-core-ui/src/lib/service/cesium-map/cs-map.service.ts @@ -15,7 +15,8 @@ import { CsKMLService } from '../kml/cs-kml.service'; import { CsVMFService } from '../vmf/cs-vmf.service'; import { MapsManagerService, RectangleEditorObservable, EventRegistrationInput, CesiumEvent, EventResult } from '@auscope/angular-cesium'; import { Entity, ProviderViewModel, buildModuleUrl, OpenStreetMapImageryProvider, BingMapsStyle, BingMapsImageryProvider, - ArcGisMapServerImageryProvider, Cartesian2, WebMercatorProjection, SplitDirection } from 'cesium'; + ArcGisMapServerImageryProvider, Cartesian2, WebMercatorProjection, SplitDirection, + Rectangle} from 'cesium'; import { UtilitiesService } from '../../utility/utilities.service'; import ImageryLayerCollection from 'cesium/Source/Scene/ImageryLayerCollection'; declare var Cesium: any; @@ -220,6 +221,7 @@ export class CsMapService { * @param layer the layer to add to the map */ public addLayer(layer: LayerModel, param: any): void { + layer.initialLoad = true; // initiate csLayers to prevent undefined errors if (!layer.csLayers) { layer.csLayers = []; @@ -274,6 +276,28 @@ export class CsMapService { } else { throw new Error('No Suitable service found'); } + + // Zoom to initialBBox if one has been set + if (layer["geojson"]) { + if (layer["geojson"]["bbox"]) { + let lon1 = 0, lon2 = 0, lat1 = 0, lat2 = 0 + const bbox = layer["geojson"]["bbox"]; + let i = 0; + for (const coord of bbox) { + if (i == 0) { + lon1 = parseFloat(coord[0]); + lat1 = parseFloat(coord[1]); + } else { + lon2 = parseFloat(coord[0]); + lat2 = parseFloat(coord[1]); + } + i = i + 1; + } + const bboxDataset = Rectangle.fromDegrees(lon1, lat1, lon2, lat2); + this.map.getCameraService().cameraFlyTo({ destination: bboxDataset }); + } + } + } /** diff --git a/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts b/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts index e1264c5..9a1a75a 100644 --- a/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts +++ b/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts @@ -343,7 +343,6 @@ export class CsWMSService { * @param param request parameters */ public addLayer(layer: LayerModel, param?: any): void { - layer.initialLoad = true; // Any running sldSubscriptions should have been stopped in rmLayer this.sldSubscriptions[layer.id] = []; if (!param) { @@ -418,41 +417,12 @@ export class CsWMSService { private addCesiumLayer(layer, wmsOnlineResource, params, usePost: boolean, lonlatextent): ImageryLayer { const browserInfo = this.deviceService.getDeviceInfo(); const viewer = this.map.getCesiumViewer(); - const cameraService = this.map.getCameraService(); - const me = this; if (UtilitiesService.layerContainsResourceType(layer, ResourceType.WMS)) { // WMS tile loading callback function, numLeft = number of tiles left to load const tileLoading = (numLeft: number) => { if (numLeft === 0) { // When there are no more tiles to load it is complete this.renderStatusService.updateComplete(layer, wmsOnlineResource); - if (layer.initialLoad) { - - // zoom to the given bounding box from layers.yaml - if (layer["geojson"]) { - if (layer["geojson"]["bbox"]) { - - var lon1 = 0, lon2 = 0, lat1 = 0, lat2 = 0 - const bbox = layer["geojson"]["bbox"]; - var i = 0; - for (const coord of bbox) { - if (i == 0) { - lon1 = parseFloat(coord[0]); - lat1 = parseFloat(coord[1]); - } else { - lon2 = parseFloat(coord[0]); - lat2 = parseFloat(coord[1]); - } - i = i + 1; - } - - const bboxDataset = Rectangle.fromDegrees(lon1, lat1, lon2, lat2); - cameraService.cameraFlyTo({ destination: bboxDataset }); - } - } - layer.initialLoad = false; - - } } }; // Register tile loading callback function @@ -499,10 +469,10 @@ export class CsWMSService { postForm.append('url', val.split('?')[0] + '?service=WMS'); const kvp = val.split('?')[1]; if (kvp) { - me.paramSubst(kvp.split('=')[0], kvp.split('=')[1], postForm); + this.paramSubst(kvp.split('=')[0], kvp.split('=')[1], postForm); } } else { - me.paramSubst(key, val, postForm); + this.paramSubst(key, val, postForm); } }); @@ -549,7 +519,7 @@ export class CsWMSService { /* End of 'createImage' overwrite */ // Create a resource which uses our custom proxy - const proxyUrl = me.env.portalBaseUrl + Constants.PROXY_API + '?usewhitelist=' + (layer.useProxyWhitelist ? 'true' : 'false') + '&url='; + const proxyUrl = this.env.portalBaseUrl + Constants.PROXY_API + '?usewhitelist=' + (layer.useProxyWhitelist ? 'true' : 'false') + '&url='; const res = new Resource({ url: url, proxy: new MyDefaultProxy(proxyUrl) }); // Force Resource to use 'POST' and our proxy From 7ab53311930d4c524e876ea545c5bedbd9c662a0 Mon Sep 17 00:00:00 2001 From: "stuart.woodman" Date: Thu, 14 Nov 2024 09:11:06 +1100 Subject: [PATCH 2/2] Revert "this" to "me" as "this" won't work in all cases. --- .../portal-core-ui/src/lib/service/wms/cs-wms.service.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts b/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts index 9a1a75a..0af683c 100644 --- a/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts +++ b/projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts @@ -417,6 +417,7 @@ export class CsWMSService { private addCesiumLayer(layer, wmsOnlineResource, params, usePost: boolean, lonlatextent): ImageryLayer { const browserInfo = this.deviceService.getDeviceInfo(); const viewer = this.map.getCesiumViewer(); + const me = this; if (UtilitiesService.layerContainsResourceType(layer, ResourceType.WMS)) { // WMS tile loading callback function, numLeft = number of tiles left to load const tileLoading = (numLeft: number) => { @@ -469,10 +470,10 @@ export class CsWMSService { postForm.append('url', val.split('?')[0] + '?service=WMS'); const kvp = val.split('?')[1]; if (kvp) { - this.paramSubst(kvp.split('=')[0], kvp.split('=')[1], postForm); + me.paramSubst(kvp.split('=')[0], kvp.split('=')[1], postForm); } } else { - this.paramSubst(key, val, postForm); + me.paramSubst(key, val, postForm); } }); @@ -519,7 +520,7 @@ export class CsWMSService { /* End of 'createImage' overwrite */ // Create a resource which uses our custom proxy - const proxyUrl = this.env.portalBaseUrl + Constants.PROXY_API + '?usewhitelist=' + (layer.useProxyWhitelist ? 'true' : 'false') + '&url='; + const proxyUrl = me.env.portalBaseUrl + Constants.PROXY_API + '?usewhitelist=' + (layer.useProxyWhitelist ? 'true' : 'false') + '&url='; const res = new Resource({ url: url, proxy: new MyDefaultProxy(proxyUrl) }); // Force Resource to use 'POST' and our proxy