Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8578 SEARCH_WITH_FILTER action: add popup support #8673

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix PR comments
  • Loading branch information
belom88 committed Oct 10, 2022
commit db2763f8d1c50dad4f8c42f8f4e05c5f6047bb53
56 changes: 42 additions & 14 deletions web/client/epics/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,22 @@ describe('search Epics', () => {
}, {layers: {flat: [{name: "layerName", url: "clearlyNotAUrl", visibility: true, queryable: true, type: "wms"}]}});
});
it('searchOnStartEpic, that sends a Getfeature and a GFI requests', (done) => {
const testStore = {
map: {
projection: "EPSG:3857"
},
layers: {
flat: [
{
name: "layerName",
url: "base/web/client/test-resources/wms/GetFeature.json",
visibility: true,
queryable: true,
type: "wms"
}
]
}
};
let action = searchLayerWithFilter({layer: "layerName", cql_filter: "cql"});
const NUM_ACTIONS = 2;
testEpic(searchOnStartEpic, NUM_ACTIONS, action, (actions) => {
Expand All @@ -608,11 +624,14 @@ describe('search Epics', () => {
expect(actions[0].type).toBe(FEATURE_INFO_CLICK);
expect(actions[1].type).toBe(SHOW_MAPINFO_MARKER);
done();
}, {layers: {flat: [{name: "layerName", url: "base/web/client/test-resources/wms/GetFeature.json", visibility: true, queryable: true, type: "wms"}]}});
}, testStore);
});
it('searchOnStartEpic, that adds popup', (done) => {
const testStore = {
mapInfo: {showInMapPopup: true},
mapInfo: { showInMapPopup: true },
map: {
projection: "EPSG:3857"
},
layers: {
flat: [
{
Expand All @@ -626,18 +645,27 @@ describe('search Epics', () => {
}
};
let action = searchLayerWithFilter({layer: "layerName", cql_filter: "cql"});
const NUM_ACTIONS = 3;
testEpic(searchOnStartEpic, NUM_ACTIONS, action, (actions) => {
expect(actions).toExist();
expect(actions.length).toBe(NUM_ACTIONS);
expect(actions[0].type).toBe(FEATURE_INFO_CLICK);
expect(actions[1].type).toBe(SHOW_MAPINFO_MARKER);
const popupAction = actions[2];
expect(popupAction.type).toBe(ADD_MAP_POPUP);
expect(popupAction.popup?.position?.coordinates?.[0]).toBe(968346.2286324208);
expect(popupAction.popup?.position?.coordinates?.[1]).toBe(5538315.133325616);
done();
}, testStore);
const NUM_ACTIONS = 2;
testEpic(
searchOnStartEpic,
NUM_ACTIONS,
action,
(actions) => {
expect(actions).toExist();
expect(actions.length).toBe(NUM_ACTIONS);
expect(actions[0].type).toBe(FEATURE_INFO_CLICK);
const popupAction = actions[1];
expect(popupAction.type).toBe(ADD_MAP_POPUP);
expect(popupAction.popup?.position?.coordinates?.[0]).toBe(
968346.2286324208
);
expect(popupAction.popup?.position?.coordinates?.[1]).toBe(
5538315.133325616
);
done();
},
testStore
);
});
it('textSearchShowGFIEpic, it sends info format taken from layer', (done) => {
let action = showGFI(
Expand Down
42 changes: 34 additions & 8 deletions web/client/epics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {getDefaultInfoFormatValueFromLayer} from '../utils/MapInfoUtils';
import {identifyOptionsSelector, isMapPopup} from '../selectors/mapInfo';
import { addPopup } from '../actions/mapPopups';
import { IDENTIFY_POPUP } from '../components/map/popups';
import { projectionSelector } from '../selectors/map';

const getInfoFormat = (layerObj, state) => getDefaultInfoFormatValueFromLayer(layerObj, {...identifyOptionsSelector(state)});

Expand Down Expand Up @@ -302,7 +303,7 @@ export const zoomAndAddPointEpic = (action$, store) =>
export const searchOnStartEpic = (action$, store) =>
action$.ofType(SEARCH_LAYER_WITH_FILTER)
.switchMap(({layer: name, "cql_filter": cqlFilter}) => {
const state = store.getState();
const state = store.getState(store.getState());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix this get state

// if layer is NOT queriable and visible then show error notification
if (queryableLayersSelector(state).filter(l => l.name === name ).length === 0) {
return Rx.Observable.of(nonQueriableLayerError());
Expand All @@ -324,14 +325,39 @@ export const searchOnStartEpic = (action$, store) =>
.switchMap(({ type, geometry, typeName }) => {
let coord = pointOnSurface({ type, geometry }).geometry.coordinates;
const latlng = {lng: coord[0], lat: coord[1] };
const {x, y} = reproject(coord, 'EPSG:4326', 'EPSG:3857');
const projection = projectionSelector(store.getState());
const { x, y } = reproject(
coord,
"EPSG:4326",
projection
);

let mapActionObservable;
if (isMapPopup(store.getState())) {
mapActionObservable = Rx.Observable.of(
addPopup(uuid(), {
component: IDENTIFY_POPUP,
maxWidth: 600,
position: { coordinates: [x, y] }
})
);
} else {
mapActionObservable = Rx.Observable.of(
showMapinfoMarker()
);
}

if (coord) { // trigger get feature info
return Rx.Observable.of(featureInfoClick({latlng}, typeName, [typeName], {[typeName]: {cql_filter: cqlFilter}}), showMapinfoMarker())
.merge(Rx.Observable.of(addPopup(uuid(),
{component: IDENTIFY_POPUP, maxWidth: 600, position: {coordinates: [x, y]}}))
.filter(() => isMapPopup(store.getState()))
);
if (coord) {
// trigger get feature info
return Rx.Observable.of(
featureInfoClick(
{ latlng },
typeName,
[typeName],
{ [typeName]: { cql_filter: cqlFilter } }
)
)
.merge(mapActionObservable);
}
return Rx.Observable.empty();
}).catch(() => {
Expand Down