forked from marvinmarnold/eyeonsurveillance.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcgis-index.html
195 lines (171 loc) · 6.13 KB
/
arcgis-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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<html>
<head>
<meta name="description" content="ArcGIS JavaScript Tutorials: Query a feature layer">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>ArcGIS JavaScript Tutorials: Query a feature layer</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.14/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.14/"></script>
</head>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/Graphic"
],
function(
Map, MapView, FeatureLayer, GraphicsLayer, Graphic
) {
var map = new Map({
basemap: "topo-vector"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-90.0663, 29.957436],
zoom: 9
});
//*** CHALLENGE ***//
var sql = "STATE_NAME = 'Louisiana'";
view.when(function(){
//*** ADD ***//
queryFeatureLayer(view.center, 991500, "intercects")
queryFeatureLayerView(view.center, 991500, "intersects")
//*** CHALLENGE ***//
// queryFeatureLayer(view.center, 1500, "intersects", sql)
// queryFeatureLayerView(view.center, 1500, "intersects", sql)
});
view.on("click", function(event){
//*** ADD ***//
queryFeatureLayer(event.mapPoint, 991500, "intersects")
queryFeatureLayerView(event.mapPoint, 991500, "intersects");
//*** CHALLENGE ***//
// queryFeatureLayer(event.mapPoint, 1500, "intersects", sql)
// queryFeatureLayerView(event.mapPoint, 1500, "intersects", sql)
});
// Reference the feature layer to query
var featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/VhMjCzR3cIjEkh7L/arcgis/rest/services/RTCC_Cameras/FeatureServer/0/",
});
// Add a graphics layer to hold features and draw data
var graphicsLayer = new GraphicsLayer();
map.add(graphicsLayer);
function addGraphics(result) {
console.log("addGraphics")
console.log(result.features)
result.features.forEach(function(element) {
console.log(element.geometry.latitude+","+element.geometry.longitude)
// console.log(element.geometry.latitude+","+element.geometry.longitude+","+Math.random())
})
graphicsLayer.removeAll();
result.features.forEach(function(feature){
var g = new Graphic({
geometry: feature.geometry,
attributes: feature.attributes,
symbol: {
type: "simple-marker",
color: [0,0,0],
outline: {
width: 2,
color: [0,255,255],
},
size: "20px"
},
popupTemplate: {
title: "{TRL_NAME}",
content: "This a {PARK_NAME} trail located in {CITY_JUR}."
}
});
graphicsLayer.add(g);
});
}
// Server-side query
function queryFeatureLayer(point, distance, spatialRelationship, sqlExpression) {
var query = {
geometry: point,
distance: distance,
// spatialRelationship: spatialRelationship,
outFields: ["*"],
returnGeometry: true,
// where: sqlExpression
};
featureLayer.queryFeatures(query).then(function(result) {
console.log("queryFeatures")
console.log(result.features)
addGraphics(result);
});
}
// Client-side query
function queryFeatureLayerView(point, distance, spatialRelationship, sqlExpression){
if (!map.findLayerById(featureLayer.id)) {
featureLayer.outFields = ["*"];
map.add(featureLayer,0);
}
var query = {
geometry: point,
distance: distance,
// spatialRelationship: spatialRelationship,
outFields: ["*"],
returnGeometry: true,
// where: sqlExpression
};
// Wait for the layerview to be ready and then query features
view.whenLayerView(featureLayer).then(function(featureLayerView) {
if (featureLayerView.updating) {
var handle = featureLayerView.watch("updating", function(isUpdating){
if (!isUpdating) {
featureLayerView.queryFeatures(query).then(function(result) {
addGraphics(result)
});
handle.remove();
}
});
} else {
featureLayerView.queryFeatures(query).then(function(result) {
addGraphics(result);
});
}
});
}
// CHALLENGE: Find a feature and show pop-ups (client-side)
// view.when(function(){
// view.whenLayerView(featureLayer).then(function(featureLayerView) {
// view.on("pointer-move", function(event){
// view.hitTest(event).then(function(response){
// // Only return features for the feature layer
// var feature = response.results.filter(function (result) {
// return result.graphic.layer === featureLayer;
// })[0].graphic;
// if (feature) {
// // Show popup for new features only
// if (!view.popup.features.length || view.popup.features.length && (view.popup.features[0].attributes.FID !== feature.attributes.FID)) {
// view.popup.open({
// title: feature.attributes.TRL_NAME,
// content: "This a " + feature.attributes.PARK_NAME + " trail located in " + feature.attributes.CITY_JUR + ".",
// location: feature.geometry
// });
// }
// }
// });
// });
// });
// });
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>