Skip to content

Commit efadeef

Browse files
committed
feat: add cesium-flyto
1 parent 84d722a commit efadeef

4 files changed

Lines changed: 109 additions & 0 deletions

File tree

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.114/Build/Cesium/Cesium.js"></script>
7+
<link href="https://cesium.com/downloads/cesiumjs/releases/1.114/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>

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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ScreenSpaceEventType } from "cesium";
2+
3+
export default class CesiumFlyTo {
4+
5+
constructor(viewer, modifier = ScreenSpaceEventType.LEFT_DOUBLE_CLICK, height = 300) {
6+
this.viewer = viewer;
7+
this.height = height;
8+
9+
this.viewer.screenSpaceEventHandler.setInputAction(this.onInputAction.bind(this), modifier);
10+
}
11+
12+
onInputAction(movement) {
13+
const scene = this.viewer.scene;
14+
const ray = scene.camera.getPickRay(movement.position);
15+
const intersection = scene.globe.pick(ray, scene);
16+
if (intersection) {
17+
const cartographic = scene.globe.ellipsoid.cartesianToCartographic(intersection);
18+
// FIXME: instead of adding a fixed height, follow the ray to the intersection minus the height
19+
cartographic.height += this.height;
20+
const destination = scene.globe.ellipsoid.cartographicToCartesian(cartographic);
21+
scene.camera.flyTo({
22+
destination: destination,
23+
duration: 0.75,
24+
orientation: {
25+
heading: scene.camera.heading,
26+
pitch: scene.camera.pitch,
27+
roll: scene.camera.roll,
28+
}
29+
});
30+
}
31+
}
32+
}

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)