Skip to content

Commit ef11033

Browse files
committed
implemented remove layer
uninstalled lodash
1 parent b046f46 commit ef11033

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"bluebird": "^3.5.2",
88
"immutable": "^3.8.2",
99
"leaflet": "^1.3.3",
10-
"lodash": "^4.17.10",
1110
"moment": "^2.22.2",
1211
"prop-types": "^15.6.2",
1312
"react": "^16.4.2",

src/action-creators/map.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { ADD_LAYER, REMOVE_LAYER } from '../action-types/map';
22

3-
export const createAddLayerAction = (name, data) => {
3+
export const createAddLayerAction = (id, data) => {
44
return {
55
type: ADD_LAYER,
66
payload: {
7-
name,
7+
id,
88
data,
99
},
1010
};
1111
};
1212

13-
export const createRemoveLayerAction = (name) => {
13+
export const createRemoveLayerAction = (id) => {
1414
return {
1515
type: REMOVE_LAYER,
1616
payload: {
17-
name,
17+
id,
1818
},
1919
};
2020
};

src/components/Layers/Layers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export default class Layers extends Component {
7272
// return new TextDecoder("utf-8").decode(data)
7373
// })
7474
.then(({data})=> data)
75-
.then(geojson => this.props.addLayer(layer.name, geojson));
75+
.then(geojson => this.props.addLayer(layer.id, geojson));
76+
} else {
77+
this.props.removeLayer(layer.id)
7678
}
7779

7880
const layersList = this.state.layersList.map(
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { connect } from 'react-redux';
1+
import { connect } from "react-redux";
22

3-
import LayerInput from '../../components/Layers';
4-
import { createAddLayerAction } from '../../action-creators/map';
3+
import LayerInput from "../../components/Layers";
4+
import {
5+
createAddLayerAction,
6+
createRemoveLayerAction
7+
} from "../../action-creators/map";
58

6-
function mapDispatchToProps (dispatch) {
9+
function mapDispatchToProps(dispatch) {
710
return {
8-
addLayer: (name, data) => dispatch(createAddLayerAction(name, data)),
11+
addLayer: (id, data) => dispatch(createAddLayerAction(id, data)),
12+
removeLayer: id => dispatch(createRemoveLayerAction(id))
913
};
1014
}
1115

12-
const LayerInputContainer = connect(null, mapDispatchToProps)(LayerInput);
16+
const LayerInputContainer = connect(
17+
null,
18+
mapDispatchToProps
19+
)(LayerInput);
1320

14-
export default LayerInputContainer;
21+
export default LayerInputContainer;

src/store/reducers/layers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import _ from 'lodash';
21
import Immutable from 'immutable';
32

43
import { ADD_LAYER, REMOVE_LAYER } from '../../action-types/map';
@@ -12,7 +11,7 @@ export default function (state = initialState, action) {
1211
newState = state.push(action.payload);
1312
break;
1413
case REMOVE_LAYER:
15-
newState = _.pullAllBy(state, action.payload, 'name');
14+
newState = state.filter(layer => action.payload.id !== layer.id )
1615
break;
1716
default:
1817
newState = state;

0 commit comments

Comments
 (0)