Skip to content

Commit

Permalink
Merge pull request #144 from stuartwoodman/AUS-4018-Allow-CSW-Records…
Browse files Browse the repository at this point in the history
…-to-Zoom-On-Load

AUS-4018 CSW records initial zoom
  • Loading branch information
vjf authored Nov 13, 2024
2 parents d9da2d9 + 7ab5331 commit cb710e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { CsGeoJsonService } from '../geojson/cs-geojson.service';
Expand Down Expand Up @@ -247,6 +248,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 = [];
Expand Down Expand Up @@ -305,6 +307,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 });
}
}

}

/**
Expand Down
29 changes: 0 additions & 29 deletions projects/portal-core-ui/src/lib/service/wms/cs-wms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -418,41 +417,13 @@ 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
Expand Down

0 comments on commit cb710e3

Please sign in to comment.