-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(globe-fly-to): add fly to in story mode
- Loading branch information
1 parent
41df51f
commit 5d20ae0
Showing
13 changed files
with
167 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {GlobeView} from '../types/globe-view'; | ||
|
||
export const SET_FLY_TO = 'SET_FLY_TO'; | ||
|
||
export interface SetFlyToAction { | ||
type: typeof SET_FLY_TO; | ||
view: GlobeView; | ||
} | ||
|
||
const setFlyToAction = (view: GlobeView): SetFlyToAction => ({ | ||
type: SET_FLY_TO, | ||
view | ||
}); | ||
|
||
export default setFlyToAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,64 @@ | ||
import 'cesium/Build/Cesium/Cesium'; | ||
|
||
import {radToDeg, degToRad} from './math-helpers'; | ||
|
||
import {GlobeView} from '../types/globe-view'; | ||
|
||
const Cesium = window.Cesium; | ||
|
||
// set the camera according to the given globe view | ||
// set the camera according to the given globe view (lng, lat in radians) | ||
export function setGlobeView(viewer: Cesium.Viewer, view: GlobeView): void { | ||
const {position, orientation} = view; | ||
const cesiumView = { | ||
destination: Cesium.Cartesian3.fromRadians( | ||
destination: Cesium.Cartesian3.fromDegrees( | ||
position.longitude, | ||
position.latitude, | ||
position.height | ||
), | ||
orientation | ||
orientation: { | ||
heading: degToRad(orientation.heading), | ||
pitch: degToRad(orientation.pitch), | ||
roll: degToRad(orientation.roll) | ||
} | ||
}; | ||
|
||
viewer.scene.camera.setView(cesiumView); | ||
} | ||
|
||
// set the camera according to the given globe view (lng, lat in degrees) | ||
export function flyToGlobeView(viewer: Cesium.Viewer, view: GlobeView): void { | ||
const {position, orientation} = view; | ||
const cesiumView = { | ||
destination: Cesium.Cartesian3.fromDegrees( | ||
position.longitude, | ||
position.latitude, | ||
position.height | ||
), | ||
orientation: { | ||
heading: degToRad(orientation.heading), | ||
pitch: degToRad(orientation.pitch), | ||
roll: degToRad(orientation.roll) | ||
} | ||
}; | ||
|
||
viewer.scene.camera.flyTo(cesiumView); | ||
} | ||
|
||
// get the globe view from the current cesium camera | ||
export function getGlobeView(viewer: Cesium.Viewer): GlobeView { | ||
const camera = viewer.scene.camera; | ||
const position = camera.positionCartographic; | ||
|
||
return { | ||
position: { | ||
longitude: position.longitude, | ||
latitude: position.latitude, | ||
longitude: radToDeg(position.longitude), | ||
latitude: radToDeg(position.latitude), | ||
height: position.height | ||
}, | ||
orientation: { | ||
heading: camera.heading, | ||
pitch: camera.pitch, | ||
roll: camera.roll | ||
heading: radToDeg(camera.heading), | ||
pitch: radToDeg(camera.pitch), | ||
roll: radToDeg(camera.roll) | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function radToDeg(rad: number): number { | ||
return (rad * 180) / Math.PI; | ||
} | ||
|
||
export function degToRad(deg: number): number { | ||
return (deg * Math.PI) / 180; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {SET_FLY_TO, SetFlyToAction} from '../actions/set-fly-to'; | ||
|
||
import {State} from './index'; | ||
import {GlobeView} from '../types/globe-view'; | ||
|
||
const initialState = null; | ||
|
||
function flyToReducer( | ||
state: GlobeView | null = initialState, | ||
action: SetFlyToAction | ||
): GlobeView | null { | ||
switch (action.type) { | ||
case SET_FLY_TO: | ||
return action.view; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export function flyToSelector(state: State): GlobeView | null { | ||
return state.flyTo; | ||
} | ||
|
||
export default flyToReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters