forked from Esri/geodev-hackerlabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
138 lines (123 loc) · 3.51 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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Search with Query Task</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
<style>
html, body, #viewDiv {
padding: 0;
margin: 0;
height: 100%;
}
</style>
<script src="https://js.arcgis.com/4.1/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/tasks/QueryTask",
"esri/tasks/support/Query",
"esri/symbols/SimpleMarkerSymbol",
"esri/core/watchUtils",
"dojo/on",
"dojo/dom",
"dojo/domReady!"
], function(Map, MapView, FeatureLayer, QueryTask, Query, SimpleMarkerSymbol, watchUtils, on, dom) {
var map = new Map({
basemap: "dark-gray-vector"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-122.68, 45.52], // lon, lat
zoom: 10
});
// Create query task to reference the PDX_Rail_Stops_Styled feature layer
var queryTask = new QueryTask({
url: "http://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/PDX_Rail_Stops_Styled/FeatureServer/0"
});
// Only return three fields
var query = new Query({
returnGeometry: true,
outFields: ["STATION", "LINE", "TYPE"],
where: ""
});
// Perform query when page loads
getFeatures("TYPE = 'MAX'");
// Get features with sql clause
function getFeatures(sql) {
query.where = sql;
queryTask.execute(query).then(function(results) {
if (!view.ready) {
watchUtils.whenTrueOnce(view, "ready", function() {
addFeatures(results.features);
})
} else {
addFeatures(results.features);
}
});
}
// Add features as graphics
function addFeatures(features) {
var color,
symbol;
// Color
switch (features[0].attributes.TYPE) {
case "MAX":
color = [237, 81, 81]
break;
case "CR":
color = [167, 198, 54]
break;
case "SC":
color = [20, 158, 206]
break;
}
symbol = new SimpleMarkerSymbol({
color: color,
size: 8,
outline: {
color: [ 255, 255, 255 ],
width: 1
}
});
// Set symbol and popup template
for (var i=0; i < features.length; i++) {
var feature = features[i];
feature.symbol = symbol;
feature.popupTemplate = {
title: "{STATION}",
content: "This is a {TYPE} rail stop for the {LINE} line."
}
view.graphics.add(feature);
}
// Add graphics
view.graphics.removeAll();
view.graphics.addMany(features);
view.goTo(features);
view.popup.visible = false;
}
// Add select element to UI
view.ui.add(dom.byId("queryDiv"), {
position: "top-right"
});
// Select a sql query
on(dom.byId("queryDiv"), "change", function(e) {
var sql = e.target.value;
getFeatures(sql);
})
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<select id="queryDiv">
<option selected>TYPE = 'MAX'</option>
<option>TYPE = 'CR'</option>
<option>TYPE = 'SC'</option>
</select>
</body>
</html>