diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-22 08:48:38 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:06:06 +0200 |
| commit | 3bf073f46e74667df4d2be9488a9f8f44ac84421 (patch) | |
| tree | 75731c952d6965cf5075b03f504193936348780f /src/store | |
| parent | d6455f1c9e57934b76ce95b3fb204072300a1991 (diff) | |
Make timeline clickable
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/middlewares/viewport-adjustment.js | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/store/middlewares/viewport-adjustment.js b/src/store/middlewares/viewport-adjustment.js index 75ad6a2f..e5500d5e 100644 --- a/src/store/middlewares/viewport-adjustment.js +++ b/src/store/middlewares/viewport-adjustment.js @@ -1,4 +1,5 @@ import {SET_MAP_DIMENSIONS, setMapPosition, setMapScale} from "../../actions/map"; +import {SET_CURRENT_DATACENTER} from "../../actions/topology/building"; import { MAP_MAX_SCALE, MAP_MIN_SCALE, @@ -10,12 +11,23 @@ import {calculateRoomListBounds} from "../../util/tile-calculations"; export const viewportAdjustmentMiddleware = store => next => action => { const state = store.getState(); - if (action.type === SET_MAP_DIMENSIONS && state.currentDatacenterId !== -1) { - const roomIds = state.objects.datacenter[state.currentDatacenterId].roomIds; + + let datacenterId = -1; + let mapDimensions = {}; + if (action.type === SET_CURRENT_DATACENTER && action.datacenterId !== -1) { + datacenterId = action.datacenterId; + mapDimensions = state.map.dimensions; + } else if (action.type === SET_MAP_DIMENSIONS && state.currentDatacenterId !== -1) { + datacenterId = state.currentDatacenterId; + mapDimensions = {width: action.width, height: action.height}; + } + + if (datacenterId !== -1) { + const roomIds = state.objects.datacenter[datacenterId].roomIds; const rooms = roomIds.map(id => Object.assign({}, state.objects.room[id])); rooms.forEach(room => room.tiles = room.tileIds.map(tileId => state.objects.tile[tileId])); - const viewportParams = calculateParametersToZoomInOnRooms(rooms, action.width, action.height); + const viewportParams = calculateParametersToZoomInOnRooms(rooms, mapDimensions.width, mapDimensions.height); store.dispatch(setMapPosition(viewportParams.newX, viewportParams.newY)); store.dispatch(setMapScale(viewportParams.newScale)); } |
