Skip to content

Commit

Permalink
fix(feature info): repairs feature info for geocore layers
Browse files Browse the repository at this point in the history
Closes #2593
Closes #2210
Closes #563
  • Loading branch information
DamonU2 committed Dec 10, 2024
1 parent b9f0335 commit c3abc28
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,20 @@ export const getSxClasses = (theme: Theme): SxStyles => ({
featureInfoItemValue: {
marginRight: 0,
wordBreak: 'break-word',
overflow: 'hidden',
overflowX: 'auto',
textOverflow: 'ellipsis',
' table': {
border: '1px solid',
width: '100%',
borderCollapse: 'collapse',
},
' th, td': {
border: '1px solid',
wordBreak: 'normal',
textAllign: 'center',
padding: '5px',
whiteSpace: 'nowrap',
},
},
boxContainerFeatureInfo: {
wordWrap: 'break-word',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export function FeatureInfoTable({ featureInfoList }: FeatureInfoTableProps): JS
function setFeatureItem(featureInfoItem: TypeFieldEntry): JSX.Element | JSX.Element[] {
function process(item: string, alias: string, index: number): JSX.Element {
let element: JSX.Element;
if (typeof item === 'string' && isImage(item)) {
if (alias === 'html') {
element = (
<Box key={generateId()} sx={sxClasses.featureInfoItemValue}>
<HtmlToReact htmlContent={sanitizeHtmlContent(item)} />
</Box>
);
} else if (typeof item === 'string' && isImage(item)) {
element = (
<CardMedia
key={generateId()}
Expand Down Expand Up @@ -89,7 +95,9 @@ export function FeatureInfoTable({ featureInfoList }: FeatureInfoTableProps): JS

const { alias, value } = featureInfoItem;
let values: string | string[] = Array.isArray(value) ? String(value.map(stringify)) : String(stringify(value));
values = values.toString().split(';');
// Split text but leave html intact
if (alias !== 'html') values = values.toString().split(';');

const results = Array.isArray(values)
? values.map((item: string, index: number) => process(item, alias, index))
: process(values, alias, 0);
Expand All @@ -110,9 +118,11 @@ export function FeatureInfoTable({ featureInfoList }: FeatureInfoTableProps): JS
}}
key={`${featureInfoItem.alias} ${index.toString()}`}
>
<Grid size={{ xs: 'auto' }} sx={{ fontWeight: 'bold', width: '80% !important' }}>
{featureInfoItem.alias}
</Grid>
{featureInfoItem.alias !== 'html' && (
<Grid size={{ xs: 'auto' }} sx={{ fontWeight: 'bold', width: '80% !important' }}>
{featureInfoItem.alias}
</Grid>
)}
<Grid sx={{ ml: 'auto', wordWrap: 'break-word', pr: '0.3125rem' }}>{setFeatureItem(featureInfoItem)}</Grid>
</Grid>
))}
Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/core/utils/date-mgt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ export abstract class DateMgt {
if (index[SECOND_DATE_ELEMENT] + 1) returnValue = `${returnValue}${dateFragments[index[SECOND_DATE_ELEMENT]]}`;
if (returnValue && index[THIRD_DATE_ELEMENT] + 1) returnValue = `${returnValue}${separators[DATE]}`;
if (index[THIRD_DATE_ELEMENT] + 1) returnValue = `${returnValue}${dateFragments[index[THIRD_DATE_ELEMENT]]}`;
if (index[TIME] + 1) returnValue = `${returnValue}${separators[DATE_TIME]}${timeString.slice(0, 8)}`;
if (index[TIME] + 1 && timeString) returnValue = `${returnValue}${separators[DATE_TIME]}${timeString.slice(0, 8)}`;

return returnValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ export abstract class AbstractGVLayer extends AbstractBaseLayer {
// Get the layer config
const layerConfig = this.getLayerConfig();

// If queryable
if (!layerConfig.source?.featureInfo?.queryable) {
// If the layer is not queryable
// GV: This should always be set by now. There were instances where that was not happeneing, recheck once config API is being used
if (layerConfig.source?.featureInfo?.queryable === false) {
logger.logError(`Layer at path ${layerConfig.layerPath} is not queryable`);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ export class GVEsriDynamic extends AbstractGVRaster {
const layerConfig = this.getLayerConfig();

// If not queryable
if (!layerConfig.source?.featureInfo?.queryable) return [];
if (!layerConfig.source.featureInfo?.queryable) return [];

let identifyUrl = layerConfig.source?.dataAccessPath;
let identifyUrl = layerConfig.source.dataAccessPath;
if (!identifyUrl) return [];

identifyUrl = identifyUrl.endsWith('/') ? identifyUrl : `${identifyUrl}/`;
Expand Down
20 changes: 19 additions & 1 deletion packages/geoview-core/src/geo/layer/gv-layers/raster/gv-wms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TypeFeatureInfoEntry } from '@/geo/map/map-schema-types';
import { loadImage } from '@/geo/utils/renderer/geoview-renderer';
import { AbstractGVRaster } from './abstract-gv-raster';
import { TypeLegend } from '@/core/stores/store-interface-and-intial-values/layer-state';
import { Projection } from '@/geo/utils/projection';

/**
* Manages a WMS layer.
Expand Down Expand Up @@ -117,6 +118,18 @@ export class GVWMS extends AbstractGVRaster {
// Get the layer config and source
const layerConfig = this.getLayerConfig();

// Check if bounds are properly set
if (!layerConfig.initialSettings!.bounds) {
const newBounds = this.getBounds(this.getLayerPath());
if (newBounds)
layerConfig.initialSettings!.bounds = Projection.transformExtentFromProj(
newBounds,
this.getMapViewer().getView().getProjection(),
Projection.PROJECTION_NAMES.LNGLAT
);
else return [];
}

const clickCoordinate = this.getMapViewer().convertCoordinateLngLatToMapProj(lnglat);
if (
lnglat[0] < layerConfig.initialSettings!.bounds![0] ||
Expand All @@ -130,8 +143,9 @@ export class GVWMS extends AbstractGVRaster {
const featureInfoFormat = this.getLayerConfig().getServiceMetadata()?.Capability?.Request?.GetFeatureInfo?.Format as TypeJsonArray;
if (featureInfoFormat)
if (featureInfoFormat.includes('text/xml' as TypeJsonObject)) infoFormat = 'text/xml';
else if (featureInfoFormat.includes('text/html' as TypeJsonObject)) infoFormat = 'text/html';
else if (featureInfoFormat.includes('text/plain' as TypeJsonObject)) infoFormat = 'text/plain';
else throw new Error('Parameter info_format of GetFeatureInfo only support text/xml and text/plain for WMS services.');
else throw new Error('Parameter info_format of GetFeatureInfo only support text/xml, text/html and text/plain for WMS services.');

const wmsSource = this.getOLSource();
const viewResolution = this.getMapViewer().getView().getResolution()!;
Expand Down Expand Up @@ -166,12 +180,16 @@ export class GVWMS extends AbstractGVRaster {
}
}
}
} else if (infoFormat === 'text/html') {
featureMember = { html: response.data };
} else featureMember = { plain_text: { '#text': response.data } };

if (featureMember) {
const featureInfoResult = GVWMS.#formatWmsFeatureInfoResult(featureMember, clickCoordinate);
return featureInfoResult;
}
}

return [];
} catch (error) {
// Log
Expand Down
2 changes: 1 addition & 1 deletion packages/geoview-core/src/geo/layer/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export class LayerApi {
const newOrderedLayerInfos: TypeOrderedLayerInfo[] = [];

const addSubLayerPathToLayerOrder = (layerEntryConfig: TypeLayerEntryConfig, layerPath: string): void => {
const subLayerPath = layerPath.endsWith(layerEntryConfig.layerId) ? layerPath : `${layerPath}/${layerEntryConfig.layerId}`;
const subLayerPath = layerPath.endsWith(`/${layerEntryConfig.layerId}`) ? layerPath : `${layerPath}/${layerEntryConfig.layerId}`;
const layerInfo: TypeOrderedLayerInfo = {
layerPath: subLayerPath,
visible: layerEntryConfig.initialSettings?.states?.visible !== false,
Expand Down

0 comments on commit c3abc28

Please sign in to comment.