Skip to content

Commit

Permalink
Merge pull request #437 from geops/release-1.2.0-beta.2
Browse files Browse the repository at this point in the history
Release 1.2.0 beta.2
  • Loading branch information
friedjoff authored Sep 10, 2020
2 parents aad656b + 140cd48 commit e8e128d
Show file tree
Hide file tree
Showing 11 changed files with 2,395 additions and 1,599 deletions.
3,881 changes: 2,321 additions & 1,560 deletions lib/data/projections.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/data/sql/V5__export_projections.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SELECT DISTINCT processed_forest_ecoregion AS forest_ecoregion,
WHEN TRUE THEN 'unknown'
ELSE additional_meta.target
END AS additional,
CASE silver_fir_area is null
CASE silver_fir_area_meta.target is null
WHEN TRUE THEN 'unknown'
ELSE silver_fir_area_meta.target
END AS silver_fir_area,
Expand Down
8 changes: 7 additions & 1 deletion lib/src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const residents = (c) => !types.treeType.find((t) => t.code === c).nonresident;
* @param {object} location
* @param {object} location.forestType Required code for forest type at current location.
* @param {object} [location.transitionForestType] Optional code for transition forest type at current location.
* @param {boolean} [mergeLevel4] Optional flag to merge level 4 into level 3.
* @returns {array} Nested arrays of recommended tree type codes.
*/
function list(location = {}) {
function list(location = {}, mergeLevel4 = false) {
const { forestType, transitionForestType } = location;
if (!forestType) {
throw new Error(`forestType is missing`);
Expand Down Expand Up @@ -66,6 +67,11 @@ function list(location = {}) {
lists[3] = union(lists[3], transitionLists[3]).sort(byNumber);
}

if (mergeLevel4) {
lists[2] = union(lists[2], lists[3]).sort(byNumber);
lists[3] = [];
}

return lists.map((trees) =>
trees.filter(residents).concat(trees.filter(nonresidents)),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/recommend.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function recommend(location = {}, projections = [], future = false) {
difference(t123, union(...pAll)),
),
), // Level 15/16/17
intersection(today4, ...p4), // Level 18 (attention)
union(today4, ...p4), // Level 18 (attention)
isFuture(difference(xor(...p4), ...today4)), // Level 19 (attention)
);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@geops/tree-app",
"description": "Web app for tree recommendations.",
"license": "MIT",
"version": "1.2.0-beta.1",
"version": "1.2.0-beta.2",
"private": true,
"dependencies": {
"history": "4.10.1",
Expand Down
16 changes: 13 additions & 3 deletions src/components/MapLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import mapPositionIcon from '../icons/mapPosition.svg';
import { MapContext } from '../spatial/components/Map';
import Mapbox from '../spatial/components/layer/Mapbox';
import Vector from '../spatial/components/layer/Vector';
import { setMapLocation } from '../store/actions';
import { setFormLocation, setMapLocation } from '../store/actions';

const getKey = (sl) =>
(
Expand Down Expand Up @@ -43,20 +43,30 @@ const vectorSource = new VectorSource({
features: [iconFeature],
});

const initialFormLocation = {
forestEcoregion: null,
altitudinalZone: null,
silverFirArea: null,
targetAltitudinalZone: null,
};

function MapLocation() {
const map = useContext(MapContext);
const dispatch = useDispatch();
const mapLocation = useSelector((state) => state.mapLocation);

useEffect(() => {
const handleCoords = ({ coordinate }) => {
const handleCoords = ({ coordinate }, resetFormLocation = true) => {
iconFeature.getGeometry().setCoordinates(coordinate);
const pixel = map.getPixelFromCoordinate(coordinate);
const features = map.getFeaturesAtPixel(pixel) || [];
const location = features
.filter((feature) => feature.properties && feature.properties.code)
.reduce(featuresToLocation, {});
dispatch(setMapLocation({ ...location, coordinate: to2056(coordinate) }));
if (resetFormLocation) {
dispatch(setFormLocation(initialFormLocation));
}
};
const waitForLoad = () => {
const mapboxLayer = map
Expand All @@ -65,7 +75,7 @@ function MapLocation() {
.find((layer) => layer instanceof Mapbox.Layer);
if (mapboxLayer && mapLocation && mapLocation.coordinate) {
const coordinate = to3857(mapLocation.coordinate);
mapboxLayer.on('loadend', () => handleCoords({ coordinate }));
mapboxLayer.on('loadend', () => handleCoords({ coordinate }, false));
map.getLayers().un('propertychange', waitForLoad);
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/ProjectionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function ProjectionForm() {
[value] = options[field];
} else if (options[field].includes(location[name])) {
value = location[name];
} else if (options[field].includes('unknown')) {
value = 'unknown';
}
return value;
};
Expand Down
21 changes: 19 additions & 2 deletions src/components/ProjectionResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function getPane(scenario, projection, language, t) {
}
);
}
const checkFields = ['slope', 'additional', 'silverFirArea', 'relief'];

function ProjectionResult() {
const { location, projectionMode, projectionResult } = useSelector(
Expand All @@ -79,6 +80,8 @@ function ProjectionResult() {
const TAZModerate = getAZ(location.targetAltitudinalZoneModerate);
const TAZExtreme = getAZ(location.targetAltitudinalZoneExtreme);
const sameAltitudinalZone = AZToday === TAZModerate && AZToday === TAZExtreme;
const { options } =
projectionMode === 'm' ? projectionResult.extreme : projectionResult.form;

const panes = [];
panes.push({
Expand Down Expand Up @@ -118,9 +121,18 @@ function ProjectionResult() {
}

const finalPanes = panes.filter((p) => p);
const foundProjection = sameAltitudinalZone || finalPanes.length > 2;
const checkField =
foundProjection === false &&
checkFields.find(
(field) =>
Array.isArray(options[field]) &&
options[field].filter((o) => o !== 'unknown').length > 0,
);

return location.altitudinalZone && location.forestType ? (
<div className={styles.container}>
{sameAltitudinalZone || finalPanes.length > 2 ? (
{foundProjection ? (
<Tab
className={styles.tab}
menu={{
Expand All @@ -133,7 +145,12 @@ function ProjectionResult() {
/>
) : (
<Header className={styles.notFound} inverted>
{t('recommendation.noProjectionFound')}
{t(
checkField
? `recommendation.checkField`
: 'recommendation.noProjectionFound',
{ field: t(`${checkField}.label`) },
)}
</Header>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectionTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TreeTypeList from './TreeTypeList';
import styles from './ProjectionTab.module.css';

function ProjectionTab({ location }) {
const [one, two, three] = useMemo(() => list(location), [location]);
const [one, two, three] = useMemo(() => list(location, true), [location]);
const { t } = useTranslation();
return (
<Tab.Pane>
Expand Down
57 changes: 28 additions & 29 deletions src/components/Recommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,35 @@ function Recommendation({ sameAltitudinalZone }) {
<TreeTypeList className={styles.bold} codes={r[8]} />
</Grid.Column>
</Grid.Row>
{r[9].length > 0 ||
(r[10].length > 0 && (
<Grid.Row centered>
<Grid.Column textAlign="center" width={4} tablet={2} mobile={2}>
<AttentionIcon fill="white" className={styles.icon} />
</Grid.Column>
<Grid.Column width={1}>
<HelpModal header={t('help.recommendationAttentionHeader')}>
<Trans i18nKey="help.recommendationAttention">
help text{' '}
<a
href="https://www.bafu.admin.ch/bafu/de/home/themen/wald/publikationen-studien/publikationen/vollzugshilfe-waldschutz.html"
rel="noopener noreferrer"
target="_blank"
>
link
</a>
</Trans>
</HelpModal>
</Grid.Column>
<Grid.Column width={11}>
<div className={styles.medium}>
<TreeTypeList className={styles.bold} codes={r[9]} />
<div className={styles.yellow}>
<TreeTypeList className={styles.bold} codes={r[10]} />
</div>
{(r[9].length > 0 || r[10].length > 0) && (
<Grid.Row centered>
<Grid.Column textAlign="center" width={4} tablet={2} mobile={2}>
<AttentionIcon fill="white" className={styles.icon} />
</Grid.Column>
<Grid.Column width={1}>
<HelpModal header={t('help.recommendationAttentionHeader')}>
<Trans i18nKey="help.recommendationAttention">
help text{' '}
<a
href="https://www.bafu.admin.ch/bafu/de/home/themen/wald/publikationen-studien/publikationen/vollzugshilfe-waldschutz.html"
rel="noopener noreferrer"
target="_blank"
>
link
</a>
</Trans>
</HelpModal>
</Grid.Column>
<Grid.Column width={11}>
<div className={styles.medium}>
<TreeTypeList className={styles.bold} codes={r[9]} />
<div className={styles.yellow}>
<TreeTypeList className={styles.bold} codes={r[10]} />
</div>
</Grid.Column>
</Grid.Row>
))}
</div>
</Grid.Column>
</Grid.Row>
)}
<Grid.Row>
<Grid.Column textAlign="center" width={4} />
<Grid.Column width={12}>
Expand Down
1 change: 1 addition & 0 deletions src/i18n/resources/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@
},
"recommendation": {
"attention": "Achtung",
"checkField": "Keine Empfehlung möglich, bitte prüfen Sie folgende Angabe: {{ field }}",
"future": "In Zukunft zusätzlich passende Baumarten einblenden",
"header": "Empfehlung",
"negative": "Reduzieren",
Expand Down

0 comments on commit e8e128d

Please sign in to comment.