forked from CartoDB/labs-cesiumjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevation.html
107 lines (88 loc) · 4.55 KB
/
elevation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>CartoDB - Cesium example (elevation)</title>
<link href="//cartodb-libs.global.ssl.fastly.net/cartodbui/assets/3.4.9/favicons/favicon.ico?1411985985" rel="shortcut icon" type="image/vnd.microsoft.icon" />
<link href='https://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css'>
<link href="css/guide.css" media="screen" rel="stylesheet" type="text/css" />
<link href="Cesium/Widgets/widgets.css" media="screen" rel="stylesheet" type="text/css" />
<link href="Cesium/Widgets/lighter.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/app.css" media="screen" rel="stylesheet" type="text/css" />
<script src="Cesium/Cesium.js"></script>
<style>
html, body, #cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.core.js"></script>
<script>
Cesium.BingMapsApi.defaultKey = 'AvpJKQgK8f4xjkNrV3GokGh1TtL5zlxAyeLpxpvXZPZrcFgJZwuWSecC7z_vB9TU';
// New datasource which uses geoJSON from SQL for x, y and column "ele" for z.
var GeoJsonZDataSource = Cesium.GeoJsonDataSource;
GeoJsonZDataSource.prototype.load = function (data) {
data = data.features;
if (!Cesium.defined(data)) {
throw new Cesium.DeveloperError("data must be defined.");
}
var entities = this._entityCollection;
entities.suspendEvents();
entities.removeAll();
for (var i = 0; i < data.length; i++) {
var start = Cesium.Cartesian3.fromDegrees(data[i].geometry.coordinates[0], data[i].geometry.coordinates[1], 0.0);
var end = Cesium.Cartesian3.fromDegrees(data[i].geometry.coordinates[0], data[i].geometry.coordinates[1], data[i].properties.ele);
var polyline = new Cesium.PolylineGraphics();
polyline.show = new Cesium.ConstantProperty(true);
polyline.positions = new Cesium.ConstantProperty([start, end]);
polyline.width = new Cesium.ConstantProperty(2);
polyline.followSurface = new Cesium.ConstantProperty(false);
var entity = new Cesium.Entity(i);
entity.polyline = polyline;
entities.add(entity);
}
entities.resumeEvents();
this._changed.raiseEvent(this);
};
var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider : new Cesium.CesiumTerrainProvider({
url : '//assets.agi.com/stk-terrain/world',
requestVertexNormals: true
}),
baseLayerPicker: false,
timeline: false,
animation: false
});
viewer.scene.globe.enableLighting = true;
// Set initial position and rotation
var ellipsoid = Cesium.Ellipsoid.WGS84;
var west = Cesium.Math.toRadians(-0.75);
var south = Cesium.Math.toRadians(38.35);
var east = Cesium.Math.toRadians(-0.74);
var north = Cesium.Math.toRadians(38.33);
var rotation = Cesium.Math.toRadians(30);
var extent = new Cesium.Rectangle(west, south, east, north);
viewer.camera.viewRectangle(extent, ellipsoid);
viewer.camera.lookUp(rotation);
// SQL API layer
var dataSource = new GeoJsonZDataSource();
viewer.dataSources.add(dataSource);
var sql = new cartodb.SQL({user: 'cartotraining', format: 'geoJSON'});
sql.execute("SELECT the_geom,ele FROM elevation_cesium")
.done(function (data) {
dataSource.load(data);
})
.error(function (errors) {
console.log("errors:" + errors);
});
</script>
</body>
</html>