Skip to content

Commit

Permalink
fix(add-data): WMS sublayer extent parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner committed Aug 28, 2024
1 parent f713949 commit b732d41
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 37 deletions.
77 changes: 45 additions & 32 deletions projects/hslayers/services/add-data/url/add-data-url.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ export class HsAddDataUrlService {
records?.some((l) => l.checked) ?? this.typeSelected == 'arcgis';
}

/**
* Display layers extent parsing error
*/
private layerExtentParsingError(): void {
this.hsToastService.createToastPopupMessage(
'ADDLAYERS.capabilitiesParsingProblem',
'ADDLAYERS.layerExtentParsingProblem',
{
serviceCalledFrom: 'HsAddDataUrlService',
toastStyleClasses: 'bg-warning text-white',
},
);
}

/**
* Calculate cumulative bounding box which encloses all the provided layers (service layer definitions)
* Common for WMS/WMTS (WFS has its own implementation)
Expand All @@ -117,17 +131,10 @@ export class HsAddDataUrlService {
return undefined;
}
try {
const layerExtents = layers.map((lyr) => [...lyr?.getExtent()]); //Spread need to not create reference
const layerExtents = layers.map((lyr) => [...(lyr?.getExtent() || [])]); //Spread need to not create reference
return this.calcCombinedExtent(layerExtents);
} catch (error) {
this.hsToastService.createToastPopupMessage(
'ADDLAYERS.capabilitiesParsingProblem',
'ADDLAYERS.layerExtentParsingProblem',
{
serviceCalledFrom: 'HsAddDataUrlService',
toastStyleClasses: 'bg-warning text-white',
},
);
this.layerExtentParsingError();
return undefined;
}
}
Expand All @@ -136,30 +143,36 @@ export class HsAddDataUrlService {
* For given array of layers (service layer definitions) it calculates a cumulative bounding box which encloses all the layers
*/
calcCombinedExtent(extents: number[][]): number[] {
const currentMapProj = this.hsMapService.getCurrentProj();
const bounds = transform([180, 90], 'EPSG:4326', currentMapProj);
try {
const currentMapProj = this.hsMapService.getCurrentProj();
const bounds = transform([180, 90], 'EPSG:4326', currentMapProj);

return extents.reduce((acc, curr) => {
//some services define layer bboxes beyond the canonical 180/90 degrees intervals, the checks are necessary then
const [west, south, east, north] = curr;
//minimum easting
if (bounds[1] * -1 <= west && west < acc[0]) {
acc[0] = west;
}
//minimum northing
if (bounds[0] * -1 <= south && south < acc[1]) {
acc[1] = south;
}
//maximum easting
if (bounds[1] >= east && east > acc[2]) {
acc[2] = east;
}
//maximum northing
if (bounds[0] >= north && north > acc[3]) {
acc[3] = north;
}
return acc;
});
const extent = extents.reduce((acc, curr) => {
//some services define layer bboxes beyond the canonical 180/90 degrees intervals, the checks are necessary then
const [west, south, east, north] = curr;
//minimum easting
if (bounds[1] * -1 <= west && west < acc[0]) {
acc[0] = west;
}
//minimum northing
if (bounds[0] * -1 <= south && south < acc[1]) {
acc[1] = south;
}
//maximum easting
if (bounds[1] >= east && east > acc[2]) {
acc[2] = east;
}
//maximum northing
if (bounds[0] >= north && north > acc[3]) {
acc[3] = north;
}
return acc;
});
return extent.length > 0 ? extent : undefined;
} catch (error) {
this.layerExtentParsingError();
return undefined;
}
}

/**
Expand Down
18 changes: 13 additions & 5 deletions projects/hslayers/services/add-data/url/wms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ export class HsUrlWmsService implements HsUrlTypeServiceModel {
* Get extent for a single layer
*/
private getSingleLayerExtent(serviceLayer: any, crs: string) {
/**
* serviceLayer might be undefined when trying to parse extent of WMS sublayer
* while creating layer. Will be added along with metadata parsing
*/
if (!serviceLayer) {
return;
}
let boundingbox = serviceLayer.BoundingBox;
if (
crs !== undefined &&
Expand Down Expand Up @@ -498,18 +505,19 @@ export class HsUrlWmsService implements HsUrlTypeServiceModel {
),
this.hsMapService.getCurrentProj(),
),
/**
* Control preventing duplicated extent parsing
* during capability attributes parsing
*/
capsExtentSet: true,
path: options.path,
dimensions: dimensions,
legends: legends,
subLayers: options.subLayers,
base: this.data.base,
visible: this.data.visible,
};
/**
* Control preventing duplicated extent parsing
* during capability attributes parsing
*/
layerOptions['capsExtentSet'] = !!layerOptions.extent;

const new_layer = USE_TILES
? new Tile(layerOptions as TileOptions<TileSource>)
: new ImageLayer(layerOptions as ImageOptions<ImageSource>);
Expand Down
3 changes: 3 additions & 0 deletions projects/hslayers/services/utils/layer-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ export class HsLayerUtilsService {
* NOTE: Not using OL because we want to extend width and height independently
*/
bufferExtent(extent: Extent, currentMapProj: Projection) {
if (!extent) {
return undefined;
}
//EPSG:4087 world bounds
const [pMinX, pMinY, pMaxX, pMaxY] = [
-20037508.342789, -10018754.171394, 20037508.342789, 10018754.171394,
Expand Down

0 comments on commit b732d41

Please sign in to comment.