From a1ff7d26ad3996bff413812c873fd5b6573dc168 Mon Sep 17 00:00:00 2001 From: stefano bovio Date: Fri, 2 Mar 2018 10:47:27 +0100 Subject: [PATCH] Fixes #2665 Add an action to force resize of Map component (#2666) --- web/client/actions/__tests__/map-test.js | 10 +++++++++- web/client/actions/map.js | 11 ++++++++++- web/client/reducers/__tests__/map-test.js | 8 ++++++++ web/client/reducers/map.js | 5 ++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/web/client/actions/__tests__/map-test.js b/web/client/actions/__tests__/map-test.js index 5de484abf5..157b6fbce5 100644 --- a/web/client/actions/__tests__/map-test.js +++ b/web/client/actions/__tests__/map-test.js @@ -20,6 +20,7 @@ var { UPDATE_VERSION, INIT_MAP, ZOOM_TO_EXTENT, + RESIZE_MAP, creationError, changeMapView, clickOnMap, @@ -31,7 +32,8 @@ var { changeRotation, updateVersion, initMap, - zoomToExtent + zoomToExtent, + resizeMap } = require('../map'); describe('Test correctness of the map actions', () => { @@ -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); + }); }); diff --git a/web/client/actions/map.js b/web/client/actions/map.js index a2f07401f7..4591887b21 100644 --- a/web/client/actions/map.js +++ b/web/client/actions/map.js @@ -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 { @@ -130,6 +131,12 @@ function initMap() { }; } +function resizeMap() { + return { + type: RESIZE_MAP + }; +} + module.exports = { CHANGE_MAP_VIEW, CLICK_ON_MAP, @@ -145,6 +152,7 @@ module.exports = { CREATION_ERROR_LAYER, UPDATE_VERSION, INIT_MAP, + RESIZE_MAP, changeMapView, clickOnMap, changeMousePointer, @@ -158,5 +166,6 @@ module.exports = { zoomToPoint, creationError, updateVersion, - initMap + initMap, + resizeMap }; diff --git a/web/client/reducers/__tests__/map-test.js b/web/client/reducers/__tests__/map-test.js index d64a69dcbb..8c405049ee 100644 --- a/web/client/reducers/__tests__/map-test.js +++ b/web/client/reducers/__tests__/map-test.js @@ -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); + }); }); diff --git a/web/client/reducers/map.js b/web/client/reducers/map.js index b41e2f4af1..245d515ab4 100644 --- a/web/client/reducers/map.js +++ b/web/client/reducers/map.js @@ -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'); @@ -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});