forked from blueaccounting/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErieStat_ArcGIS_chart_Popup.html
441 lines (392 loc) · 16.7 KB
/
ErieStat_ArcGIS_chart_Popup.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<script src="js/ba_chart2.js"></script>
<!--<script src="js/export-csv_glc.js"></script>-->
<link rel="stylesheet" href="css/BA_Style.css">
<title>Intro to popups - 4.7</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#instruction {
z-index: 99;
position: absolute;
top: 15px;
left: 50%;
padding: 5px;
margin-left: -175px;
height: 20px;
width: 350px;
background: rgba(25, 25, 25, 0.8);
color: white;
}
.esri-popup .esri-popup-header .esri-title {
font-size: 18px;
font-weight: bolder;
}
/*.esri-popup .esri-popup-body .esri-popup-content {*/
/*font-size: 16px;*/
/*}*/
/*.esri-popup__content p{*/
/*font-size: 16px;*/
/*}*/
#chart{
visibility: hidden;
z-index: 99;
position: absolute;
top: 15px;
/*left: 70%;*/
right: 15px;
/*padding: 5px;*/
/*margin-right: 25px;*/
height: 400px;
/*width: 500px;*/
background: rgba(255, 255, 255, 0.8);
/*color: black;*/
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script src="https://js.arcgis.com/4.7/"></script>
<script src="//code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script>
require([
"esri/tasks/Locator",
"esri/Map",
"esri/views/MapView",
"esri/layers/MapImageLayer",
"esri/layers/FeatureLayer",
"esri/geometry/geometryEngine",
"esri/tasks/IdentifyTask",
"esri/tasks/QueryTask",
"esri/tasks/support/Query",
"esri/tasks/support/IdentifyParameters",
"dojo/_base/array",
"esri/Graphic",
"dojo/dom",
"dojo/on",
"dojo/dom-construct",
"dojo/domReady!"
], function(
Locator,
Map,
MapView,
MapImageLayer,
FeatureLayer,
geometryEngine,
IdentifyTask,
QueryTask,
Query,
IdentifyParameters,
arrayUtils,
Graphic,
dom,
on,
domConstruct
) {
var data;
$.getJSON("data/all_data2.json", function(d){
data = d;
});
var identifyTask, params;
var serviceURL = "https://gis.glc.org/server/rest/services/ErieStat/PriorityWatersheds/MapServer";
var metric = metrics.SRP_L_S;
// var unit = units.SRP_L_S;
var geometry;
var highlightSymbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
color: "#F3A51E",//"#07fcf0",
width: 3
};
var erieStatLayer = new MapImageLayer({
url: "https://gis.glc.org/server/rest/services/ErieStat/PriorityWatersheds/MapServer",
id: "esLayer",
sublayers: [{
id: 0
}, {
id: 1,
labelsVisible: true,
labelingInfo: [{
labelExpression: "[MergeNm]",
labelPlacement: "always-horizontal",
symbol: {
type: "text", // autocasts as new TextSymbol()
color: [255, 0, 0],
family: "Montserrat, sans-serif",
font: {
size: 12,
weight: "bolder",
style: "italic"
}
},
}],
}, {
id: 2,
opacity: 0.7,
// labelsVisible: true,
// labelingInfo: [{
// labelExpression: "[Name]",
// labelPlacement: "always-horizontal",
// symbol: {
// type: "text", // autocasts as new TextSymbol()
// color: [255, 0, 0, 0.85],
// family: "Montserrat, sans-serif",
// font: {
// size: 9,
// weight: "bolder",
// style: "italic"
// }
// },
// minScale: 18500000,
// maxScale: 9250000
// }]
}]
});
var pilotWatershedLayer = new FeatureLayer({
url: "https://gis.glc.org/server/rest/services/ErieStat/PriorityWatersheds/MapServer/1",
// opacity: 0.7
});
// Create the Map
var map = new Map({
basemap: "topo",
});
// Create the MapView
var view = new MapView({
container: "viewDiv",
spatialReference: erieStatLayer.spatialReference,
map: map,
center: [-82.4301521, 42.2370542],
zoom: 7
});
map.layers.add(erieStatLayer);
map.layers.add(pilotWatershedLayer);
// pilotWatershedLayer.when(function(){
// return pilotWatershedLayer.queryExtent();
// })
// .then(function(response){
// view.goTo(response.extent);
// });
view.whenLayerView(pilotWatershedLayer).then(function(layerView){
layerView.watch("updating", function(val){
// wait for the layer view to finish updating
if(!val){
layerView.queryExtent().then(function(response){
// go to the extent of all the graphics in the layer view
view.goTo(response.extent);
});
}
});
});
view.popup.set("dockEnabled", true);
view.popup.set("dockOptions", {
breakpoint: false,
position: "bottom-left",
buttonEnabled: false
} );
// view.on("layerview-create", function(event) {
// if (event.layer.id === "esLayer") {
// // Explore the properties of the housing layer's layer view here
// console.log("LayerView for New York housing density created!", event.layerView);
// }
// });
// on(erieStatLayer, "click", function(){
// var query = erieStatLayer.createQuery();
// });
// on(dom.byId("esLayer"), "click", function(){
// var query = erieStatLayer.createQuery();
// })
// view.on("click", function(event){
//
// var wellBuffers = geometryEngine.geodesicBuffer(wellPoints, [
// 50
// ], "meters",
// true);
//
// var query = pilotWatershedLayer.createQuery();
// query.geometry = wellBuffers;
// query.spatialRelationship = "intersects";
// var results = pilotWatershedLayer.queryFeatures(query).then(function (response){
// view.toTo(response.features.map(function(feature){
// return feature.geometry;
// }));
// });
// console.log(results);
//
// });
//
// view.popup.open({
// title: "test",
// location: event.mapPoint
//
// });
// erieStatLayer.when(function(){
// view.extent = erieStatLayer.fullExtent;
//// view.goTo(erieStatLayer.fullExtent);
// });
view.when(function() {
// executeIdentifyTask() is called each time the view is clicked
on(view, "click", executeIdentifyTask);
on(view, "click", executeQueryTask);
// Create identify task for the specified map service
identifyTask = new IdentifyTask(serviceURL);
// Set the parameters for the Identify
params = new IdentifyParameters();
params.tolerance = 3;
params.layerIds = [1];
params.layerOption = "top";
params.width = view.width;
params.height = view.height;
});
function executeQueryTask(event){
var queryparcelTask = new QueryTask({url: "https://gis.glc.org/server/rest/services/ErieStat/PriorityWatersheds/MapServer/1"});
var query = new Query();
query.geometry = event.mapPoint;
query.returnGeometry = true;
// query.where = "MergeNm = '" + value + "'";
queryparcelTask.execute(query).then(highlightFeature);//.then(zoomFeature);
}
function executeIdentifyTask(event) {
event.stopPropagation();
// Get the coordinates of the click on the view
// around the decimals to 3 decimals
// var lat = Math.round(event.mapPoint.latitude * 1000) / 1000;
// var lon = Math.round(event.mapPoint.longitude * 1000) / 1000;
//
// view.popup.open({
// // Set the popup's title to the coordinates of the clicked location
// title: "Reverse geocode: [" + lon + ", " + lat + "]",
// location: event.mapPoint // Set the location of the popup to the clicked location
// });
// Set the geometry to the location of the view click
params.geometry = event.mapPoint;
params.mapExtent = view.extent;
dom.byId("viewDiv").style.cursor = "wait";
identifyTask.execute(params).then(function(response) {
if(response == null){
return;
}
var results = response.results;
return arrayUtils.map(results, function(result) {
var feature = result.feature;
var layerName = result.layerName;
var w_name = feature.attributes["Watershed Name"];
feature.popupTemplate = {
title: "{Watershed Name}" + " Watershed",
content: function(value, key, data){
if(narratives[watershedNames[w_name]]){
return "<p style='font-size: 16px'>" + narratives[watershedNames[w_name]] + "</p>";
}else{
return "<p style='text-transform: uppercase;font-style: italic'>*Watershed Description unavailable.</p>"
}
}
};
var w_data = getWatershedMetric(data, watershedNames[w_name], metric);
var chart_size = [window.innerWidth*0.45, window.innerHeight*0.45];
buildChart(data, "chart", w_name, metric, units[metric],chart_size[0], chart_size[1]);
// var data_series = [];
// for (var i = 0; i < w_data.length; i++){
// data_series.push(w_data[i].Value);
// }
// var chart = createChart("chart", "column", w_name + " " + metric, data_series, ColorPicker.blue7,
// metric, unit);
$("#chart").css("visibility", "visible");
$("#chart").css("width", chart_size[0]);
$("#chart").css("height", chart_size[1]);
// $("#canvas-chart").css("left", window.innerWidth*0.7+"px");
// feature.attributes.layerName = layerName;
// if (layerName === 'Soil Survey Geographic') {
// feature.popupTemplate = { // autocasts as new PopupTemplate()
// title: "{Map Unit Name}",
// content: "<b>Dominant order:</b> {Dominant Order} ({Dom. Cond. Order %}%)" +
// "<br><b>Dominant sub-order:</b> {Dominant Sub-Order} ({Dom. Cond. Suborder %}%)" +
// "<br><b>Dominant Drainage Class:</b> {Dom. Cond. Drainage Class} ({Dom. Cond. Drainage Class %}%)" +
// "<br><b>Farmland Class:</b> {Farmland Class}"
// };
// }
// else if (layerName === 'State Soil Geographic') {
// feature.popupTemplate = { // autocasts as new PopupTemplate()
// title: "{Map Unit Name}",
// content: "<b>Dominant order:</b> {Dominant Order} ({Dominant %}%)" +
// "<br><b>Dominant sub-order:</b> {Dominant Sub-Order} ({Dominant Sub-Order %}%)"
// };
// }
// else if (layerName === 'Global Soil Regions') {
// feature.popupTemplate = { // autocasts as new PopupTemplate()
// title: layerName,
// content: "<b>Dominant order:</b> {Dominant Order}" +
// "<br><b>Dominant sub-order:</b> {Dominant Sub-Order}"
// };
// }
return feature;
});
}).then(showPopup);
function showPopup(response) {
if (response.length > 0) {
// if(window.innerHeight > window.innerWidth){
// view.popup.dockOptions = {
// position: "top-left"
// };
// }else{
// view.popup.dockOptions = {
// position: "top-left"
// };
// }
// if(window.innerHeight < 768 || window.innerWidth < 768){
// $("")
// }
// view.popup.dockOptions = {
// position: "top-left"
// };
view.popup.open({
features: response,
// location: event.mapPoint
});
}
dom.byId("viewDiv").style.cursor = "auto";
}
}
function zoomFeature(result){
view.graphics.removeAll();
var aoi = result.features;
geometry = aoi[0].geometry;
var graphicGeometry = new Graphic({
geometry: geometry,
symbol: highlightSymbol
});
view.goTo(aoi);
view.graphics.add(graphicGeometry);
}
function highlightFeature(result){
view.graphics.removeAll();
var aoi = result.features;
geometry = aoi[0].geometry;
var graphicGeometry = new Graphic({
geometry: geometry,
symbol: highlightSymbol
});
view.goTo({
center: [geometry.centroid.longitude, geometry.centroid.latitude]
});
view.graphics.add(graphicGeometry);
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<!--<div id="legend">Legend goes here. it is a long <br> paragraph with breaks</div>-->
<!--<div id="canvas-chart">-->
<div id="chart">
</div>
<!--</div>-->
</body>
</html>