diff --git a/js/extension/actions/cadastrapp.js b/js/extension/actions/cadastrapp.js index 3b69628..e2d5f18 100644 --- a/js/extension/actions/cadastrapp.js +++ b/js/extension/actions/cadastrapp.js @@ -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"; @@ -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 diff --git a/js/extension/components/plot/PlotSelectionToolbar.jsx b/js/extension/components/plot/PlotSelectionToolbar.jsx index 4aa7a7b..2e4c3b7 100644 --- a/js/extension/components/plot/PlotSelectionToolbar.jsx +++ b/js/extension/components/plot/PlotSelectionToolbar.jsx @@ -24,7 +24,7 @@ export default function PlotSelectionToolbar({ loadInfo = () => {}, zoomToSelection = () => {}, removePlots = () => {}, - showLandedPropertyInformation = () => {}, + showLandedPropertyInformationByParcelle = () => {}, selectedPlots = [] }) { const atLeastOneSelected = selectedPlots.length > 0; @@ -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, diff --git a/js/extension/epics/cadastrapp.js b/js/extension/epics/cadastrapp.js index 1915e7e..8adb413 100644 --- a/js/extension/epics/cadastrapp.js +++ b/js/extension/epics/cadastrapp.js @@ -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'; diff --git a/js/extension/epics/mapSelection.js b/js/extension/epics/mapSelection.js index 7aa9f0f..e5b43bd 100644 --- a/js/extension/epics/mapSelection.js +++ b/js/extension/epics/mapSelection.js @@ -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 { @@ -20,7 +20,8 @@ import { SHOW_POPUP, showPopup, SAVE_BUBBLE_INFO, - showLandedPropertyInformation + showLandedPropertyInformation, + SHOW_LANDED_PROPERTIES_INFORMATION_BY_PARCELLE } from '../actions/cadastrapp'; import { @@ -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 diff --git a/js/extension/plugins/cadastrapp/PlotSelection.jsx b/js/extension/plugins/cadastrapp/PlotSelection.jsx index 6b754d6..b063200 100644 --- a/js/extension/plugins/cadastrapp/PlotSelection.jsx +++ b/js/extension/plugins/cadastrapp/PlotSelection.jsx @@ -13,7 +13,7 @@ import { removePlots, zoomToSelection, loadInfo, - showLandedPropertyInformation + showLandedPropertyInformationByParcelle } from '../../actions/cadastrapp'; import { @@ -42,7 +42,7 @@ const PlotsSelection = connect((state) => ({ onRowsDeselected: deselectPlots, removePlots: removePlots, zoomToSelection: zoomToSelection, - showLandedPropertyInformation, + showLandedPropertyInformationByParcelle, onTabDelete: () => removePlotSelection() })(PS);