Skip to content

Commit

Permalink
feat: run locate function on location changes
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Mar 10, 2020
1 parent 2073987 commit 2c3ef95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const SET_FORM_LOCATION = 'SET_FORM_LOCATION';
export const SET_LOCATE_RESULT = 'SET_LOCATE_RESULT';
export const SET_LOCATION = 'SET_LOCATION';
export const SET_MAP_LAYER = 'SET_MAP_LAYER';
export const SET_MAP_LOCATION = 'SET_MAP_LOCATION';
Expand All @@ -12,6 +13,10 @@ export function setFormLocation(formLocation) {
return { type: SET_FORM_LOCATION, formLocation };
}

export function setLocateResult(locateResult) {
return { type: SET_LOCATE_RESULT, locateResult };
}

export function setLocation(location) {
return { type: SET_LOCATION, location };
}
Expand Down
10 changes: 9 additions & 1 deletion src/store/enhancers/projection.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-console */
import { project } from '@geops/tree-lib';
import { locate, project } from '@geops/tree-lib';
import { applyMiddleware } from 'redux';

import {
SET_FORM_LOCATION,
SET_MAP_LOCATION,
SET_PROJECTION_MODE,
setLocation,
setLocateResult,
setProjectionResult,
setTargetAltitudinalZone,
} from '../actions';
Expand Down Expand Up @@ -35,6 +36,13 @@ const projection = store => next => action => {
? mapLocation.targetAltitudinalZoneExtreme
: formLocation.targetAltitudinalZone;
store.dispatch(setTargetAltitudinalZone(targetAltitudinalZone));
try {
const locateResult = locate(location);
console.log(locateResult, location);
store.dispatch(setLocateResult(locateResult));
} catch (error) {
console.log('Locate error: ', error);
}
try {
const projectionResult = project(location, targetAltitudinalZone);
store.dispatch(setProjectionResult(projectionResult));
Expand Down
12 changes: 8 additions & 4 deletions src/store/reducers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
SET_LOCATION,
SET_FORM_LOCATION,
SET_LOCATE_RESULT,
SET_LOCATION,
SET_MAP_LAYER,
SET_MAP_LOCATION,
SET_MAP_VIEW,
Expand Down Expand Up @@ -50,12 +51,15 @@ const getFormLocation = (state, action) => {

function tree(state = initialState, action) {
switch (action.type) {
case SET_LOCATION: {
return { ...state, location: action.location };
}
case SET_FORM_LOCATION: {
return { ...state, formLocation: getFormLocation(state, action) };
}
case SET_LOCATE_RESULT: {
return { ...state, locateResult: action.locateResult };
}
case SET_LOCATION: {
return { ...state, location: action.location };
}
case SET_MAP_LAYER:
return { ...state, mapLayer: action.mapLayer };
case SET_MAP_LOCATION: {
Expand Down

0 comments on commit 2c3ef95

Please # to comment.