-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuseFile.js
46 lines (43 loc) · 1.68 KB
/
useFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Copyright 2022, 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 { compose, mapPropsStream, withHandlers } from 'recompose';
import {selectLineFeature} from "@js/extension/utils/geojson";
/**
* Enhancer for processing json file with features
* Flatten features and then selects first line feature to build longitudinal profile out of it
*/
export default compose(
withHandlers({
useFlattenFeatures: ({ onClose = () => {}, changeGeometry = () => {}, warning = () => {}}) =>
(flattenFeatures, crs) => {
const { feature, coordinates } = selectLineFeature(flattenFeatures, crs);
if (feature && coordinates) {
changeGeometry({
type: "LineString",
coordinates,
projection: 'EPSG:3857'
});
onClose();
} else {
warning({
title: "notification.warning",
message: "longitudinal.warnings.noLineFeatureFound",
autoDismiss: 6,
position: "tc"
});
}
}
}),
mapPropsStream(props$ => props$.merge(
props$
.distinctUntilKeyChanged('flattenFeatures')
.filter(({flattenFeatures}) => flattenFeatures)
.do(({ flattenFeatures, crs, useFlattenFeatures = () => { }, warnings = []}) => useFlattenFeatures(flattenFeatures, crs, warnings))
.ignoreElements()
))
);