-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
623 lines (548 loc) · 16.6 KB
/
main.js
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/layers/TileLayer",
"esri/layers/VectorTileLayer",
"esri/widgets/Expand",
"esri/widgets/Legend",
"esri/widgets/TimeSlider",
"esri/tasks/QueryTask",
"esri/rest/support/Query",
"esri/rest/support/StatisticDefinition",
"esri/popup/content/CustomContent"
], function (Map, MapView, FeatureLayer, TileLayer, VectorTileLayer, Expand, Legend, TimeSlider, QueryTask, Query, StatisticDefinition) {
// state boundary feature layer
const state = new FeatureLayer({
portalItem: {
id: "1173c9605a2e47a3835452b67de39b79"
}
});
// county boundary feature layer
var county = new FeatureLayer({
portalItem: {
id: "ba98baef19d447ca83fb2084c396acde"
},
outFields: ["*"],
minScale: 0,
maxScale: 0,
popupTemplate: {
title: "{Name} County",
content: queryWellCounts
}
});
///// Pop up function for counties
var queryWellsTask = new QueryTask({
url: "https://services.arcgis.com/ZzrwjTRez6FJiOq4/arcgis/rest/services/OGHistory/FeatureServer/0"
});
function queryWellCounts(target) {
var counts = new StatisticDefinition({
statisticType: "count",
onStatisticField: "API",
outStatisticFieldName: "count_county"
});
var query = new Query({
geometry: target.graphic.geometry,
outFields: ["*"],
spatialRelationship: "intersects",
timeExtent: timeSlider.timeExtent,
outStatistics: [counts]
});
var yearOnly = {year:'numeric'}; //set to show year only in date strings
return queryWellsTask.execute(query).then(function(result) {
var stats = result.features[0].attributes;
if (stats.count_county==1) {
return (
"Between " +
"<b>" +
timeSlider.timeExtent.start.toLocaleDateString("en-us",yearOnly) +
"</b> and <b>" +
timeSlider.timeExtent.end.toLocaleDateString("en-us",yearOnly) +
"</b> there was " +
"<b>" +
stats.count_county +
"</b>" +
" well in {NAME} County.")
}else{
return(
"Between " +
"<b>" +
timeSlider.timeExtent.start.toLocaleDateString("en-us",yearOnly) +
"</b> and <b>" +
timeSlider.timeExtent.end.toLocaleDateString("en-us",yearOnly) +
"</b> there were " +
"<b>" +
stats.count_county +
"</b>" +
" wells in {NAME} County." )
}
});
}
let OGLayerView;
// oil and gas well location layer
const layer = new FeatureLayer({
portalItem: {
id: "dd28d5595a2940929574e79522bb4245"
}
});
let tableView;
// oil and gas layer hidden
const table = new FeatureLayer({
portalItem: {
id: "c27b246d53f0430d8eb781e31e9a3c70"
},
visible:false
});
// Create Map
const map = new Map({
basemap: {
baseLayers:[
new TileLayer({
portalItem: {
id:"a66bfb7dd3b14228bf7ba42b138fe2ea" //firefly
}
}),
new TileLayer({
portalItem: {
id: "a8588e0401e246469260f03ee44d69f1" //shaded releif
},
blendMode: "multiply"
}),
new VectorTileLayer({
portalItem: {
id:"30d6b8271e1849cd9c3042060001f425" // firefly reference
}
})
]
},
layers: [state,county,layer,table]
});
// Set the map view
var view = new MapView({
container: "viewDiv",
map: map,
center: [-109.71988355828537, 38.96201717886498], // Centered on Thompson Springs 38.96201717886498, -109.71988355828537
zoom:6.999
});
/*
view.popup.watch("selectedFeature", function(e) {
view.graphics.removeAll();
if (e && e.geometry) {
view.graphics.add(
new Graphic({
geometry: e.geometry,
symbol: {
type: "simple-fill",
style: "none",
outline: {
color: "#6600FF",
width: 2
}
}
})
);
}
});
*/
// Create a collapsible legend
const legendExpand = new Expand({
collapsedIconClass: "esri-icon-collapse",
expandIconClass: "esri-icon-expand",
expandTooltip: "Legend",
view: view,
content: new Legend({
view:view,
layerInfos: [{
layer:layer,
title:"Oil and Gas Surface Well Locations (1970-Present)"
}]
}),
expanded: false,
group: "top-left"
});
view.ui.add(legendExpand, "top-left");
// Create events for the time slider
const events = [
{name:`Creation of SITLA`, date: 1995},
{name:`Great Recession`, date: 2008},
{name: `Covid-19 Pandemic`, date: 2020}
];
// Create time slider with interval set to 1 years
const timeSlider = new TimeSlider({
container: "timeSlider",
playRate: 1000,
stops: {
interval: {
value: 1,
unit: "years"
}
},
// configure ticks for dates
tickConfigs: [{
mode: "position",
values: [
new Date(1970, 0, 1), new Date(1975, 0, 1), new Date(1980, 0 , 1), new Date(1985, 0, 1),
new Date(1990, 0, 1), new Date(1995, 0, 1), new Date(2000, 0, 1), new Date(2005, 0, 1),
new Date(2010, 0, 1), new Date(2015, 0, 1), new Date(2020, 0, 1)
].map((date) => date.getTime()),
labelsVisible: true,
labelFormatFunction: (value) => {
const date = new Date(value);
return `${date.getUTCFullYear()}`;
},
tickCreatedFunction: (value, tickElement, labelElement) => {
tickElement.classList.add("custom-ticks2");
labelElement.classList.add("custom-labels2");
}
}, {
mode: "position",
values: events
.map((event) => new Date(event.date, 0, 1))
.map((date) => date.getTime()),
labelsVisible: true,
labelFormatFunction: (value) => {
const event = events.find(
(s) => new Date(s.date, 0, 1).getTime() === value
);
return event.name;
},
tickCreatedFunction: (value, tickElement, labelElement) => {
tickElement.classList.add("custom-ticks");
labelElement.classList.add("custom-labels");
}
}
]
});
// add time slider to view
view.ui.add(timeSlider);
// Creating view layer for hidden layer
view.whenLayerView(table).then((layerView) => {
tableView = layerView;
// creating view layer for visible layer
view.whenLayerView(layer).then((layerView) => {
OGLayerView = layerView;
// Setting start date for time slider
const start = new Date(1970, 0, 1);
// Extent for time Slider
timeSlider.fullTimeExtent = {
start: start,
end: new Date(2020,0,1)
};
// Show 1 year intervals
let end = new Date(start);
end.setDate(end.getDate() + 1825); // the number here is in days (1825 = 5 years)
timeSlider.timeExtent = {start,end};
});
//// Table view
// watch timeslider timeExtent change
timeSlider.watch("timeExtent", () => {
//oil wells that popped up before the end of the current time extent
tableView.definitionExpression =
"OrigComplDate <=" + timeSlider.timeExtent.end.getTime();
// add grayscale effect to old wells (may or may not keep this)
tableView.effect = {
filter: {
timeExtent:timeSlider.timeExtent
},
excludedEffect: "grayscale(20%) opacity(80)"
};
OGLayerView.definitionExpression =
"OrigComplDate <=" + timeSlider.timeExtent.end.getTime();
// add grayscale effect to old wells (may or may not keep this)
OGLayerView.effect = {
filter: {
timeExtent:timeSlider.timeExtent
},
excludedEffect: "grayscale(80%) opacity(30%)"
};
// Run statistics for well counts within current time extent
const statQuery = OGLayerView.effect.filter.createQuery();
statQuery.outStatistics = [
wellCounts
];
layer.queryFeatures(statQuery).then((result) => {
statDiv.innerHTML = "";
if (result.error) {
return result.error;
} else {
if (result.features.length >= 1) {
var yearOnly = {year:'numeric'}; //set to show year only in date strings
const yearHtml =
"Between " +
"<span>" +
timeSlider.timeExtent.start.toLocaleDateString("en-US", yearOnly) +
"</span> and <span>" +
timeSlider.timeExtent.end.toLocaleDateString("en-US", yearOnly) +
"</span> the Oil and Gas Industry in Utah:</br></br>";
var thousandsSep = {maximumFractionDigits:0}; //create thousands seperators
const oilHtml =
"Had <span>" +
result.features[0].attributes["Well_Counts"].toLocaleString("en-US", thousandsSep) +
"</span> oil and gas wells.";
statDiv.innerHTML =
yearHtml + "<ul style = 'margin-bottom:0'><li>" + oilHtml + "</li></ul>";
}
}
})
// Run statistics for GDP/employment/salary within current time extent
const tableQuery = tableView.effect.filter.createQuery();
tableQuery.outStatistics = [
GDPAvg,
employmentCount,
wageAvg
];
table.queryFeatures(tableQuery).then((result) => {
statsDiv1.innerHTML = "";
if (result.error) {
return result.error;
} else {
if (result.features.length >= 1) {
const GDPHtml = result.features[0].attributes["GDP_Average"] == null
?"GDP data not available"
:"Added an average of " +
"<span>" +
result.features[0].attributes["GDP_Average"].toFixed(1) +
"</span> million dollars to Utah's Gross Domestic Product per year" +
".<br />";
var thousandsSep = {maximumFractionDigits:0}; //create thousands seperators
const employmentHtml = result.features[0].attributes["Employment_Count"] == null
?"Employment data not available"
:"Employed " +
"<span>" +
result.features[0].attributes["Employment_Count"].toLocaleString("en-US", thousandsSep) +
"</span> full and part time employees (direct and supporting employees)" +
".<br />";
const WageHtml = result.features[0].attributes["Wage_Average"] == null
?"Salary data not available"
:"Paid employees " +
"<span> $"+
result.features[0].attributes["Wage_Average"].toFixed(2) +
"/hr</span> on average (adjusted for inflation).";
statsDiv1.innerHTML =
"<ul style='margin-bottom:0'>" + "<li>" + GDPHtml + "</li> <li>" + employmentHtml + "</li> <li>" +
WageHtml + "</li> </ul>";
}
}
})
// Run statistics for GDP/employment/salary within current time extent
const SITLAQuery = tableView.effect.filter.createQuery();
SITLAQuery.where = "OGRev > 5.0"
SITLAQuery.outStatistics = [
OGRev,
OGofTotal
];
table.queryFeatures(SITLAQuery).then((result) => {
statsDiv2.innerHTML = "";
if (result.error) {
return result.error;
} else {
if (result.features.length >= 1) {
const OGRevHtml = result.features[0].attributes["OGRev_Sum"] == null | 0
?"Utah School and Institutional Trust Lands Administration (SITLA) revenue data not available."
:"Contributed an average of " +
"<span>" +
result.features[0].attributes["OGRev_Sum"].toFixed(1) +
"</span> million dollars to the Utah School and Institutional Trust Lands Administration per year" +
".<br />";
const OGofTotalHtml = result.features[0].attributes["OGofTotal_Average"] == null | 0
?"Utah School and Institutional Trust Lands Administration (SITLA) revenue data not available."
:"Was responsible for " +
"<span>" +
result.features[0].attributes["OGofTotal_Average"].toFixed(1) +
"</span>% of the Utah School and Institutional Trust Lands Administration (SITLA) total gross revenue." +
"<br />";
const referenceHtml =
"<i><font size = '1'>" +
"Estimates from the US Bureau of Economic Analysis, the US Bureau of Labor Statistics, Utah School and Institutional Trust Lands Administration and Utah's Division of Oil, Gas, and Mining." +
"<br />GDP, employment, wage, and SITLA revenue percentage calculations are averages based on current time frame selection." +
"<br />SITLA financial data for oil and gas revenue was not available before 2000." +
"</font></i>";
statsDiv2.innerHTML =
"<ul style='margin-top:0'>" + "</li> <li>" + OGRevHtml + "</li> <li>" + OGofTotalHtml + "</li> </ul></br>" + referenceHtml;
}
}
})
.catch((error) => {
console.log(error);
});
});
const wellCounts = {
onStatisticField: "API",
outStatisticFieldName: "Well_Counts",
statisticType: "count"
};
const GDPAvg = {
onStatisticField: "GDP_billions_",
outStatisticFieldName: "GDP_Average",
statisticType: "avg"
};
const employmentCount = {
onStatisticField: "Employed",
outStatisticFieldName: "Employment_Count",
statisticType: "avg"
};
const wageAvg= {
onStatisticField: "AverageInflation",
outStatisticFieldName: "Wage_Average",
statisticType: "avg"
};
const OGRev = {
onStatisticField: "OGRev",
outStatisticFieldName: "OGRev_Sum",
statisticType: "avg"
};
const OGofTotal = {
onStatisticField: "OGPercent",
outStatisticFieldName: "OGofTotal_Average",
statisticType: "avg"
};
const statDiv = document.getElementById("statDiv")
const statsDiv1 = document.getElementById("statsDiv1");
const statsDiv2 = document.getElementById("statsDiv2");
const infoDiv = document.getElementById("infoDiv");
const infoDivExpand = new Expand({
collapsedIconClass: "esri-icon-collapse",
expandIconClass: "esri-icon-expand",
expandTooltip: "Expand Oil and Gas Industry info",
view: view,
content: infoDiv,
expanded: true,
group: "top-right"
});
view.ui.add({component: infoDivExpand, position: "top-right", index: 0});
});
//Create line graph for crude oil production
var definition = {
type: "line",
title: "Crude Oil Production",
style: {
colors: ["#52c2de"]
},
datasets: [
{
url: "https://services.arcgis.com/ZzrwjTRez6FJiOq4/arcgis/rest/services/OilGasProduction19602019/FeatureServer/0",
query: {
orderByFields: "Year"
}
}
],
series: [
{
category: {
field: "Year",
label: "Year"},
value: {
field: "Production",
label: "Crude Oil Production (thousand barrels)"}
},
]
};
var cedarChart = new cedar.Chart("chart", definition);
cedarChart.show()
const productionPanel = document.getElementById("productionPanel")
view.when(function() {
// Display the chart in an Expand widget
const productionExpand = new Expand({
expandIconClass: "esri-icon-chart",
expandTooltip: "Oil Production Graph",
expanded: false,
view: view,
content: productionPanel,
group: "top-right"
});
view.ui.add(productionExpand, "top-right");
});
//Create line graph for crude oil reserves
var definition = {
type: "line",
title: "Crude Oil Reserves",
style: {
colors: ["#9230c7"]
},
datasets: [
{
url: "https://services.arcgis.com/ZzrwjTRez6FJiOq4/arcgis/rest/services/OilGasProduction19602019/FeatureServer/0",
query: {
orderByFields: "Year"
}
}
],
series: [
{
category: {
field: "Year",
label: "Year"},
value: {
field: "Crude_Oil_Reserves",
label: "Crude Oil Reserves (thousands barrels)"}
},
]
};
var cedarChart1 = new cedar.Chart("chart1", definition);
cedarChart1.show()
const productionPanel1 = document.getElementById("productionPanel1")
view.when(function() {
// Display the chart in an Expand widget
const productionExpand1 = new Expand({
expandIconClass: "esri-icon-chart",
expandTooltip: "Crude Oil Reserves Graph",
expanded: false,
view: view,
content: productionPanel1,
group: "top-right"
});
view.ui.add(productionExpand1, "top-right");
});
//Create line graph for natural gas reserves
var definition = {
type: "line",
title: "Natural Gas Reserves",
style: {
colors: ["#5a3382"]
},
datasets: [
{
url: "https://services.arcgis.com/ZzrwjTRez6FJiOq4/arcgis/rest/services/OilGasProduction19602019/FeatureServer/0",
query: {
orderByFields: "Year"
}
}
],
series: [
{
category: {
field: "Year",
label: "Year"},
value: {
field: "Natural_Gas_Liquids_Reserves",
label: "Natural Gas Reserves (thousand barrels)"}
},
]
};
var cedarChart2 = new cedar.Chart("chart2", definition);
cedarChart2.show()
const productionPanel2 = document.getElementById("productionPanel2")
view.when(function() {
// Display the chart in an Expand widget
const productionExpand1 = new Expand({
expandIconClass: "esri-icon-chart",
expandTooltip: "Natural Gas Reserves Graph",
expanded: false,
view: view,
content: productionPanel2,
group: "top-right"
});
view.ui.add(productionExpand1, "top-right");
});
// Instruction Box
const instructions = document.getElementById("instructionDiv")
const instructionBox = new Expand({
expandIconClass: "esri-icon-collapse",
expandTooltip: "How to use this map",
expanded: true,
view: view,
content: instructions,
group : "top-left"
});
view.ui.add({component: instructionBox, position: "top-left", index: 1});
});