-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexample.html
executable file
·160 lines (143 loc) · 4.2 KB
/
example.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Custom Websocket</title>
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#viewDiv {
height: 100%;
width: 100%;
}
body {
background-color: #fff;
overflow: hidden;
font-family: sans-serif;
}
#info {
background: rgb(218 209 220);
}
#connectionStatus {
color: white;
background: #e33a3a;
padding: 8px 16px;
display: none;
}
#updateRate {
color: rgb(78, 78, 78);
background: rgb(218 209 220);
padding: 8px 16px;
display: none;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/next/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/next/"></script>
<script>
var streamLayer;
var view;
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/StreamLayer",
"esri/layers/FeatureLayer",
], function(Map, MapView, StreamLayer, FeatureLayer) {
// Stream layer connecting to our custom websocket service
const layer = new StreamLayer({
popupTemplate: {
content: "OBJECTID={OBJECTID}, TRACKID={TRACKID}",
},
webSocketUrl: "ws://localhost:8000",
objectIdField: "OBJECTID",
fields: [
{
name: "OBJECTID",
alias: "ObjectId",
type: "oid",
},
{
name: "TRACKID",
alias: "TrackId",
type: "oid",
}
],
timeInfo: {
trackIdField: "TRACKID"
},
geometryType: "point",
maxReconnectionAttempts: 100,
maxReconnectionInterval: 10,
renderer: {
type: "simple",
symbol: {
type: "simple-marker",
size: "8px",
color: "gray",
},
},
});
// Display the railroads that we are used to generate feature in our stream service
const railroads = new FeatureLayer({
url: "http://services2.arcgis.com/FiaPA4ga0iQKduv3/arcgis/rest/services/Transportation_v1/FeatureServer/9",
definitionExpression: "BASENAME='Seaboard Coast Line'" ,
minScale: 0,
renderer: {
type: "simple",
symbol: {
type: "simple-line",
width: "1px",
color: "gray",
},
},
})
const map = new Map({
basemap: "gray",
layers: [ railroads, layer ]
});
view = new MapView({
container: "viewDiv",
zoom: 8,
center: [-81.515, 27.665],
map,
});
view.whenLayerView(layer).then(layerView => {
// Display connection status and current update rate
const connectionStatusDiv = document.getElementById("connectionStatus");
const updateRateDiv = document.getElementById("updateRate");
const info = document.getElementById("info");
layerView.on("update-rate", (updateRate) => {
updateRateDiv.innerHTML = `${updateRate.client} (${updateRate.websocket} service)`
})
view.ui.add(info, "top-right");
connectionStatusDiv.style.display = "inline-flex";
updateRateDiv.style.display = "inline-flex";
layerView.watch("connectionStatus", function(value) {
if (value === "connected") {
connectionStatusDiv.style.backgroundColor = "#4e4e4e";
connectionStatusDiv.innerHTML = "connected";
} else {
connectionStatusDiv.style.backgroundColor = "orange";
connectionStatusDiv.innerHTML = "reconnecting";
}
});
}).catch(e => console.log(e))
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="info">
<div id="connectionStatus" class="esri-widget">Disconnected</div>
<div id="updateRate" class="esri-widget">0 (0)</div>
</div>
</body>
</html>