Skip to content

Commit

Permalink
#67 Add UF geometry retrival when showing UFInfo from parcelle table (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz authored May 10, 2021
1 parent 90f8a6d commit 9aa0193
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
7 changes: 7 additions & 0 deletions js/extension/actions/cadastrapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const SHOW_OWNERS = "CADASTRAPP:SHOW_OWNERS";
export const CLEAR_OWNERS = "CADASTRAPP:CLEAR_OWNERS";

export const SHOW_LANDED_PROPERTIES_INFORMATION = "CADASTRAPP:SHOW_LANDED_PROPERTIES_INFORMATION";
export const SHOW_LANDED_PROPERTIES_INFORMATION_BY_PARCELLE = "CADASTRAPP:SHOW_LANDED_PROPERTIES_INFORMATION_BY_PARCELLE";

export const LOAD_INFO = "CADASTRAPP:LOAD_INFO";
export const INFORMATION_UPDATE = "CADASTRAPP:INFORMATION_UPDATE";
export const INFORMATION_CLEAR = "CADASTRAPP:INFORMATION_CLEAR";
Expand Down Expand Up @@ -236,6 +238,11 @@ export const showLandedPropertyInformation = (parcelle) => ({
type: SHOW_LANDED_PROPERTIES_INFORMATION,
parcelle
});
// LANDED PROPERTY
export const showLandedPropertyInformationByParcelle = (parcelle) => ({
type: SHOW_LANDED_PROPERTIES_INFORMATION_BY_PARCELLE,
parcelle
});

// INFORMATION

Expand Down
4 changes: 2 additions & 2 deletions js/extension/components/plot/PlotSelectionToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function PlotSelectionToolbar({
loadInfo = () => {},
zoomToSelection = () => {},
removePlots = () => {},
showLandedPropertyInformation = () => {},
showLandedPropertyInformationByParcelle = () => {},
selectedPlots = []
}) {
const atLeastOneSelected = selectedPlots.length > 0;
Expand All @@ -49,7 +49,7 @@ export default function PlotSelectionToolbar({
disabled: !onlyOneSelected,
glyph: "th-list",
tooltipId: "cadastrapp.result.parcelle.uf",
onClick: () => { showLandedPropertyInformation(find(currentData, {parcelle: selectedPlots[0]})); }
onClick: () => { showLandedPropertyInformationByParcelle(find(currentData, {parcelle: selectedPlots[0]})); }
}]
: []), {
disabled: !atLeastOneSelected,
Expand Down
2 changes: 1 addition & 1 deletion js/extension/epics/cadastrapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export * from './setup';
export { syncLayerForPlots, zoomToExtentAllResultsEpic } from './layerSync';

// epics that implement map selection
export { cadastrappMapSelection, mouseMovePopupEpic, showPopupEpic } from './mapSelection';
export { cadastrappMapSelection, mouseMovePopupEpic, showPopupEpic, showLandedPropertyByParcelle } from './mapSelection';

export { cadastrappZoomToSelection } from './events';

Expand Down
31 changes: 29 additions & 2 deletions js/extension/epics/mapSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';
import {getInfoBulle, getParcelle} from '../api';
import uuid from 'uuid';

import pointOnSurface from '@turf/point-on-surface';
import {SELECTION_TYPES, MOUSE_EVENT, CONTROL_NAME, DEFAULT_POPUP_PROPS} from '../constants';
import { error } from '@mapstore/actions/notifications';
import {
Expand All @@ -20,7 +20,8 @@ import {
SHOW_POPUP,
showPopup,
SAVE_BUBBLE_INFO,
showLandedPropertyInformation
showLandedPropertyInformation,
SHOW_LANDED_PROPERTIES_INFORMATION_BY_PARCELLE
} from '../actions/cadastrapp';

import {
Expand Down Expand Up @@ -179,6 +180,32 @@ export const cadastrappMapSelection = (action$, {getState = () => {}}) =>
// if the selection type is not present, it means has been reset, so deactivate any drawing tool
return deactivate();
});
/**
* Retrieves the geometry of the ufFeature, when not present, and shows the LandedPropertyInformation with this data.
* The current implementation use a point on surface to query WFS, emulating the click event of the selection tool,
* as suggested here: https://github.com/georchestra/mapstore2-cadastrapp/issues/67#issuecomment-836237999
*/
export const showLandedPropertyByParcelle = (action$, {getState = () => {}}) => {
return action$.ofType(SHOW_LANDED_PROPERTIES_INFORMATION_BY_PARCELLE)
.filter(({parcelle}) => !!parcelle?.feature)
.switchMap(
({parcelle}) => {
const {geometry} = pointOnSurface(parcelle?.feature) ?? {};
if (!geometry) {
console.log("Error retrieving uf feature in map selection. No parcelle geometry to extract point for UF Layer intersection"); // eslint-disable-line no-console
return Rx.Observable.of(showLandedPropertyInformation(parcelle));
}
return Rx.Observable.defer(() => getUFFeatures(geometry, getState))
.catch( (e) => {
console.log("Error retrieving uf feature in map selection"); // eslint-disable-line no-console
console.log(e); // eslint-disable-line no-console
return Rx.Observable.of(showLandedPropertyInformation(parcelle));
})
.map(({ features: ff = [] }) => ff?.[0])
.map(feature => showLandedPropertyInformation({ ...parcelle, feature, ufFeature: !!feature}));
}
);
};

/**
* Generates geometry data and fetches feature info obtained from mouse over event position on map
Expand Down
4 changes: 2 additions & 2 deletions js/extension/plugins/cadastrapp/PlotSelection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
removePlots,
zoomToSelection,
loadInfo,
showLandedPropertyInformation
showLandedPropertyInformationByParcelle
} from '../../actions/cadastrapp';

import {
Expand Down Expand Up @@ -42,7 +42,7 @@ const PlotsSelection = connect((state) => ({
onRowsDeselected: deselectPlots,
removePlots: removePlots,
zoomToSelection: zoomToSelection,
showLandedPropertyInformation,
showLandedPropertyInformationByParcelle,
onTabDelete: () => removePlotSelection()
})(PS);

Expand Down

0 comments on commit 9aa0193

Please sign in to comment.