Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to change map rotation #1273

Merged
merged 1 commit into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion web/client/actions/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ var {
CHANGE_ZOOM_LVL,
CHANGE_MAP_CRS,
CHANGE_MAP_STYLE,
CHANGE_ROTATION,
changeMapView,
clickOnMap,
changeMousePointer,
changeZoomLevel,
changeMapCrs,
changeMapStyle
changeMapStyle,
changeRotation
} = require('../map');

describe('Test correctness of the map actions', () => {
Expand Down Expand Up @@ -87,4 +89,14 @@ describe('Test correctness of the map actions', () => {
expect(retval.style).toBe(style);
expect(retval.mapStateSource).toBe(mapStateSource);
});

it('changeRotation', () => {
let angle = 0.5235987755982989;
let mapStateSource = "test";
let retval = changeRotation(angle, mapStateSource);
expect(retval).toExist();
expect(retval.type).toEqual(CHANGE_ROTATION);
expect(retval.rotation).toEqual(angle);
expect(retval.mapStateSource).toEqual(mapStateSource);
});
});
13 changes: 12 additions & 1 deletion web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PAN_TO = 'PAN_TO';
const ZOOM_TO_EXTENT = 'ZOOM_TO_EXTENT';
const CHANGE_MAP_CRS = 'CHANGE_MAP_CRS';
const CHANGE_MAP_STYLE = 'CHANGE_MAP_STYLE';
const CHANGE_ROTATION = 'CHANGE_ROTATION';


function changeMapView(center, zoom, bbox, size, mapStateSource, projection) {
Expand Down Expand Up @@ -73,6 +74,14 @@ function zoomToExtent(extent, crs) {
};
}

function changeRotation(rotation, mapStateSource) {
return {
type: CHANGE_ROTATION,
rotation,
mapStateSource
};
}

function changeMapStyle(style, mapStateSource) {
return {
type: CHANGE_MAP_STYLE,
Expand All @@ -89,12 +98,14 @@ module.exports = {
ZOOM_TO_EXTENT,
CHANGE_MAP_CRS,
CHANGE_MAP_STYLE,
CHANGE_ROTATION,
changeMapView,
clickOnMap,
changeMousePointer,
changeZoomLevel,
changeMapCrs,
zoomToExtent,
panTo,
changeMapStyle
changeMapStyle,
changeRotation
};
6 changes: 5 additions & 1 deletion web/client/components/map/openlayers/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var OpenlayersMap = React.createClass({
changeMeasurementState: React.PropTypes.func,
registerHooks: React.PropTypes.bool,
interactive: React.PropTypes.bool,
onInvalidLayer: React.PropTypes.func
onInvalidLayer: React.PropTypes.func,
bbox: React.PropTypes.object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't use the bbox, apart from the rotation, I would only have a rotation property

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well currently bbox is passed to the Map component in any case (see plugins/Map.jsx@render:

<plugins.Map id="map"
                {...this.props.options}
                {...this.props.map}), // <---
                ...

) so I don't think it makes sense to pass the rotation separately when bbox is passed regardless?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, nice

},
getDefaultProps() {
return {
Expand Down Expand Up @@ -312,6 +313,9 @@ var OpenlayersMap = React.createClass({
if (Math.round(newProps.zoom) !== this.props.zoom) {
view.setZoom(Math.round(newProps.zoom));
}
if (newProps.bbox && newProps.bbox.rotation !== undefined && newProps.bbox.rotation !== this.props.bbox.rotation) {
view.setRotation(newProps.bbox.rotation);
}
},
normalizeCenter: function(center) {
return ol.proj.transform(center, this.props.projection, 'EPSG:4326');
Expand Down
11 changes: 11 additions & 0 deletions web/client/reducers/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,15 @@ describe('Test the map reducer', () => {
expect(state.mapStateSource).toBe("test");
expect(state.style.width).toBe(100);
});
it('change map rotation', () => {
let rotation = 0.5235987755982989;
const action = {
type: 'CHANGE_ROTATION',
rotation: rotation,
mapStateSource: "test"
};
let state = mapConfig({}, action);
expect(state.bbox.rotation).toEqual(rotation);
expect(state.mapStateSource).toBe("test");
});
});
7 changes: 6 additions & 1 deletion web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

var {CHANGE_MAP_VIEW, CHANGE_MOUSE_POINTER,
CHANGE_ZOOM_LVL, CHANGE_MAP_CRS, ZOOM_TO_EXTENT, PAN_TO, CHANGE_MAP_STYLE} = require('../actions/map');
CHANGE_ZOOM_LVL, CHANGE_MAP_CRS, ZOOM_TO_EXTENT, PAN_TO, CHANGE_MAP_STYLE,
CHANGE_ROTATION} = require('../actions/map');


var assign = require('object-assign');
Expand Down Expand Up @@ -69,6 +70,10 @@ 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 CHANGE_ROTATION: {
let newBbox = assign({}, state.bbox, {rotation: action.rotation});
return assign({}, state, {bbox: newBbox, mapStateSource: action.mapStateSource});
}
default:
return state;
}
Expand Down