Skip to content

Commit

Permalink
fix(geocore): fixed errors with sublayers showing as loading endlessly
Browse files Browse the repository at this point in the history
Also fixes issues with legend not loading
Closes #2689
  • Loading branch information
DamonU2 committed Jan 22, 2025
1 parent 462a956 commit ea5922c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ const IconStack = memo(function IconStack({ layerPath, onIconClick, onStackIconC
export const LayerIcon = memo(function LayerIcon({ layer }: LayerIconProps): JSX.Element {
const isError = layer.layerStatus === 'error' || ('queryStatus' in layer && layer.queryStatus === 'error');

const isLoading =
layer.layerStatus === 'processing' || layer.layerStatus === 'loading' || ('queryStatus' in layer && layer.queryStatus === 'processing');
const isLoading = layer.layerStatus !== 'loaded' && layer.layerStatus !== 'error';

const hasChildren = 'children' in layer && layer?.children.length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ export function commonProcessInitialSettings(
] as Extent;

// Transform to latlon extent
const latlonExtent = Projection.transformExtentFromObj(
layerExtent,
layerMetadata.extent.spatialReference,
Projection.PROJECTION_NAMES.LNGLAT
);
layerConfig.initialSettings!.bounds = latlonExtent;
if (layerExtent) {
const latlonExtent = Projection.transformExtentFromObj(
layerExtent,
layerMetadata.extent.spatialReference,
Projection.PROJECTION_NAMES.LNGLAT
);
layerConfig.initialSettings!.bounds = latlonExtent;
}
}
layerConfig.initialSettings!.bounds = validateExtent(layerConfig.initialSettings!.bounds);

layerConfig.initialSettings!.bounds = validateExtent(layerConfig.initialSettings!.bounds || [-180, -90, 180, 90]);
}

/** ***************************************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,13 +855,14 @@ export class GVEsriDynamic extends AbstractGVRaster {
const responseJson = await response.json();
const { extent } = responseJson;

const projExtent = Projection.transformExtentFromProj(
[extent.xmin, extent.ymin, extent.xmax, extent.ymax],
`EPSG:${extent.spatialReference.wkid}`,
this.getMapViewer().getProjection().getCode()
);

return projExtent;
if (extent) {
const projExtent = Projection.transformExtentFromProj(
[extent.xmin, extent.ymin, extent.xmax, extent.ymax],
`EPSG:${extent.spatialReference.wkid}`,
this.getMapViewer().getProjection().getCode()
);
return validateExtent(projExtent, this.getMapViewer().getProjection().getCode());
}
} catch (error) {
logger.logError(`Error fetching geometry from ${queryUrl}`, error);
}
Expand Down
15 changes: 12 additions & 3 deletions packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,17 @@ export class LayerApi {
gvLayer.onIndividualLayerLoaded((sender, payload) => {
// Log
logger.logDebug(`${payload.layerPath} loaded on map ${this.getMapId()}`);

const legendLayerInfo = LegendEventProcessor.getLegendLayerInfo(this.getMapId(), payload.layerPath);
// Ensure that the layer bounds are set when the layer is loaded
if (legendLayerInfo && !legendLayerInfo.bounds) LegendEventProcessor.getLayerBounds(this.getMapId(), payload.layerPath);

this.#emitLayerLoaded({ layer: sender, layerPath: payload.layerPath });
});

return gvLayer.getOLLayer();
}

throw new Error('Error, no corresponding GV layer');
});

Expand Down Expand Up @@ -1627,9 +1634,11 @@ export class LayerApi {
// Get the layer
const layer = this.getGeoviewLayer(layerConfig.layerPath) as AbstractGVLayer;

// Get the bounds of the layer
const calculatedBounds = layer.getBounds();
if (calculatedBounds) bounds.push(calculatedBounds);
if (layer) {
// Get the bounds of the layer
const calculatedBounds = layer.getBounds();
if (calculatedBounds) bounds.push(calculatedBounds);
}
} else {
// Is a group
layerConfig.listOfLayerEntryConfig.forEach((subLayerConfig) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/geoview-core/src/geo/utils/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export abstract class Projection {
* @returns The new extent transformed in the destination projection.
*/
static transformExtentFromProj(extent: Extent, source: ProjectionLike, destination: ProjectionLike, stops?: number | undefined): Extent {
// This is included for certain outliers.
// TODO Refactor: invalid extents should be handled before this point, test and remove - 5a65ad7c-561a-466a-8375-8d876624df9d
if (typeof extent[0] !== 'number')
return olTransformExtent([-180, 90, 180, 90], Projection.PROJECTION_NAMES.LNGLAT, destination, stops);
// Project
return olTransformExtent(extent, source, destination, stops);
}
Expand Down
26 changes: 13 additions & 13 deletions packages/geoview-core/src/geo/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,19 @@ export function validateExtent(extent: Extent, code: string = 'EPSG:4326'): Exte
'EPSG:3978': [-7192737.96, -3004297.73, 5183275.29, 4484204.83],
};

// Replace any invalid entries with maximum value
const minX = extent[0] < maxExtents[code][0] || extent[0] === -Infinity || Number.isNaN(extent[0]) ? maxExtents[code][0] : extent[0];
const minY = extent[1] < maxExtents[code][1] || extent[1] === -Infinity || Number.isNaN(extent[1]) ? maxExtents[code][1] : extent[1];
const maxX = extent[2] > maxExtents[code][2] || extent[2] === Infinity || Number.isNaN(extent[2]) ? maxExtents[code][2] : extent[2];
const maxY = extent[3] > maxExtents[code][3] || extent[3] === Infinity || Number.isNaN(extent[3]) ? maxExtents[code][3] : extent[3];

// Check the order
const validatedExtent: Extent = [
minX < maxX ? minX : maxX,
minY < maxY ? minY : maxY,
maxX > minX ? maxX : minX,
maxY > minY ? maxY : minY,
];
let validatedExtent: Extent;
// In rare cases, services return 'NaN' as extents, not picked up by Number.isNan
if (typeof extent[0] !== 'number') validatedExtent = maxExtents[code];
else {
// Replace any invalid entries with maximum value
const minX = extent[0] < maxExtents[code][0] || extent[0] === -Infinity || Number.isNaN(extent[0]) ? maxExtents[code][0] : extent[0];
const minY = extent[1] < maxExtents[code][1] || extent[1] === -Infinity || Number.isNaN(extent[1]) ? maxExtents[code][1] : extent[1];
const maxX = extent[2] > maxExtents[code][2] || extent[2] === Infinity || Number.isNaN(extent[2]) ? maxExtents[code][2] : extent[2];
const maxY = extent[3] > maxExtents[code][3] || extent[3] === Infinity || Number.isNaN(extent[3]) ? maxExtents[code][3] : extent[3];

// Check the order
validatedExtent = [minX < maxX ? minX : maxX, minY < maxY ? minY : maxY, maxX > minX ? maxX : minX, maxY > minY ? maxY : minY];
}

return validatedExtent;
}
Expand Down

0 comments on commit ea5922c

Please sign in to comment.