Skip to content

Commit 2bfe4e6

Browse files
committed
examples(Camera animation): cleanup example code
1 parent dbd9ee3 commit 2bfe4e6

File tree

1 file changed

+60
-49
lines changed

1 file changed

+60
-49
lines changed

examples/misc_camera_animation.html

+60-49
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,82 @@
22
<head>
33
<title>Itowns - Globe travel</title>
44

5-
<style type="text/css">
6-
#miniDiv {
7-
display: block;
8-
margin-bottom: 20px;
9-
margin-right: 20px;
10-
position: absolute;
11-
width:100px;
12-
height:100px;
13-
left: 20;
14-
bottom: 0;
15-
color: white;
16-
}
17-
</style>
185
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
198
<link rel="stylesheet" type="text/css" href="css/example.css">
209
<link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
2110

22-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2311
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
2412
</head>
2513
<body>
2614
<div id="viewerDiv"></div>
27-
<script src="js/GUI/GuiTools.js"></script>
15+
16+
<!-- Import iTowns source code -->
2817
<script src="../dist/itowns.js"></script>
18+
<script src="js/GUI/LoadingScreen.js"></script>
19+
20+
2921
<script type="text/javascript">
30-
// # Simple Globe viewer
31-
/* global itowns, Promise */
32-
// Define initial camera position
33-
var placement = {
22+
23+
24+
25+
// ---------- CREATE A GlobeView FOR SUPPORTING DATA VISUALIZATION : ----------
26+
27+
// Define camera initial position
28+
const placement = {
3429
coord: new itowns.Coordinates('EPSG:4326', 2.351323, 48.856712),
3530
range: 25000000,
3631
}
3732

3833
// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
39-
var viewerDiv = document.getElementById('viewerDiv');
34+
const viewerDiv = document.getElementById('viewerDiv');
35+
36+
// Create a GlobeView
37+
const view = new itowns.GlobeView(viewerDiv, placement);
38+
39+
// Setup loading screen and debug menu
40+
setupLoadingScreen(viewerDiv, view);
41+
42+
// Display a realistic atmosphere
43+
view.getLayerById('atmosphere').setRealisticOn(true);
44+
45+
46+
// ---------- DISPLAY ORTHO-IMAGES : ----------
47+
48+
// Add one imagery layer to the scene. This layer's properties are defined in a json file, but it could be
49+
// defined as a plain js object. See `Layer` documentation for more info.
50+
itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
51+
config.source = new itowns.WMTSSource(config.source);
52+
view.addLayer(
53+
new itowns.ColorLayer('Ortho', config),
54+
);
55+
});
56+
4057

41-
// Instanciate iTowns GlobeView*
42-
var view = new itowns.GlobeView(viewerDiv, placement);
43-
var time = 50000;
44-
var pathTravel = [];
45-
const atmosphere = view.getLayerById('atmosphere');
46-
atmosphere.setRealisticOn(true);
4758

59+
// ---------- DISPLAY A DIGITAL ELEVATION MODEL : ----------
60+
61+
// Add two elevation layers, each with a different level of detail. Here again, each layer's properties are
62+
// defined in a json file.
63+
function addElevationLayerFromConfig(config) {
64+
config.source = new itowns.WMTSSource(config.source);
65+
view.addLayer(
66+
new itowns.ElevationLayer(config.id, config),
67+
);
68+
}
69+
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);
70+
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
71+
72+
73+
74+
// ---------- ANIMATE CAMERA : ----------
75+
76+
const time = 50000;
77+
78+
// Array containing CameraTransformOptions (see
79+
// http://www.itowns-project.org/itowns/docs/#api/Controls/CameraUtils) for each step of the animation.
80+
const pathTravel = [];
4881
pathTravel.push({ coord: new itowns.Coordinates('EPSG:4326', 2.0889, 42.809), range: 100000, time: time * 0.2 });
4982
pathTravel.push({ range: 13932, time: time * 0.2, tilt: 7.59, heading: 110.9 });
5083
pathTravel.push({ tilt: 8, time: time * 0.2 });
@@ -56,33 +89,11 @@
5689
pathTravel.push({ coord: new itowns.Coordinates('EPSG:4326', 9.114, 41.973), tilt: 15.92, heading: 13.18, time: time });
5790
pathTravel.push({ range: 16601, time: time * 0.2 });
5891

59-
function addLayerCb(layer) {
60-
return view.addLayer(layer);
61-
}
62-
6392
function travel() {
64-
var camera = view.camera.camera3D;
6593
return itowns.CameraUtils
66-
.sequenceAnimationsToLookAtTarget(view, camera, pathTravel);
94+
.sequenceAnimationsToLookAtTarget(view, view.camera.camera3D, pathTravel);
6795
}
6896

69-
// Add one imagery layer to the scene
70-
// This layer is defined in a json file but it could be defined as a plain js
71-
// object. See Layer* for more info.
72-
itowns.Fetcher.json('./layers/JSONLayers/Ortho.json').then(function _(config) {
73-
config.source = new itowns.WMTSSource(config.source);
74-
var layer = new itowns.ColorLayer('Ortho', config);
75-
view.addLayer(layer);
76-
});
77-
// Add two elevation layers.
78-
// These will deform iTowns globe geometry to represent terrain elevation.
79-
function addElevationLayerFromConfig(config) {
80-
config.source = new itowns.WMTSSource(config.source);
81-
var layer = new itowns.ElevationLayer(config.id, config);
82-
view.addLayer(layer);
83-
}
84-
itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addElevationLayerFromConfig);
85-
itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addElevationLayerFromConfig);
8697

8798
// Listen for globe full initialisation event
8899
view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function init() {

0 commit comments

Comments
 (0)