-
Notifications
You must be signed in to change notification settings - Fork 3
/
message-event.html
142 lines (124 loc) · 2.98 KB
/
message-event.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
139
140
141
142
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>StreamLayer-Message Event</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
<style type="text/css">
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
.banner {
margin-top: 5px;
margin-bottom: 5px;
color: #000080;
font-size: 2em;
font-weight: bold;
}
.bordered{
border-color: #dcdcdc;
border-style: solid;
border-width: thin;
padding: 10px;
}
.control{
float: left;
width: 25%;
height:15px;
text-align: center;
text-wrap: normal;
}
.padded {
margin-left: 10px;
padding-top: 10px;
}
#mapDiv {
width: 100%;
height: 70%;
}
</style>
<script src="https://js.arcgis.com/3.16/"></script>
</head>
<body>
<div class="banner">
Stream Layer: Message Event
</div>
<div id="mapDiv"></div>
<div class="padded" id="divFilterControls" style="position: relative;">
<div class="control bordered">
<span>Less than 18000 feet: </span>
<span id="lt18000"></span>
</div>
<div class="control bordered">
<span>Greater than 18000 feet: </span>
<span id="gt18000"></span>
</div>
</div>
</body>
<script>
require([
"esri/map",
"esri/layers/StreamLayer",
"esri/InfoTemplate",
"dojo/dom",
"dojo/dom-class",
"dojo/on",
"dojo/domReady!"
], function(
Map, StreamLayer, InfoTemplate,
dom, domClass, on){
var url = "http://ec2-75-101-155-202.compute-1.amazonaws.com:6080/arcgis/rest/services/AsdiTracks/StreamServer";
var map,
streamLayer,
flights = {},
gtCnt = 0,
ltCnt = 0,
intervalTimer;
updateCounts();
map = new Map("mapDiv", {
basemap: "topo",
center: [-90, 40],
zoom: 3
});
connectStreamLayer();
function connectStreamLayer(){
streamLayer = new StreamLayer(url, {
purgeOptions: { displayCount: 10000 },
outFields: ["*"],
infoTemplate: new InfoTemplate("Attributes", "${*}")
});
map.addLayer(streamLayer);
streamLayer.on("error", function(err){
console.log("error: ", err);
});
streamLayer.on("message", function(evt){
var id = evt.attributes.FltId,
alt = evt.attributes.AltitudeFeet,
oldalt = flights.hasOwnProperty(id) ? flights[id] : -1;
if(oldalt < 0) {
flights[id] = alt;
}
else {
oldalt < 18000 ? ltCnt-- : gtCnt--;
}
if (alt > 18000) {
gtCnt++;
}
else{
ltCnt++
}
});
intervalTimer = setInterval(updateCounts, 1000);
}
function updateCounts(){
dom.byId("gt18000").innerHTML = gtCnt;
dom.byId("lt18000").innerHTML = ltCnt;
}
});
</script>
</html>