Skip to content

Commit 8bab185

Browse files
committed
feat: add cesium-flyto
1 parent f83d9aa commit 8bab185

6 files changed

Lines changed: 118 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ npx parcel serve demos/cesium-view-cube.html --open
2020
npx parcel serve demos/cesium-first-person-mode.html --open
2121
npx parcel serve demos/cesium-sphere-camera.html --open
2222
npx parcel serve demos/cesium-binoculars.html --open
23+
npx parcel serve demos/cesium-flyto.html --open
2324
```
2425

2526
## Guide

demos/cesium-flyto.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<script src="https://cesium.com/downloads/cesiumjs/releases/1.120/Build/Cesium/Cesium.js"></script>
7+
<link href="https://cesium.com/downloads/cesiumjs/releases/1.120/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
8+
<style>
9+
html, body, #cesiumContainer {
10+
height: 100%;
11+
margin: 0;
12+
}
13+
</style>
14+
</head>
15+
16+
<body>
17+
<div id="cesiumContainer"></div>
18+
<button id="activate" type="button">toggle mode</button>
19+
<script type="module">
20+
import {createViewer} from './setup.js';
21+
import CesiumFlyto from '../packages/cesium-flyto/cesium-flyto.js';
22+
23+
createViewer('cesiumContainer').then(viewer => {
24+
const mode = new CesiumFlyto(viewer);
25+
document.querySelector('#activate').addEventListener('click', () => mode.active = !mode.active);
26+
});
27+
</script>
28+
</body>
29+
30+
</html>

demos/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<li><a href="cesium-first-person-mode.html">cesium-first-person-mode: a first person navigation mode that uses the Pointer Lock API</a></li>
1313
<li><a href="cesium-sphere-camera.html">cesium-sphere-camera: a camera mode that allows the user to rotate the camera around a position</a></li>
1414
<li><a href="cesium-view-cube.html">cesium-view-cube: a view cube widget</a></li>
15+
<li><a href="cesium-flyto.html">cesium-flyto:</a></li>
1516
</ul>
1617
</body>
1718

packages/cesium-flyto/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2024-present, camptocamp SA
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ScreenSpaceEventType } from "cesium";
2+
3+
export default class CesiumFlyTo {
4+
5+
/**
6+
* @param {import('cesium').Viewer} viewer
7+
* @param {ScreenSpaceEventType} [modifier=ScreenSpaceEventType.LEFT_DOUBLE_CLICK]
8+
* @param {number} [height=300]
9+
* @param {number} [duration]
10+
*/
11+
constructor(viewer, modifier = ScreenSpaceEventType.LEFT_DOUBLE_CLICK, height = 300, duration = undefined) {
12+
this.viewer = viewer;
13+
this.height = height;
14+
this.duration = duration;
15+
this.viewer.screenSpaceEventHandler.setInputAction(this.onInputAction.bind(this), modifier);
16+
}
17+
18+
onInputAction(movement) {
19+
const scene = this.viewer.scene;
20+
const ray = scene.camera.getPickRay(movement.position);
21+
const intersection = scene.globe.pick(ray, scene);
22+
if (intersection) {
23+
const cartographic = scene.globe.ellipsoid.cartesianToCartographic(intersection);
24+
// FIXME: instead of adding a fixed height, follow the ray to the intersection minus the height
25+
cartographic.height += this.height;
26+
const destination = scene.globe.ellipsoid.cartographicToCartesian(cartographic);
27+
scene.camera.flyTo({
28+
destination: destination,
29+
duration: this.duration,
30+
orientation: {
31+
// FIXME: use ray heading ?
32+
heading: scene.camera.heading,
33+
pitch: scene.camera.pitch,
34+
roll: scene.camera.roll,
35+
}
36+
});
37+
}
38+
}
39+
}

packages/cesium-flyto/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@geoblocks/cesium-flyto",
3+
"version": "0.0.0",
4+
"license": "BSD-3-Clause",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/geoblocks/cesium-helpers/",
8+
"directory": "packages/cesium-flyto"
9+
},
10+
"main": "cesium-flyto.js",
11+
"module": "cesium-flyto.js",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"peerDependencies": {
16+
"cesium": "1.x"
17+
}
18+
}

0 commit comments

Comments
 (0)