Skip to content

Commit

Permalink
Fixes #2665 Add an action to force resize of Map component (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Mar 2, 2018
1 parent 4064803 commit a1ff7d2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
10 changes: 9 additions & 1 deletion web/client/actions/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var {
UPDATE_VERSION,
INIT_MAP,
ZOOM_TO_EXTENT,
RESIZE_MAP,
creationError,
changeMapView,
clickOnMap,
Expand All @@ -31,7 +32,8 @@ var {
changeRotation,
updateVersion,
initMap,
zoomToExtent
zoomToExtent,
resizeMap
} = require('../map');

describe('Test correctness of the map actions', () => {
Expand Down Expand Up @@ -151,4 +153,10 @@ describe('Test correctness of the map actions', () => {
expect(retval).toExist();
expect(retval.type).toEqual(INIT_MAP);
});

it('resizeMap', () => {
const retval = resizeMap();
expect(retval).toExist();
expect(retval.type).toEqual(RESIZE_MAP);
});
});
11 changes: 10 additions & 1 deletion web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const CHANGE_ROTATION = 'CHANGE_ROTATION';
const CREATION_ERROR_LAYER = 'CREATION_ERROR_LAYER';
const UPDATE_VERSION = 'UPDATE_VERSION';
const INIT_MAP = 'INIT_MAP';
const RESIZE_MAP = 'RESIZE_MAP';

function creationError(options) {
return {
Expand Down Expand Up @@ -130,6 +131,12 @@ function initMap() {
};
}

function resizeMap() {
return {
type: RESIZE_MAP
};
}

module.exports = {
CHANGE_MAP_VIEW,
CLICK_ON_MAP,
Expand All @@ -145,6 +152,7 @@ module.exports = {
CREATION_ERROR_LAYER,
UPDATE_VERSION,
INIT_MAP,
RESIZE_MAP,
changeMapView,
clickOnMap,
changeMousePointer,
Expand All @@ -158,5 +166,6 @@ module.exports = {
zoomToPoint,
creationError,
updateVersion,
initMap
initMap,
resizeMap
};
8 changes: 8 additions & 0 deletions web/client/reducers/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,12 @@ describe('Test the map reducer', () => {
let state = mapConfig({}, action);
expect(state.version).toEqual(version);
});

it('force resize update of map', () => {
const action = {
type: 'RESIZE_MAP'
};
let state = mapConfig({}, action);
expect(state.resize).toEqual(1);
});
});
5 changes: 4 additions & 1 deletion web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

var {CHANGE_MAP_VIEW, CHANGE_MOUSE_POINTER,
CHANGE_ZOOM_LVL, CHANGE_MAP_CRS, CHANGE_MAP_SCALES, ZOOM_TO_EXTENT, PAN_TO,
CHANGE_MAP_STYLE, CHANGE_ROTATION, UPDATE_VERSION, ZOOM_TO_POINT} = require('../actions/map');
CHANGE_MAP_STYLE, CHANGE_ROTATION, UPDATE_VERSION, ZOOM_TO_POINT, RESIZE_MAP} = require('../actions/map');
const {isArray} = require('lodash');


Expand Down Expand Up @@ -133,6 +133,9 @@ function mapConfig(state = null, action) {
case CHANGE_MAP_STYLE: {
return assign({}, state, {mapStateSource: action.mapStateSource, style: action.style, resize: state.resize ? state.resize + 1 : 1});
}
case RESIZE_MAP: {
return assign({}, state, {resize: state.resize ? state.resize + 1 : 1});
}
case CHANGE_ROTATION: {
let newBbox = assign({}, state.bbox, {rotation: action.rotation});
return assign({}, state, {bbox: newBbox, mapStateSource: action.mapStateSource});
Expand Down

0 comments on commit a1ff7d2

Please sign in to comment.