-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (84 loc) · 4.12 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cesiumjs.org/releases/1.53/Build/Cesium/Widgets/widgets.css">
<link href="https://fonts.googleapis.com/css?family=Lobster|Open+Sans" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<script src="https://cesiumjs.org/releases/1.53/Build/Cesium/Cesium.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/1.3.4/chroma.min.js"></script>
<title>Environment & Food</title>
</head>
<body>
<div id="cesiumContainer"></div>
<div class="legend">
<h4> Environment & Food </h4>
<p><a href="index.html">Calories</a> | <a href="sugar.html">Sugars</a> | <a href="fat.html">Total Fat</a></p>
<br>
<div id="patches"></div><br/>
<p> Virtual globe Lib: cesium.js | BaseMap: Mapbox</p>
<p> Author: Xiang (Peter) Chen | Arkansas Tech University</p>
</div>
<script>
//create a cesium view, and use the mapbox dark map as the base map.
var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider : new Cesium.MapboxImageryProvider({
mapId : 'mapbox.dark',
accessToken : 'pk.eyJ1IjoiamFrb2J6aGFvIiwiYSI6ImNpenh0dG41ZjAyY3gzMXFsdTJqbm5oNmwifQ.ucAGT19EfvxX2EUaHUwAxA'
}),
// terrainProvider: new Cesium.CesiumTerrainProvider({
// url: '//assets.agi.com/stk-terrain/world'
// }),
vrButton: false, // virtual reality support
infoBox: true, // pick a feature and show its attributes
sceneModePicker: true, // 2d, 2.5d and 3d
navigationHelpButton: false,
baseLayerPicker : false,
fullscreenButton: true,
geocoder: false,
skyBox: false,
homeButton: false,
animation: false,
timeline: false
});
// determine the number of classes and their respective break values.
var grades = [400, 800, 1200,1600,2000,2400];
// determine the color.md ramp. The number of colors is determined by the number of classes.
// try different interpolation method lch, lab, hsl
//var colors = chroma.scale(['yellow', 'navy']).mode('hsl').colors(grades.length);
var colors = chroma.scale('YlOrRd').colors(grades.length);
// create the legend
var labels = [];
// set the color.md based on the class which the input value falls in.
function setColor(d) {
for (var j = 0; j < grades.length - 1; j++) {
if ( d >= grades[j] && d < grades[j+1] ) return colors[j];
}
if (d >= grades[grades.length - 1]) return colors[grades.length -1];
}
var dataSource = Cesium.GeoJsonDataSource.load('assets/rests-polygon.geojson').then(
function(dataSource) {
var p = dataSource.entities.values;
for (var i = 0; i < p.length; i++) {
p[i].polygon.material = Cesium.Color.fromCssColorString(setColor(p[i].properties.avg_calories));
p[i].polygon.extrudedHeight = p[i].properties.avg_calories * p[i].properties.avg_calories * 0.00005;
p[i].polygon.outline = false;
}
viewer.dataSources.add(dataSource);
viewer.zoomTo(dataSource);
}
);
// insert legend patches.
for (var i = 0; i < grades.length - 1; i++) {
labels.push('<i style="background:' + colors[i] + '"></i> <p>' + grades[i] + ' - ' + (grades[i + 1] + 1).toString() + '</p>');
}
labels.push('<i style="background:' + colors[grades.length - 1] + '"></i> <p>' + (grades[grades.length - 1] +1 ).toString() + ' +' + '</p>');
$("#patches").html(labels.join(''));
// hide the credit banner, however you should credit the map libraries or data somewhere else.
document.getElementsByClassName("cesium-widget-credits")[0].style.visibility = "hidden";
</script>
</body>
</html>