-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
138 lines (126 loc) · 3.89 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Cedar Charts</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.11/esri/themes/light/main.css"/>
<style>
html, body{
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#viewDiv { height: calc(100% - 300px); width: 100%; }
#chart1, #chart2 { height: 300px; width: 33%; box-shadow: 0px 0px 0px 1px black inset; float: left;}
#chart3 { height: 300px; width: 34%; box-shadow: 0px 0px 0px 1px black inset; float: right;}
</style>
<script src='https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.12/amcharts.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.12/serial.js'></script>
<script src='https://unpkg.com/@esri/cedar@1.0.0-beta.2/dist/umd/cedar.js'></script>
<script src='https://unpkg.com/@esri/cedar@1.0.0-beta.2/dist/umd/themes/amCharts/calcite.js'></script>
<script src="https://js.arcgis.com/4.11/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/geometry/Extent"
], function(Map, MapView, FeatureLayer, Extent) {
var map = new Map({
basemap: "topo",
})
var extent = new Extent ({
xmin: -83.7,
ymin: 36.4,
xmax: -75.7,
ymax: 39.6
})
var view = new MapView({
container: "viewDiv",
map: map,
extent: extent
});
var featureLayer = new FeatureLayer("https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_States_Generalized/FeatureServer/0",
{ outFields: ["*"],
renderer: {
type: "simple", // autocasts as new SimpleRenderer()
symbol: {
type: "simple-fill", // autocasts as new SimpleMarkerSymbol()
color: [0, 0, 0, 0.1],
outline: { // autocasts as new SimpleLineSymbol()
width: 0.5,
color: "white"
}
}
}
}
);
view.map.add(featureLayer);
view.whenLayerView(featureLayer).then(function(layerView) {
layerView.watch("updating", function(value) {
if (!value) {
layerView
.queryFeatures({
geometry: view.extent,
returnGeometry: true
})
.then(function(results) {
var features = [];
graphics = results.features;
graphics.forEach(function(result, index) {
var attributes = result.attributes;
features.push({
attributes: {
STATE_ABBR: attributes.STATE_ABBR,
POPULATION: attributes.POPULATION,
POP_SQMI: attributes.POP_SQMI,
MED_AGE: attributes.MED_AGE
}
});
});
loadCharts(features, "chart1", "POPULATION", "Population")
loadCharts(features, "chart2", "POP_SQMI", "Density (Square Mile)")
loadCharts(features, "chart3", "MED_AGE", "Median Age")
})
.catch(function(error) {
console.error("query failed: ", error);
});
}
});
});
function loadCharts(features, chartName, chartField, chartLabel){
features.sort(function(a, b) {
return b.attributes.POPULATION -a.attributes.POPULATION;
});
var definition = {
type: "bar",
datasets: [{
data: {
features: features
}
}],
series: [{
category: {
field: "STATE_ABBR",
label: "US State"
},
value: {
field: chartField,
label: chartLabel
}
}]
};
var cedarChart = new cedar.Chart(chartName, definition);
cedarChart.show();
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="chart1"></div>
<div id="chart2"></div>
<div id="chart3"></div>
</body>
</html>