Skip to content

Commit

Permalink
Support for navigation history in cesium (#1690)
Browse files Browse the repository at this point in the history
- Fixed infinite nested history, removing it (is not needed at all)
 - Removed wrong reducers for ZoomIn and ZoomOut buttons
 - Now the CHANGE_MAP_VIEW action accept a viewerOptions to store specific viewer options in history. It can be used for rotation in OpenLayers, for the future
  • Loading branch information
offtherailz authored Apr 6, 2017
1 parent e48116f commit ab81b0e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
5 changes: 3 additions & 2 deletions web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const CHANGE_MAP_STYLE = 'CHANGE_MAP_STYLE';
const CHANGE_ROTATION = 'CHANGE_ROTATION';


function changeMapView(center, zoom, bbox, size, mapStateSource, projection) {
function changeMapView(center, zoom, bbox, size, mapStateSource, projection, viewerOptions) {
return {
type: CHANGE_MAP_VIEW,
center,
zoom,
bbox,
size,
mapStateSource,
projection
projection,
viewerOptions
};
}

Expand Down
36 changes: 23 additions & 13 deletions web/client/components/map/cesium/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ let CesiumMap = React.createClass({
standardWidth: React.PropTypes.number,
standardHeight: React.PropTypes.number,
mousePointer: React.PropTypes.string,
zoomToHeight: React.PropTypes.number
zoomToHeight: React.PropTypes.number,
viewerOptions: React.PropTypes.object
},
getDefaultProps() {
return {
Expand All @@ -38,7 +39,12 @@ let CesiumMap = React.createClass({
mapOptions: {},
standardWidth: 512,
standardHeight: 512,
zoomToHeight: 80000000
zoomToHeight: 80000000,
viewerOptions: {
heading: 0,
pitch: -1 * Math.PI / 2,
roll: 0
}
};
},
getInitialState() {
Expand Down Expand Up @@ -190,26 +196,24 @@ let CesiumMap = React.createClass({
if (a === undefined || b === undefined) {
return false;
}
return ( a.toFixed(12) - (b.toFixed(12))) === 0;
// avoid errors like 44.40641479 !== 44.40641478999999
return ( a.toFixed(12) - (b.toFixed(12))) <= 0.000000000001;
};
const centerIsUpdate = isNearlyEqual(newProps.center.x, currentCenter.longitude) &&
isNearlyEqual(newProps.center.y, currentCenter.latitude);
const centerIsUpdate = !isNearlyEqual(newProps.center.x, currentCenter.longitude) ||
!isNearlyEqual(newProps.center.y, currentCenter.latitude);
const zoomChanged = newProps.zoom !== currentZoom;

// Do the change at the same time, to avoid glitches
if (centerIsUpdate || zoomChanged) {
this.map.camera.setView({
const position = {
destination: Cesium.Cartesian3.fromDegrees(
newProps.center.x,
newProps.center.y,
this.getHeightFromZoom(newProps.zoom)
),
orientation: {
heading: this.map.camera.heading,
pitch: this.map.camera.pitch,
roll: this.map.camera.roll
}
});
orientation: newProps.viewerOptions.orientation
};
this.map.camera.flyTo(position, {duration: 1});
}
},

Expand All @@ -234,7 +238,13 @@ let CesiumMap = React.createClass({
},
crs: 'EPSG:4326',
rotation: 0
}, size, this.props.id, this.props.projection );
}, size, this.props.id, this.props.projection, {
orientation: {
heading: this.map.camera.heading,
pitch: this.map.camera.pitch,
roll: this.map.camera.roll
}
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion web/client/plugins/ZoomIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ module.exports = {
priority: 1
}
}),
reducers: { zoomIn: require("../reducers/map")}
reducers: {}
};
2 changes: 1 addition & 1 deletion web/client/plugins/ZoomOut.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ module.exports = {
priority: 1
}
}),
reducers: {zoomOut: require("../reducers/map")}
reducers: {}
};
2 changes: 1 addition & 1 deletion web/client/utils/MapHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mapConfigHistory = (reducer) => {
let mapC = assign({}, newState.present, {mapStateSource: "undoredo", style: state.present.style, resize: state.present.resize});
unredoState = assign({}, newState, {present: mapC});
}
return unredoState || newState;
return unredoState || {past: newState.past, present: newState.present, future: newState.future};
};
};

Expand Down

0 comments on commit ab81b0e

Please sign in to comment.