Skip to content

Commit

Permalink
Default map state should be null
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnafu committed Dec 23, 2016
1 parent 14b30df commit bae2a61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ FeatureGridMap.defaultProps = {

module.exports = connect((state) => {
return {
map: (state.map && state.map) || (state.config && state.config.map),
map: state.map || (state.config && state.config.map),
layers: state.config && state.config.layers || [],
features: state.featuregrid.jsonlayer.features || [],
selFeatures: state.featuregrid.select || null
Expand Down
20 changes: 11 additions & 9 deletions web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var assign = require('object-assign');
var MapUtils = require('../utils/MapUtils');
var CoordinatesUtils = require('../utils/CoordinatesUtils');

function mapConfig(state = {}, action) {
function mapConfig(state = null, action) {
switch (action.type) {
case CHANGE_MAP_VIEW:
const {type, ...params} = action;
Expand All @@ -35,17 +35,19 @@ function mapConfig(state = {}, action) {
});
case CHANGE_MAP_SCALES:
if (action.scales) {
const dpi = state.mapOptions && state.mapOptions.view && state.mapOptions.view.DPI || null;
const resolutions = MapUtils.getResolutionsForScales(action.scales, state.projection || "EPSG:4326", dpi);
const dpi = state && state.mapOptions && state.mapOptions.view && state.mapOptions.view.DPI || null;
const resolutions = MapUtils.getResolutionsForScales(action.scales, (state && state.projection) || "EPSG:4326", dpi);
// add or update mapOptions.view.resolutions
let mapOptions = assign({}, state.mapOptions);
mapOptions.view = assign({}, mapOptions.view, {
resolutions: resolutions
});
return assign({}, state, {
mapOptions: mapOptions
mapOptions: assign({}, state && state.mapOptions,
{
view: assign({}, state && state.mapOptions && state.mapOptions.view, {
resolutions: resolutions
})
})
});
} else if (state.mapOptions && state.mapOptions.view && state.mapOptions.view && state.mapOptions.view.resolutions) {
} else if (state && state.mapOptions && state.mapOptions.view && state.mapOptions.view && state.mapOptions.view.resolutions) {
// TODO: this block is removing empty objects from the state, check if it really needed
// deeper clone
let newState = assign({}, state);
newState.mapOptions = assign({}, newState.mapOptions);
Expand Down

0 comments on commit bae2a61

Please sign in to comment.