From 8e5613c5f6245940b4d1f2afd8f31524f141c649 Mon Sep 17 00:00:00 2001 From: Suren Date: Fri, 16 Jun 2023 21:29:07 +0530 Subject: [PATCH] #9139: Fix - New WFS layers no longer visible in dashboards (#9230) (cherry picked from commit 3af3f96ee6549e7a532e22dc5e01c8ac9204bae0) --- .../__tests__/handleMapZoomLayer-test.js | 31 +++++++++++++++++ .../enhancers/__tests__/layerSelector-test.js | 33 +++++++++++++++++++ .../enhancers/handleMapZoomLayer.js | 8 +++-- .../widgetbuilder/enhancers/layerSelector.js | 4 +-- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 web/client/plugins/widgetbuilder/enhancers/__tests__/layerSelector-test.js diff --git a/web/client/plugins/widgetbuilder/enhancers/__tests__/handleMapZoomLayer-test.js b/web/client/plugins/widgetbuilder/enhancers/__tests__/handleMapZoomLayer-test.js index e0077f4558..fb5a896d30 100644 --- a/web/client/plugins/widgetbuilder/enhancers/__tests__/handleMapZoomLayer-test.js +++ b/web/client/plugins/widgetbuilder/enhancers/__tests__/handleMapZoomLayer-test.js @@ -101,5 +101,36 @@ describe('handleMapZoomLayer enhancer', function() { })); ReactDOM.render(, document.getElementById("container")); }); + it('test zoom map and epsgSupported with boundingBox', (done) => { + const editorData = { + selectedMapId: 'MAP_ID', + maps: [{ + mapId: 'MAP_ID', + size: { + width: 518, + height: 351 + }, + layers: [{ + id: "layer.id1", + boundingBox: { + crs: 'EPSG:4326', + bounds: { + minx: -12, + miny: 24, + maxx: -66, + maxy: 49 + } + } + }] + }] + }; + const selectedNodes = ["layer.id1"]; + const Sink = handleMapZoomLayer(createSink(props => { + props.zoomTo(selectedNodes); + expect(props.isEpsgSupported()).toBeTruthy(); + done(); + })); + ReactDOM.render(, document.getElementById("container")); + }); }); diff --git a/web/client/plugins/widgetbuilder/enhancers/__tests__/layerSelector-test.js b/web/client/plugins/widgetbuilder/enhancers/__tests__/layerSelector-test.js new file mode 100644 index 0000000000..8c3d572213 --- /dev/null +++ b/web/client/plugins/widgetbuilder/enhancers/__tests__/layerSelector-test.js @@ -0,0 +1,33 @@ +/* + * Copyright 2023, GeoSolutions Sas. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. +*/ + +import expect from 'expect'; +import { addSearchObservable } from '../layerSelector'; + + +describe('layerSelector enhancer', function() { + + it('test addSearchObservable with addSearch', () => { + expect(addSearchObservable({ + type: "wms", + name: "test-layer" + }, { + type: "wms" + }).value).toBeFalsy(); + }); + it('test addSearchObservable skip addSearch', () => { + expect(addSearchObservable({ + type: "wfs", + name: "test-layer" + }, { + type: "wfs" + }).value).toBeTruthy(); + }); + +}); + diff --git a/web/client/plugins/widgetbuilder/enhancers/handleMapZoomLayer.js b/web/client/plugins/widgetbuilder/enhancers/handleMapZoomLayer.js index 4f546f60b4..d0f54dde6f 100644 --- a/web/client/plugins/widgetbuilder/enhancers/handleMapZoomLayer.js +++ b/web/client/plugins/widgetbuilder/enhancers/handleMapZoomLayer.js @@ -45,6 +45,10 @@ const toBoundsArray = extent => { } return null; }; +const getBbox = l => l.bbox || l.boundingBox; +const getLayersBbox = (layers) => { + return layers?.filter(getBbox).map(getBbox) ?? []; +}; const enhancer = compose( connect(() => ({}), { @@ -54,7 +58,7 @@ const enhancer = compose( isEpsgSupported: ({ editorData = {}, selectedNodes = [] }) => () => { const layers = editorData.maps?.find(m => m.mapId === editorData.selectedMapId)?.layers || []; const selectedLayers = selectedNodes.map(nodeId => layers.find(layer => layer.id === nodeId)).filter(l => l); - const layersBbox = selectedLayers.filter(l => l.bbox).map(l => l.bbox); + const layersBbox = getLayersBbox(selectedLayers); const uniqueCRS = layersBbox.length > 0 ? layersBbox.reduce((a, b) => a.crs === b.crs ? a : { crs: 'differentCRS' }) : { crs: 'differentCRS' }; const currentEPSG = !!head(layersBbox) && uniqueCRS.crs !== 'differentCRS' && uniqueCRS.crs; return currentEPSG && Proj4js.defs(currentEPSG); @@ -63,7 +67,7 @@ const enhancer = compose( const map = editorData.maps?.find(m => m.mapId === editorData.selectedMapId) || {}; const layers = map.layers || []; const selectedLayers = selectedNodes.map(nodeId => layers.find(layer => layer.id === nodeId)).filter(l => l); - const layersBbox = selectedLayers.filter(l => l.bbox).map(l => l.bbox); + const layersBbox = getLayersBbox(selectedLayers); const bbox = layersBbox.length > 1 ? layersBbox.reduce((a, b) => { return { bounds: { diff --git a/web/client/plugins/widgetbuilder/enhancers/layerSelector.js b/web/client/plugins/widgetbuilder/enhancers/layerSelector.js index 5dba1ae0f5..c71d4d697e 100644 --- a/web/client/plugins/widgetbuilder/enhancers/layerSelector.js +++ b/web/client/plugins/widgetbuilder/enhancers/layerSelector.js @@ -18,8 +18,8 @@ export const toLayer = (r, service) => ["tms", "wfs"].includes(service?.type) // // the type wms is default (for csw and wms), wmts have to be passed. // TODO: improve and centralize more : API[service?.type || 'wms'].getLayerFromRecord(r, { service }); -// checks for tms wmts in order to addSearch() to skip addSearch -export const addSearchObservable = (selected, service) => ["tms", "wmts"].includes(service?.type) ? Rx.Observable.of(toLayer(selected, service)) : addSearch(toLayer(selected, service)); +// checks for tms, wmts & wfs, in order to skip addSearch +export const addSearchObservable = (selected, service) => ["tms", "wmts", "wfs"].includes(service?.type) ? Rx.Observable.of(toLayer(selected, service)) : addSearch(toLayer(selected, service)); /** * enhancer for CompactCatalog (or a container) to validate a selected record,