Skip to content

Commit

Permalink
#9139: Fix - New WFS layers no longer visible in dashboards (#9230) (#…
Browse files Browse the repository at this point in the history
…9233)

(cherry picked from commit 3af3f96)
  • Loading branch information
dsuren1 authored Jun 19, 2023
1 parent cbfe58a commit 501bb38
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,36 @@ describe('handleMapZoomLayer enhancer', function() {
}));
ReactDOM.render(<Provider store={store}><Sink editorData={editorData} selectedNodes={selectedNodes} /></Provider>, 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(<Provider store={store}><Sink editorData={editorData} selectedNodes={selectedNodes} /></Provider>, document.getElementById("container"));
});
});

Original file line number Diff line number Diff line change
@@ -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();
});

});

Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({}), {
Expand All @@ -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);
Expand All @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions web/client/plugins/widgetbuilder/enhancers/layerSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 501bb38

Please sign in to comment.