Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[feat] wms layer improvements (#3151)
Igor Dykhta343b554dbfa6
diff --git a/src/actions/src/action-types.ts b/src/actions/src/action-types.tsindex 2d4c55f9a..1d934484c 100644--- a/src/actions/src/action-types.ts+++ b/src/actions/src/action-types.ts@@ -148,6 +148,7 @@ export const ActionTypes = {REMOVE_NOTIFICATION: `${ACTION_PREFIX}REMOVE_NOTIFICATION`,SET_LOCALE: `${ACTION_PREFIX}SET_LOCALE`,LAYER_FILTERED_ITEMS_CHANGE: `${ACTION_PREFIX}LAYER_FILTERED_ITEMS_CHANGE`,+ WMS_FEATURE_INFO: `${ACTION_PREFIX}WMS_FEATURE_INFO`,SYNC_TIME_FILTER_WITH_LAYER_TIMELINE: `${ACTION_PREFIX}SYNC_TIME_FILTER_WITH_LAYER_TIMELINE`,SYNC_TIME_FILTER_TIMELINE_MODE: `${ACTION_PREFIX}SYNC_TIME_FILTER_TIMELINE_MODE`,TOGGLE_PANEL_LIST_VIEW: `${ACTION_PREFIX}TOGGLE_PANEL_LIST_VIEW`,diff --git a/src/actions/src/vis-state-actions.ts b/src/actions/src/vis-state-actions.tsindex b8bd3ccc5..91556fa69 100644--- a/src/actions/src/vis-state-actions.ts+++ b/src/actions/src/vis-state-actions.ts@@ -1629,6 +1629,33 @@ export function layerFilteredItemsChange(};}+export type WMSFeatureInfoAction = {+ layer: Layer;+ featureInfo: Array<{name: string; value: string}> | string | null;+ coordinate?: [number, number] | null;+};++/**+ * WMS layer feature info callback+ * @memberof visStateActions+ * @param layer+ * @param featureInfo+ * @param coordinate+ * @return action+ */+export function wmsFeatureInfo(+ layer: WMSFeatureInfoAction['layer'],+ featureInfo: WMSFeatureInfoAction['featureInfo'],+ coordinate?: WMSFeatureInfoAction['coordinate']+): Merge<WMSFeatureInfoAction, {type: typeof ActionTypes.WMS_FEATURE_INFO}> {+ return {+ type: ActionTypes.WMS_FEATURE_INFO,+ layer,+ featureInfo,+ coordinate+ };+}+export type SyncTimeFilterWithLayerTimelineAction = {idx: number;enable: boolean;diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsxindex 05bcc2d35..36c4ff235 100644--- a/src/components/src/map-container.tsx+++ b/src/components/src/map-container.tsx@@ -526,6 +526,20 @@ export default function MapContainerFactory(this.props.visStateActions.layerFilteredItemsChange(this.props.visState.layers[idx], event);};+ _onWMSFeatureInfo = (+ idx: number,+ data: {+ featureInfo: Array<{name: string; value: string}> | string | null;+ coordinate?: [number, number] | null;+ }+ ) => {+ this.props.visStateActions.wmsFeatureInfo(+ this.props.visState.layers[idx],+ data.featureInfo,+ data.coordinate+ );+ };+_handleMapToggleLayer = layerId => {const {index: mapIndex = 0, visStateActions} = this.props;visStateActions.toggleLayerForMap(mapIndex, layerId);@@ -823,7 +837,8 @@ export default function MapContainerFactory({onLayerHover: this._onLayerHover,onSetLayerDomain: this._onLayerSetDomain,- onFilteredItemsChange: this._onLayerFilteredItemsChange+ onFilteredItemsChange: this._onLayerFilteredItemsChange,+ onWMSFeatureInfo: this._onWMSFeatureInfo},deckGlProps);diff --git a/src/components/src/map/layer-hover-info.tsx b/src/components/src/map/layer-hover-info.tsxindex cd0a93180..2562ac877 100644--- a/src/components/src/map/layer-hover-info.tsx+++ b/src/components/src/map/layer-hover-info.tsx@@ -138,22 +138,37 @@ const EntryInfoRow: React.FC<EntryInfoRowProps> = ({const field = fields[fieldIdx];const fieldValueAccessor = layer.accessVSFieldValue(field, currentTime);const value = fieldValueAccessor(field, data instanceof DataRow ? {index: data._rowIndex} : data);- const primaryValue = primaryData- ? fieldValueAccessor(- field,- primaryData instanceof DataRow ? {index: primaryData._rowIndex} : primaryData- )- : null;- const displayValue = getTooltipDisplayValue({item, field, value});- const displayDeltaValue = primaryData- ? getTooltipDisplayDeltaValue({- field,- value,- primaryValue,- compareType- })- : null;+ // Handle WMS layer data in comparison mode - WMS layers don't have comparable field data+ let primaryValue = null;+ let displayDeltaValue: string | null = null;++ if (primaryData) {+ try {+ // Only calculate primary value if primaryData has a compatible structure+ if (+ primaryData instanceof DataRow ||+ (primaryData && typeof primaryData === 'object' && 'index' in primaryData)+ ) {+ primaryValue = fieldValueAccessor(+ field,+ primaryData instanceof DataRow ? {index: primaryData._rowIndex} : primaryData+ );++ displayDeltaValue = getTooltipDisplayDeltaValue({+ field,+ value,+ primaryValue,+ compareType+ });+ }+ } catch (error) {+ // If there's an error accessing primaryData (e.g., WMS layer data), skip comparison+ primaryValue = null;+ }+ }++ const displayValue = getTooltipDisplayValue({item, field, value});return (<Row@@ -236,6 +251,7 @@ const LayerHoverInfoFactory = () => {const hasFieldsToShow =(data.fieldValues && Object.keys(data.fieldValues).length > 0) ||+ (data.wmsFeatureData && data.wmsFeatureData.length > 0) ||(props.fieldsToShow && props.fieldsToShow.length > 0);return (@@ -246,7 +262,13 @@ const LayerHoverInfoFactory = () => {</StyledLayerName>{hasFieldsToShow && <StyledDivider />}<StyledTable>- {data.fieldValues ? (+ {data.wmsFeatureData ? (+ <tbody>+ {data.wmsFeatureData.map(({name, value}, i) => (+ <Row key={i} name={name} value={value} />+ ))}+ </tbody>+ ) : data.fieldValues ? (<tbody>{data.fieldValues.map(({labelMessage, value}, i) => (<Row key={i} name={intl.formatMessage({id: labelMessage})} value={value} />diff --git a/src/deckgl-layers/src/wms/wms-layer.ts b/src/deckgl-layers/src/wms/wms-layer.tsindex 888a620cc..1b20e216c 100644--- a/src/deckgl-layers/src/wms/wms-layer.ts+++ b/src/deckgl-layers/src/wms/wms-layer.ts@@ -130,7 +130,8 @@ export default class WMSLayer extends CompositeLayer<Required<_WMSLayerProps>> {? COORDINATE_SYSTEM.LNGLAT: COORDINATE_SYSTEM.CARTESIAN,bounds,- image+ image,+ pickable: this.props.pickable}));}diff --git a/src/layers/src/wms-layer/wms-layer.ts b/src/layers/src/wms-layer/wms-layer.tsindex 4e101d461..2f38ff943 100644--- a/src/layers/src/wms-layer/wms-layer.ts+++ b/src/layers/src/wms-layer/wms-layer.ts@@ -21,6 +21,8 @@ import {DatasetType, WMSDatasetMetadata, LAYER_TYPES} from '@kepler.gl/constantsimport {notNullorUndefined} from '@kepler.gl/common-utils';import {WMSLayer as DeckWMSLayer} from '@kepler.gl/deckgl-layers';import {KeplerTable as KeplerDataset} from '@kepler.gl/table';+import {DataContainerInterface} from '@kepler.gl/utils';+import {AnimationConfig} from '@kepler.gl/types';// Typesexport type WMSTile = {@@ -40,6 +42,7 @@ export type WMSLayerVisConfig = {name: string;title: string;boundingBox: number[][];+ queryable: boolean;} | null;};@@ -65,6 +68,9 @@ export default class WMSLayer extends AbstractTileLayer<WMSTile, any[]> {declare config: WMSLayerConfig;declare visConfigSettings: WMSLayerVisConfigSettings;+ // Store reference to the deck layer for feature info access+ private deckLayerRef: DeckWMSLayer | null = null;+// Constructorconstructor(props: ConstructorParameters<typeof AbstractTileLayer>[0] & {@@ -132,15 +138,14 @@ export default class WMSLayer extends AbstractTileLayer<WMSTile, any[]> {formatLayerData(datasets, oldLayerData, animationConfig): WMSLayerData {const {dataId} = this.config;- if (!notNullorUndefined(dataId)) {+ if (!notNullorUndefined(dataId) || !datasets[dataId]) {return {- ...super.formatLayerData(datasets, oldLayerData, animationConfig),tilesetDataUrl: null,metadata: null};}const dataset = datasets[dataId];- const metadata = dataset.metadata;+ const metadata = dataset?.metadata;return {...super.formatLayerData(datasets, oldLayerData, animationConfig),@@ -149,9 +154,9 @@ export default class WMSLayer extends AbstractTileLayer<WMSTile, any[]> {};}- _getCurrentServiceLayer(dataset: KeplerDataset) {+ _getCurrentServiceLayer() {const {visConfig} = this.config;- return visConfig.wmsLayer ?? dataset.metadata?.layers?.[0] ?? null;+ return visConfig.wmsLayer ?? null;}updateLayerMeta(dataset: KeplerDataset): void {@@ -159,7 +164,7 @@ export default class WMSLayer extends AbstractTileLayer<WMSTile, any[]> {return;}- const currentLayer = this._getCurrentServiceLayer(dataset);+ const currentLayer = this._getCurrentServiceLayer();if (currentLayer && currentLayer.boundingBox) {this.updateMeta({bounds: currentLayer.boundingBox@@ -167,24 +172,169 @@ export default class WMSLayer extends AbstractTileLayer<WMSTile, any[]> {}}+ hasHoveredObject(objectInfo: any) {+ // For WMS layers, we consider it hovered if the layer is picked+ // The actual feature info will be retrieved via getHoverData+ if (this.isLayerHovered(objectInfo)) {+ return {+ index: 0, // WMS layers don't have discrete data points, so we use index 0+ ...objectInfo+ };+ }+ return null;+ }++ getHoverData(+ object: any,+ dataContainer: DataContainerInterface,+ fields: Field[],+ animationConfig: AnimationConfig,+ hoverInfo: {index: number; x?: number; y?: number}+ ) {+ // Check if this is a WMS feature info object from clicked state+ if (object?.wmsFeatureInfo) {+ if (Array.isArray(object.wmsFeatureInfo)) {+ return {+ wmsFeatureData: object.wmsFeatureInfo+ };+ }++ return {+ wmsFeatureData: [+ {+ name: 'WMS Feature Info',+ value: object.wmsFeatureInfo+ }+ ]+ };+ }++ if (hoverInfo.x !== undefined && hoverInfo.y !== undefined) {+ return {+ fieldValues: [+ {+ labelMessage: 'layer.wms.hover',+ value: 'Click to query WMS feature info'+ }+ ]+ };+ }++ return null;+ }+renderLayer(opts) {const {visConfig} = this.config;- const {data} = opts;- const wmsLayer = visConfig.wmsLayer?.name;+ const {data, interactionConfig, layerCallbacks} = opts;+ const wmsLayer = this._getCurrentServiceLayer();if (!wmsLayer) {return [];}+ const {name: wmsLayerName, queryable} = wmsLayer;+ const defaultLayerProps = this.getDefaultDeckLayerProps(opts);+ const pickable = interactionConfig?.tooltip?.enabled && queryable;++ const deckLayer = new DeckWMSLayer({+ id: `${this.id}-WMSLayer` as string,+ idx: defaultLayerProps.idx,+ serviceType: 'wms',+ data: data.tilesetDataUrl,+ layers: [wmsLayerName],+ opacity: visConfig.opacity,+ transparent: visConfig.transparent,+ pickable,+ // @ts-ignore+ onClick: pickable ? this._onClick.bind(this, layerCallbacks) : null+ });- return [- new DeckWMSLayer({- id: `${this.id}-WMSLayer` as string,- serviceType: 'wms',- data: data.tilesetDataUrl,- layers: [wmsLayer],- opacity: visConfig.opacity,- transparent: visConfig.transparent,- pickable: false- })- ];+ // Store reference to the deck layer for feature info access+ this.deckLayerRef = deckLayer;++ return [deckLayer];+ }++ protected async _onClick(layerCallbacks, {bitmap, coordinate}) {+ if (!bitmap) return null;++ const x = bitmap.pixel[0];+ const y = bitmap.pixel[1];+ const featureInfo = await this.getWMSFeatureInfo(x, y);++ // Call the callback to update state with coordinate+ if (layerCallbacks?.onWMSFeatureInfo) {+ layerCallbacks.onWMSFeatureInfo({featureInfo, coordinate});+ }++ return featureInfo;+ }++ // Method to retrieve WMS feature info asynchronously+ protected async getWMSFeatureInfo(+ x: number,+ y: number+ ): Promise<Array<{name: string; value: string}> | null> {+ try {+ if (this.deckLayerRef && typeof this.deckLayerRef.getFeatureInfoText === 'function') {+ const featureInfoXml = await this.deckLayerRef.getFeatureInfoText(x, y);+ if (featureInfoXml) {+ // Parse the XML response to extract attributes+ const parsedAttributes = this.parseWMSFeatureInfo(featureInfoXml);+ return parsedAttributes.length > 0 ? parsedAttributes : null;+ }+ }+ return null;+ } catch (error) {+ console.warn('Failed to get WMS feature info:', error);+ return null;+ }+ }++ // Helper method to parse WMS XML response+ protected parseWMSFeatureInfo(xmlString: string): Array<{name: string; value: string}> {+ try {+ // Simple XML parsing to extract feature attributes+ const parser = new DOMParser();+ const xmlDoc = parser.parseFromString(xmlString, 'text/xml');++ const attributes: Array<{name: string; value: string}> = [];++ // Look for feature members+ const featureMembers = xmlDoc.getElementsByTagName('gml:featureMember');++ for (let i = 0; i < featureMembers.length; i++) {+ const featureMember = featureMembers[i];++ // Get all child elements that contain attribute data+ const children = featureMember.children;++ for (let j = 0; j < children.length; j++) {+ const feature = children[j];+ const featureChildren = feature.children;++ // Extract attribute name-value pairs+ for (let k = 0; k < featureChildren.length; k++) {+ const attr = featureChildren[k];+ const tagName = attr.tagName;+ const value = attr.textContent || '';++ // Clean up the tag name (remove namespace prefix)+ const cleanName = tagName.includes(':') ? tagName.split(':')[1] : tagName;++ // Skip empty values and geometry elements+ if (value.trim() && !cleanName.toLowerCase().includes('geom')) {+ attributes.push({+ name: cleanName.replace(/_/g, ' ').toUpperCase(),+ value: value.trim()+ });+ }+ }+ }+ }++ return attributes;+ } catch (error) {+ console.warn('Error parsing WMS feature info XML:', error);+ return [];+ }}}diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.tsindex 4677a5ee9..11fa16165 100644--- a/src/localization/src/translations/en.ts+++ b/src/localization/src/translations/en.ts@@ -119,6 +119,9 @@ export default {rastertile: 'raster tile',wms: 'WMS'},+ wms: {+ hover: 'Value:'+ },layerUpdateError:'An error occurred during layer update: {errorMessage}. Make sure the format of the input data is valid.',interaction: 'Interaction'diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.tsindex 83efa5faf..10ddd5574 100644--- a/src/reducers/src/vis-state-updaters.ts+++ b/src/reducers/src/vis-state-updaters.ts@@ -3523,6 +3523,42 @@ export function layerFilteredItemsChangeUpdater<S extends VisState>(};}+/**+ * Update WMS feature info and pin tooltip+ */+export function wmsFeatureInfoUpdater<S extends VisState>(+ state: S,+ action: VisStateActions.WMSFeatureInfoAction+): S {+ const {layer, featureInfo, coordinate} = action;+ if (!layer) {+ console.warn(`WMS feature info layer doesn't exist`);+ return state;+ }++ // Create a clicked object similar to layerClickUpdater to pin the tooltip+ const clicked = featureInfo+ ? {+ picked: true,+ object: {+ wmsFeatureInfo: featureInfo+ },+ coordinate: coordinate || [0, 0],+ layer: {+ props: {+ idx: state.layers.findIndex(l => l.id === layer.id),+ id: layer.id+ }+ }+ }+ : null;++ return {+ ...state,+ clicked+ };+}+// eslint-disable-next-line max-statementsexport function syncTimeFilterWithLayerTimelineUpdater<S extends VisState>(state: S,diff --git a/src/reducers/src/vis-state.ts b/src/reducers/src/vis-state.tsindex c0bd34c27..7d57f958d 100644--- a/src/reducers/src/vis-state.ts+++ b/src/reducers/src/vis-state.ts@@ -148,6 +148,8 @@ const actionHandler = {[ActionTypes.LAYER_FILTERED_ITEMS_CHANGE]: visStateUpdaters.layerFilteredItemsChangeUpdater,+ [ActionTypes.WMS_FEATURE_INFO]: visStateUpdaters.wmsFeatureInfoUpdater,+[ActionTypes.SYNC_TIME_FILTER_WITH_LAYER_TIMELINE]:visStateUpdaters.syncTimeFilterWithLayerTimelineUpdater,diff --git a/src/table/src/dataset-utils.ts b/src/table/src/dataset-utils.tsindex 35be69572..b683c598a 100644--- a/src/table/src/dataset-utils.ts+++ b/src/table/src/dataset-utils.ts@@ -285,7 +285,8 @@ export function wmsCapabilitiesToDatasetMetadata(capabilities: WMSCapabilities):return {name: layer.name,title: layer.title || layer.name,- boundingBox+ boundingBox,+ queryable: layer.queryable};});}diff --git a/src/types/layers.d.ts b/src/types/layers.d.tsindex 8e3423b7b..256b0eca9 100644--- a/src/types/layers.d.ts+++ b/src/types/layers.d.ts@@ -419,12 +419,23 @@ export type LayerCallbacks = {count: number;}) => void;+ onWMSFeatureInfo?: (+ idx: number,+ props: {+ featureInfo: Array<{name: string; value: string}> | string | null;+ coordinate?: [number, number] | null;+ }+ ) => void;};export type BindedLayerCallbacks = {onLayerHover?: (value: any) => void;onSetLayerDomain?: (value: any) => void;onFilteredItemsChange?: (event: {id: string; count: number}) => void;+ onWMSFeatureInfo?: (+ featureInfo: Array<{name: string; value: string}> | string | null,+ coordinate?: [number, number]+ ) => void;};export type VisualChannelAggregation = 'colorAggregation' | 'sizeAggregation';diff --git a/test/browser/layer-tests/index.js b/test/browser/layer-tests/index.jsindex f53493f1c..9328da95b 100644--- a/test/browser/layer-tests/index.js+++ b/test/browser/layer-tests/index.js@@ -15,3 +15,4 @@ import './point-layer-specs';import './scenegraph-layer-specs';import './trip-layer-specs';import './s2-geometry-layer-specs';+import './wms-layer-specs';diff --git a/test/browser/layer-tests/wms-layer-specs.js b/test/browser/layer-tests/wms-layer-specs.jsnew file mode 100644index 000000000..0e62d87bb--- /dev/null+++ b/test/browser/layer-tests/wms-layer-specs.js@@ -0,0 +1,403 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import test from 'tape-catch';+import {KeplerGlLayers} from '@kepler.gl/layers';+import {testCreateCases} from 'test/helpers/layer-utils';++const {WMSLayer} = KeplerGlLayers;++// Shared test fixtures+const MOCK_WMS_LAYER_CONFIG = {+ name: 'test_layer',+ title: 'Test WMS Layer',+ boundingBox: [+ [-180, -90],+ [180, 90]+ ],+ queryable: true+};++const MOCK_WMS_DATASET = {+ type: 'wms-tile',+ metadata: {+ tilesetDataUrl: 'http://example.com/wms',+ label: 'Test WMS Dataset',+ layers: [MOCK_WMS_LAYER_CONFIG]+ }+};++const MOCK_RENDER_OPTS = {+ data: {+ tilesetDataUrl: 'http://example.com/wms',+ metadata: {layers: [MOCK_WMS_LAYER_CONFIG]}+ },+ mapState: {dragRotate: false},+ interactionConfig: {tooltip: {enabled: true}},+ layerCallbacks: {onWMSFeatureInfo: () => {}}+};++// Mock DOMParser for browser environment+global.DOMParser = class MockDOMParser {+ parseFromString(str) {+ const createMockElement = (tagName, textContent = '') => ({+ tagName,+ textContent,+ children: [],+ getElementsByTagName: name =>+ Array.from(this.children).filter(child => child.tagName === name)+ });++ // Simple mock for the specific XML structure used in tests+ if (str.includes('conus:RED_BAND')) {+ return {+ getElementsByTagName: name => {+ if (name === 'gml:featureMember') {+ return [+ {+ children: [+ {+ children: [+ createMockElement('conus:RED_BAND', '255.0'),+ createMockElement('conus:GREEN_BAND', '195.0'),+ createMockElement('conus:BLUE_BAND', '0.0'),+ createMockElement('conus:ALPHA_BAND', '255.0')+ ]+ }+ ]+ }+ ];+ }+ return [];+ }+ };+ }++ return {getElementsByTagName: () => []};+ }+};++// Helper function to create a configured WMS layer+function createWMSLayer(config = {}) {+ const layer = new WMSLayer({+ id: 'test-wms-layer',+ dataId: 'wms-dataset',+ ...config+ });++ layer.updateLayerVisConfig({+ wmsLayer: MOCK_WMS_LAYER_CONFIG,+ opacity: 0.8,+ transparent: true,+ ...config.visConfig+ });++ return layer;+}++test('#WMSLayer -> constructor', t => {+ const TEST_CASES = {+ CREATE: [+ {+ props: {+ dataId: 'wms-test-data',+ isVisible: true,+ label: 'test wms layer'+ },+ test: layer => {+ t.ok(layer.config.dataId === 'wms-test-data', 'WMSLayer dataId should be correct');+ t.ok(layer.type === 'wms', 'type should be wms');+ t.ok(layer.isAggregated === false, 'WMSLayer is not aggregated');+ t.ok(layer.config.label === 'test wms layer', 'label should be correct');+ t.ok(layer.config.isVisible === true, 'should be visible by default');+ t.ok(layer.config.visConfig, 'should have visConfig');+ t.equal(layer.config.visConfig.opacity, 0.8, 'should have default opacity');+ t.equal(layer.config.visConfig.transparent, true, 'should be transparent by default');+ t.equal(layer.config.visConfig.wmsLayer, null, 'should have null wmsLayer initially');+ t.ok(typeof layer.layerIcon === 'function', 'should have layerIcon');+ t.deepEqual(+ layer.supportedDatasetTypes,+ ['wms-tile'],+ 'should support wms-tile dataset type'+ );+ }+ }+ ]+ };++ testCreateCases(t, WMSLayer, TEST_CASES.CREATE);+ t.end();+});++test('WMSLayer -> basic layer functionality', t => {+ const layer = createWMSLayer();++ // Test layer configuration+ t.deepEqual(+ layer.config.visConfig.wmsLayer,+ MOCK_WMS_LAYER_CONFIG,+ 'should update wmsLayer config'+ );+ t.equal(layer.config.visConfig.opacity, 0.8, 'should have correct opacity');+ t.equal(layer.config.visConfig.transparent, true, 'should be transparent');++ // Test layer properties+ t.equal(layer.name, 'WMS Tile', 'should have correct layer name');+ t.ok(layer.layerIcon, 'should have layer icon');+ t.equal(layer.requireData, true, 'WMS layer should require data');+ t.ok(layer.isValidToSave(), 'should be valid to save');++ // Test _getCurrentServiceLayer+ const serviceLayer = layer._getCurrentServiceLayer();+ t.ok(serviceLayer, 'should return service layer when configured');+ t.equal(serviceLayer.name, 'test_layer', 'should return correct service layer');++ t.end();+});++test('WMSLayer -> hover functionality', t => {+ const layer = createWMSLayer();++ // Test hasHoveredObject+ const mockObjectInfo = {+ picked: true,+ layer: {props: {id: 'test-wms-layer'}}+ };++ const hoveredObject = layer.hasHoveredObject(mockObjectInfo);+ t.ok(hoveredObject, 'should return hovered object when layer is picked');+ t.equal(hoveredObject.index, 0, 'should return index 0 for WMS layer');++ // Test hasHoveredObject with no picked object+ const hoveredObjectNotPicked = layer.hasHoveredObject({...mockObjectInfo, picked: false});+ t.equal(hoveredObjectNotPicked, null, 'should return null when layer is not picked');++ // Test getHoverData with hover coordinates+ const hoverData = layer.getHoverData(null, null, [], null, {index: 0, x: 100, y: 200});+ t.ok(hoverData, 'should return hover data for WMS layer');+ t.ok(hoverData.fieldValues, 'should have fieldValues array');+ t.equal(hoverData.fieldValues.length, 1, 'should have 1 field value');+ t.equal(hoverData.fieldValues[0].labelMessage, 'layer.wms.hover', 'should have WMS hover label');++ // Test getHoverData with WMS feature info - string format+ const wmsFeatureInfoObject = {+ wmsFeatureInfo: '<FeatureInfo><Feature>Test feature data</Feature></FeatureInfo>'+ };+ const wmsHoverData = layer.getHoverData(wmsFeatureInfoObject, null, [], null, {index: 0});+ t.ok(wmsHoverData.wmsFeatureData, 'should have wmsFeatureData array');+ t.equal(wmsHoverData.wmsFeatureData.length, 1, 'should have 1 feature data item');++ // Test getHoverData with WMS feature info - array format+ const wmsFeatureInfoArrayObject = {+ wmsFeatureInfo: [+ {name: 'RED BAND', value: '255.0'},+ {name: 'GREEN BAND', value: '195.0'},+ {name: 'BLUE BAND', value: '0.0'}+ ]+ };+ const wmsArrayHoverData = layer.getHoverData(wmsFeatureInfoArrayObject, null, [], null, {+ index: 0+ });+ t.equal(wmsArrayHoverData.wmsFeatureData.length, 3, 'should have 3 feature data items');+ t.equal(+ wmsArrayHoverData.wmsFeatureData[0].name,+ 'RED BAND',+ 'should have correct attribute name'+ );++ t.end();+});++test('#WMSLayer -> renderLayer variations', t => {+ const baseLayer = createWMSLayer();++ // Test normal rendering+ const deckLayers = baseLayer.renderLayer(MOCK_RENDER_OPTS);+ t.ok(deckLayers, 'should create deck layers');+ t.equal(deckLayers.length, 1, 'should render one deck layer');++ const deckLayer = deckLayers[0];+ t.equal(deckLayer.id, 'test-wms-layer-WMSLayer', 'should have correct layer id');+ t.equal(deckLayer.props.pickable, true, 'should be pickable when tooltips enabled and queryable');+ t.equal(deckLayer.props.serviceType, 'wms', 'should have correct service type');+ t.deepEqual(deckLayer.props.layers, ['test_layer'], 'should have correct layers');+ t.equal(deckLayer.props.opacity, 0.8, 'should have correct opacity');+ t.ok(typeof deckLayer.props.onClick === 'function', 'should have onClick handler');++ // Test with tooltips disabled+ const tooltipsDisabledOpts = {+ ...MOCK_RENDER_OPTS,+ interactionConfig: {tooltip: {enabled: false}}+ };+ const nonPickableLayers = baseLayer.renderLayer(tooltipsDisabledOpts);+ t.equal(+ nonPickableLayers[0].props.pickable,+ false,+ 'should not be pickable when tooltips disabled'+ );++ // Test with non-queryable layer+ const nonQueryableLayer = createWMSLayer({+ visConfig: {wmsLayer: {...MOCK_WMS_LAYER_CONFIG, queryable: false}}+ });+ const nonQueryableLayers = nonQueryableLayer.renderLayer(MOCK_RENDER_OPTS);+ t.equal(+ nonQueryableLayers[0].props.pickable,+ false,+ 'should not be pickable when layer is not queryable'+ );++ // Test without wmsLayer config+ const unconfiguredLayer = new WMSLayer({id: 'test-wms-layer', dataId: 'wms-dataset'});+ const emptyLayers = unconfiguredLayer.renderLayer(MOCK_RENDER_OPTS);+ t.equal(emptyLayers.length, 0, 'should not render any layers without wmsLayer config');++ t.end();+});++test('#WMSLayer -> formatLayerData', t => {+ const layer = createWMSLayer();++ const mockDatasets = {'wms-dataset': MOCK_WMS_DATASET};+ const layerData = layer.formatLayerData(mockDatasets);+ t.ok(layerData, 'should return layer data object');+ t.equal(layerData.tilesetDataUrl, 'http://example.com/wms', 'should have tileset data URL');+ t.ok(layerData.metadata, 'should have metadata');++ t.end();+});++test('#WMSLayer -> updateLayerMeta', t => {+ const layer = createWMSLayer();++ // Test with non-WMS dataset+ t.doesNotThrow(() => {+ layer.updateLayerMeta({type: 'csv'});+ }, 'should not throw with non-WMS dataset');++ // Test with WMS dataset+ t.doesNotThrow(() => {+ layer.updateLayerMeta({type: 'wms-tile'});+ }, 'should update meta with WMS dataset');++ t.deepEqual(+ layer.meta.bounds,+ [+ [-180, -90],+ [180, 90]+ ],+ 'should set bounds from bounding box'+ );++ t.end();+});++test('#WMSLayer -> parseWMSFeatureInfo', t => {+ const layer = createWMSLayer();++ const xmlString = `<?xml version="1.0" encoding="UTF-8"?>+<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:conus="http://conus" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs https://opengeo.ncep.noaa.gov/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd">+ <gml:featureMember>+ <conus:conus_cref_qcd fid="">+ <conus:RED_BAND>255.0</conus:RED_BAND>+ <conus:GREEN_BAND>195.0</conus:GREEN_BAND>+ <conus:BLUE_BAND>0.0</conus:BLUE_BAND>+ <conus:ALPHA_BAND>255.0</conus:ALPHA_BAND>+ </conus:conus_cref_qcd>+ </gml:featureMember>+</wfs:FeatureCollection>`;++ const parsedAttributes = layer.parseWMSFeatureInfo(xmlString);+ t.ok(Array.isArray(parsedAttributes), 'should return an array');+ t.equal(parsedAttributes.length, 4, 'should parse 4 attributes');+ t.equal(parsedAttributes[0].name, 'RED BAND', 'should parse RED_BAND attribute name correctly');+ t.equal(parsedAttributes[0].value, '255.0', 'should parse RED_BAND attribute value correctly');+ t.equal(+ parsedAttributes[1].name,+ 'GREEN BAND',+ 'should parse GREEN_BAND attribute name correctly'+ );+ t.equal(parsedAttributes[1].value, '195.0', 'should parse GREEN_BAND attribute value correctly');++ // Test edge cases+ t.deepEqual(layer.parseWMSFeatureInfo(''), [], 'should return empty array for empty XML');+ t.deepEqual(+ layer.parseWMSFeatureInfo('<invalid>xml</invalid>'),+ [],+ 'should return empty array for invalid XML'+ );++ t.end();+});++test('#WMSLayer -> findDefaultLayerProps', t => {+ // Test with valid WMS dataset+ const result = WMSLayer.findDefaultLayerProps(MOCK_WMS_DATASET);+ t.ok(result.props, 'should return props object');+ t.equal(result.props.length, 1, 'should return one layer prop for WMS dataset');+ t.equal(result.props[0].label, 'Test WMS Dataset', 'should use dataset label');+ t.deepEqual(+ result.props[0].layers,+ MOCK_WMS_DATASET.metadata.layers,+ 'should pass through all layers'+ );++ // Test with non-WMS dataset+ const nonWmsResult = WMSLayer.findDefaultLayerProps({+ type: 'csv',+ metadata: {label: 'CSV Dataset'}+ });+ t.deepEqual(nonWmsResult.props, [], 'should return empty props for non-WMS dataset');++ // Test with empty WMS dataset+ const emptyWmsDataset = {type: 'wms-tile', metadata: {label: 'Empty WMS Dataset', layers: []}};+ const emptyResult = WMSLayer.findDefaultLayerProps(emptyWmsDataset);+ t.equal(+ emptyResult.props.length,+ 1,+ 'should return one prop even for WMS dataset with no layers'+ );+ t.deepEqual(emptyResult.props[0].layers, [], 'should have empty layers array');++ t.end();+});++test('#WMSLayer -> edge cases and error handling', t => {+ const layer = createWMSLayer();++ // Test formatLayerData with missing dataset+ t.doesNotThrow(() => {+ const emptyLayerData = layer.formatLayerData({}, {}, {});+ t.ok(emptyLayerData, 'should return layer data object even with missing dataset');+ t.equal(emptyLayerData.tilesetDataUrl, null, 'should handle missing dataset gracefully');+ }, 'should not throw error when formatting with missing dataset');++ // Test layer visibility+ const invisibleLayer = createWMSLayer({isVisible: false});+ t.equal(invisibleLayer.config.isVisible, false, 'should respect initial visibility setting');++ // Test hasHoveredObject when layer is not visible+ const mockObjectInfo = {picked: true, layer: {props: {id: 'test-wms-layer'}}};+ const hoveredObject = invisibleLayer.hasHoveredObject(mockObjectInfo);+ t.ok(hoveredObject, 'should return hovered object even when layer is not visible');++ // Test getWMSFeatureInfo with no deckLayerRef+ layer['getWMSFeatureInfo'](100, 200)+ .then(result => {+ t.equal(result, null, 'should return null when no deckLayerRef');+ })+ .catch(_error => {+ t.fail('should not throw error when no deckLayerRef');+ });++ // Test deckLayerRef storage+ const firstRender = layer.renderLayer(MOCK_RENDER_OPTS);+ t.ok(layer['deckLayerRef'], 'should store deckLayerRef after first render');++ const firstRef = layer['deckLayerRef'];+ const secondRender = layer.renderLayer(MOCK_RENDER_OPTS);+ t.ok(layer['deckLayerRef'], 'should have deckLayerRef after second render');+ t.notEqual(layer['deckLayerRef'], firstRef, 'should update deckLayerRef on new render');++ t.end();+});