-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathejscreenAPI.html
946 lines (867 loc) · 39.8 KB
/
ejscreenAPI.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
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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>EJScreen Report API</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://js.arcgis.com/4.11/esri/css/main.css">
<link rel="SHORTCUT ICON" href="images/ej.ico" />
<style>
body {
margin: 8px;
font-family: Verdana;
}
#search {
display: block;
position: absolute;
z-index: 2;
top: 20px;
left: 74px;
}
#loadingDiv {
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
display: none;
z-index: 500;
position: absolute;
left: 40%;
top: 50%;
}
.formTable {
background-color: #d9edf7;
width: 100%;
font-family: Verdana;
font-size: 11pt;
padding-top: 4px;
}
.blackfont {
color: Black !important;
}
.custompanel {
margin: 4px 15px 4px 15px;
word-wrap: break-word;
}
</style>
<link rel="stylesheet" href="css/bootstrap.css" />
<script src="https://js.arcgis.com/4.11/"></script>
<script type="text/javascript" src="javascript/config.js"></script>
<script type="text/javascript" src="javascript/tagmanager.js"></script>
<!-- <script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-32633028-1', 'auto');
ga('send', 'pageview');
</script> -->
<script type="text/javascript">
require(["dojo",
"esri/views/MapView",
"esri/Map",
'esri/widgets/Sketch/SketchViewModel',
"esri/tasks/QueryTask",
"esri/tasks/support/Query",
"esri/geometry/SpatialReference",
"esri/Graphic",
"esri/layers/GraphicsLayer",
"esri/geometry/Point",
"esri/geometry/Polyline",
"esri/geometry/Polygon",
"esri/PopupTemplate",
"esri/widgets/Search",
"esri/geometry/support/webMercatorUtils",
"esri/geometry/geometryEngine",
"esri/config",
"esri/request",
"dojo/on",
"dojo/parser",
"dijit/registry",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
"dijit/form/Button", "dijit/WidgetSet", "dojo/domReady!"
], function (
dojo,
MapView, Map, SketchViewModel,
QueryTask,
Query,
SpatialReference,
Graphic,
GraphicsLayer,
Point,
Polyline,
Polygon,
PopupTemplate,
Search,
webMercatorUtils,
geometryEngine,
esriConfig,
esriRequest,
on, parser, registry
) {
var pointsym = { // symbol used for points
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: "cross",
color: "rgba(255, 0, 255, 1.0)",
size: "12px",
outline: { // autocasts as new SimpleLineSymbol()
color: "rgba(255, 0, 255, 1.0)",
width: 1 // points
}
};
var linesym = { // symbol used for polylines
type: "simple-line", // autocasts as new SimpleMarkerSymbol()
color: "#ff0000",
width: "2",
style: "solid"
};
var polysym = { // symbol used for polygons
type: "simple-fill", // autocasts as new SimpleMarkerSymbol()
color: "rgba(0, 255, 0, 0.25)",
style: "solid",
outline: {
color: "red",
width: 2
}
};
var pname = location.pathname;
var pos = pname.lastIndexOf("/");
pname = pname.substr(0, pos);
var rooturl = location.protocol + "//" + location.host + pname + "/";
var ejscreenSOEbrokerurl = rooturl + "ejscreenRESTbroker.aspx";
var ejscreenReportfile = "EJSCREEN_report.aspx";
var charLimit = 2048;
var typedesc = {
"point": "Use the location box below to find an address or place and then click on the map or enter/paste a JSON geometry string in the Geometry box.",
"polyline": "Use the location box below to find an address or place and then click on the map to draw a line or polyline (line segments cannot cross each other). Enter 'C' to end the drawing. Or enter/paste a JSON geometry string in the Geometry box.",
"polygon": "Use the location box below to find an address or place and then click on the map to draw a polygon (lines cannot cross each other). Click on the starting point to end the drawing. Or enter/paste a JSON geometry string in the Geometry box.",
"rectangle": "Use the location box below to find an address or place. Hold down the mouse and drag left to define a rectangle area. Release the mouse to finish dragging. Or enter/paste a JSON geometry string in the Geometry box.",
"blockgroup": "Use the location box below to find an address or place. Click on the map to select a Census block group. Or you can enter a FIPS code for the Census block group.",
"tract": "Use the location box below to find an address or place. Click on the map to select a Census tract. Or you can enter a FIPS code for the Census tract.",
"city": "Use the location box below to find an address or place. Click on the map to select a city. Or you can enter a FIPS code for the city.",
"county": "Use the location box below to find an address or place. Click on the map to select a county. Or you can enter a FIPS code for the county."
};
//valid areatypes for census based inputs
var censusidtypes = ["blockgroup", "tract", "city", "county"];
//track whether result are from identify, used to distinguish from text input
var valsById = false;
var ejscreenform = dojo.byId("ejform");
//global id and namestr, set by identify or text input;
var areaid;
var namestr;
const fieldsMapping = {RAW_D_PEOPCOLOR:"RAW_D_MINOR",
RAW_D_DEMOGIDX2:"RAW_D_INDEX",
S_D_PEOPCOLOR:"S_D_MINOR",
S_D_DEMOGIDX2:"S_D_INDEX",
S_D_PEOPCOLOR_PER:"S_D_MINOR_PER",
S_D_DEMOGIDX2_PER:"S_D_INDEX_PER",
S_P2_LEAD:"S_P_LEAD",
S_P2_DIESEL:"S_P_DIESEL",
S_P2_CANCER:"S_P_CANCER",
S_P2_RESP:"S_P_RESP",
S_P2_TRAFFIC:"S_P_TRAFFIC",
S_P2_NPDES:"S_P_NPDES",
S_P2_NPL: "S_P_NPL",
S_P2_RMP: "S_P_RMP",
S_P2_TSDF: "S_P_TSDF",
S_P2_O3: "S_P_O3",
S_P2_PM25: "S_P_PM25",
S_P2_UST: "S_P_UST",
S_P2_RSEI_AIR:"S_P_RSEI_AIR",
N_D_PEOPCOLOR: "N_D_MINOR",
N_D_DEMOGIDX2: "N_D_INDEX",
N_D_PEOPCOLOR_PER: "N_D_MINOR_PER",
N_D_DEMOGIDX2_PER: "N_D_INDEX_PER",
N_P2_LEAD: "N_P_LEAD",
N_P2_DIESEL: "N_P_DIESEL",
N_P2_CANCER: "N_P_CANCER",
N_P2_RESP: "N_P_RESP",
N_P2_TRAFFIC: "N_P_TRAFFIC",
N_P2_NPDES: "N_P_NPDES",
N_P2_NPL: "N_P_NPL",
N_P2_RMP: "N_P_RMP",
N_P2_TSDF: "N_P_TSDF",
N_P2_O3: "N_P_O3",
N_P2_PM25: "N_P_PM25",
N_P2_UST: "N_P_UST",
N_P2_RSEI_AIR:"N_P_RSEI_AIR"
}
var fieldDelete =[
"RAW_D_DEMOGIDX5",
"RAW_D_LIFEEXP",
"RAW_D_LIFEEXP",
"S_D_LIFEEXP",
"S_D_DEMOGIDX5ST",
"S_D_LIFEEXP_PER",
"S_D_DEMOGIDX5ST_PER",
"N_D_LIFEEXP",
"N_D_DEMOGIDX5",
"N_D_LIFEEXP_PER",
"N_D_DEMOGIDX5_PER",
"N_P5_DIESEL",
"N_P5_CANCER",
"N_P5_RESP",
"N_P5_TRAFFIC",
"N_P5_NPDES",
"N_P5_NPL",
"N_P5_RMP",
"N_P5_TSDF",
"N_P5_O3",
"N_P5_PM25",
"N_P5_UST",
"N_P5_LEAD",
"N_P5_RSEI_AIR" ,
"S_P5_O3",
"S_P5_PM25",
"S_P5_TSDF",
"S_P5_LEAD",
"S_P5_DIESEL",
"S_P5_CANCER",
"S_P5_RESP",
"S_P5_TRAFFIC",
"S_P5_NPDES",
"S_P5_NPL",
"S_P5_RMP",
"S_P5_UST",
"S_P5_RSEI_AIR",
"NUM_WATERDIS",
"NUM_AIRPOLL",
"NUM_BROWNFIELD",
"NUM_TRI",
"NUM_SCHOOL",
"NUM_HOSPITAL",
"NUM_CHURCH",
"YESNO_TRIBAL",
"YESNO_CEJSTDIS",
"YESNO_IRADIS",
"YESNO_AIRNONATT",
"YESNO_IMPWATERS",
"YESNO_HOUSEBURDEN",
"YESNO_TRANSDIS",
"YESNO_FOODDESERT",
"centroidX",
"centroidY",
"stateName",
"stateAbbr"
]
on(dojo.byId("submitget"), "click", function (event) {
submitAction("get");
});
on(dojo.byId("submitpost"), "click", function (event) {
submitAction("post");
});
on(dojo.byId("copyurl"), "click", function (event) {
selectText("urlcontent");
document.execCommand('copy');
});
on(dojo.byId("copyjson"), "click", function (event) {
selectText("resultjson");
document.execCommand('copy');
});
var marginwidth = 28;
var bwsWidth = getWinWidth() - marginwidth;
dojo.byId("geometry").style.width = (bwsWidth - 120) + "px";
window.onresize = function (event) {
var bwsWidth = getWinWidth() - marginwidth;
dojo.byId("geometry").style.width = (bwsWidth - 120) + "px";
};
var geomtype;
var idconnect = null;
var map = new Map({
basemap: "gray"
});
var view = new MapView({
container: "map",
map: map,
// center: [-100.11, 36.65],
center: [-77.0369, 38.9072],
zoom: 10
});
var drawGraphicsLayer = new GraphicsLayer();
map.add(drawGraphicsLayer);
var search = new Search({
container: "search",
view: view,
popupEnabled: false,
resultGraphicEnabled: false
});
//search.startup();
var sketchViewModel;
view.when(function () {
ejscreenform.reset();
sketchViewModel = new SketchViewModel({
view: view,
layer: drawGraphicsLayer,
pointSymbol: pointsym,
polylineSymbol: linesym,
polygonSymbol: polysym,
updateOnGraphicClick: false
});
sketchViewModel.on("create", function (event) {
if (event.state === "complete") {
drawGraphicsLayer.removeAll();
var g = event.graphic;
drawGraphicsLayer.add(g);
//console.log("is simple: " + geometryEngine.isSimple(g.geometry))
if (geometryEngine.isSimple(g.geometry)) {
var mgeometry = g.geometry;
var geometry = webMercatorUtils.webMercatorToGeographic(mgeometry);
var jstr = JSON.stringify(geometry.toJSON());
ejscreenform.geometry.value = jstr;
//clearRadio();
if (event.tool == "polygon") {
setTimeout(function () {
sketchViewModel.create(event.tool);
}, 1000);
} else {
sketchViewModel.create(event.tool);
}
} else {
alert("The geometry is invalid. Please draw a new one.");
}
}
});
var radioObj = dojo.byId("rform").inmethod;
var rl = radioObj.length;
for (var k = 0; k < rl; k++) {
if (radioObj[k].checked) {
var s = radioObj[k].value;
geomtype = s;
activateTool(s);
}
on(radioObj[k], "click", function (e) {
var s = e.target.value;
geomtype = s;
//clear areatype when the radio button is clicked
ejscreenform.areatype.value = "";
//only send census based areatypes in for report, not needed for geometry types (point,line,poly,rect)
if (censusidtypes.includes(geomtype.toLowerCase())) {
ejscreenform.areatype.value = s;
}
activateTool(s);
});
}
});
function clearRadio() {
var radioObj = dojo.byId("rform").inmethod;
var rl = radioObj.length;
for (var k = 0; k < rl; k++) {
radioObj[k].checked = false;
}
}
function submitAction(method) {
//test if values are from identify task
if (valsById == false) {
//if not, it's from the input text box, use that as the name string
ejscreenform.namestr.value = ejscreenform.areaid.value;
} else {
//valsById == true
//values are from a previous identify
//if the value in text box does match the previous areaid, replace with current text box value
if (ejscreenform.areaid.value != areaid) {
areaid = ejscreenform.areaid.value;
//update name string and remove the flag for values by identify
ejscreenform.namestr.value = ejscreenform.areaid.value;
valsById = false;
}
}
var r = validateform(ejscreenform);
dojo.byId("forjson").style.display = "block";
if (r) {
var kvpairs = [];
for (var i = 0; i < ejscreenform.elements.length; i++) {
var e = ejscreenform.elements[i];
if (e.type != "submit") {
kvpairs.push(e.name + "=" + e.value);
}
}
var queryString = kvpairs.join("&");
var poststr = kvpairs.join("<br />");
if (ejscreenform.f.value == "report") {
dojo.byId("jsondiv").style.display = "none";
dojo.byId("reportdiv").style.display = "block";
if (!(dojo.byId("reportframe"))) {
var iframe = document.createElement('iframe');
iframe.id = "reportframe";
iframe.name = "reportframe";
iframe.src = ejscreenReportfile;
iframe.style.width = "100%";
iframe.style.height = "2140px";
iframe.style.overflow = "auto";
dojo.byId("reportdiv").appendChild(iframe);
}
if (method == "get") {
//dojo.byId("urlcontent").innerHTML = rooturl + ejscreenReportfile + "?" + queryString;
var urlcon = rooturl+ejscreenReportfile + "?" + queryString;
if(urlcon.trim().length > charLimit){
alert("2048 character limit exceeded for GET. Consider using POST.");
return false;
}else{
dojo.byId("urlcontent").innerHTML = urlcon;
}
} else {
var postcontent = "HTTP POST URL: " + rooturl + ejscreenReportfile + "<br />HTTP POST Body:<div style='padding-left: 10px;'>" + poststr + "</div>";
dojo.byId("urlcontent").innerHTML = postcontent;
}
ejscreenform.action = ejscreenReportfile;
ejscreenform.target = "reportframe";
ejscreenform.method = method;
ejscreenform.submit();
document.getElementById('urlcontent').scrollIntoView();
} else {
if (dojo.byId("reportframe")) {
dojo.byId("reportdiv").removeChild(dojo.byId("reportframe"));
}
dojo.byId("jsondiv").style.display = "block";
dojo.byId("reportdiv").style.display = "none";
if (method == "get") {
var urlcon = ejscreenSOEbrokerurl + "?" + queryString;
if(urlcon.trim().length > charLimit){
alert("2048 character limit exceeded for GET. Consider using POST.");
return false;
}else{
dojo.byId("urlcontent").innerHTML = urlcon;
}
} else {
var postcontent = "HTTP POST URL: " + ejscreenSOEbrokerurl + "<br />HTTP POST Body:<div style='padding-left: 10px;'>" + poststr + "</div>";
dojo.byId("urlcontent").innerHTML = postcontent;
}
dojo.byId("resultjson").innerHTML = "Loading...Please wait";
document.getElementById('resultjson').scrollIntoView();
if (!method) {
method = "POST";
}
$.ajax({
type: method,
url: ejscreenApiPageUrl,
data: $('#ejform').serialize(),
dataType: 'json',
success: function (response) {
//alert(JSON.stringify(response));
//dojo.byId("resultjson").innerHTML = JSON.stringify(response, undefined, 2);
//we are deleting the extra fields to replicate production
for(var i=0 ;i <fieldDelete.length;i++){
delete response[fieldDelete[i]];
}
// console.log(JSON.stringify(response))
var strResponse = JSON.stringify(response, undefined, 2);
if (ejscreenform.f.value == "pjson"){
strResponse = JSON.stringify(response, undefined, 2);
}else if (ejscreenform.f.value == "json"){
strResponse = JSON.stringify(response);
}
//replacing the fields to show the old fields
for (const property in fieldsMapping) {
strResponse =strResponse.replace(property,fieldsMapping[property]);
}
dojo.byId("resultjson").innerHTML = strResponse;
},
error: function (err) {
if (ejscreenform.f.value == "pjson"){
dojo.byId("resultjson").innerHTML = JSON.stringify(err, undefined, 2);
}
else if (ejscreenform.f.value == "json"){
strResponse = JSON.stringify(response);
}
}
});
/* esriRequest(ejscreenSOEbrokerurl, {
query: queryString,
responseType: "json",
callbackParamName: "callback"
}, {
"usePost": true
}).then(function (result) {
dojo.byId("resultjson").innerHTML = JSON.stringify(result.data, undefined, 2);
}).catch(function (err) {
dojo.byId("resultjson").innerHTML = "error occurred: " + err;
});*/
}
}
}
function activateTool(mtype) {
ejscreenform.reset();
drawGraphicsLayer.removeAll();
if (dojo.byId("reportframe")) {
var iframe = dojo.byId("reportframe");
dojo.byId("reportdiv").removeChild(iframe);
}
dojo.byId("censusdiv").style.display = "none";
dojo.byId("geomdiv").style.display = "none";
dojo.byId("forjson").style.display = "none";
if (idconnect != null) {
idconnect.remove();
idconnect = null;
}
dojo.byId("methodnote").innerHTML = "Note: " + typedesc[mtype];
switch (mtype.toLowerCase()) {
case "blockgroup":
case "tract":
case "city":
case "county":
sketchViewModel.cancel();;
if (idconnect == null) {
idconnect = on(view, "click", doIdentify);
}
dojo.byId("censusdiv").style.display = "block";
break;
case "point":
sketchViewModel.create("point");
ejscreenform.distance.value = "1";
dojo.byId("geomdiv").style.display = "block";
break;
case "line":
case "polyline":
sketchViewModel.create("polyline");;
ejscreenform.distance.value = "1";
dojo.byId("geomdiv").style.display = "block";
break;
case "polygon":
sketchViewModel.create("polygon");
dojo.byId("geomdiv").style.display = "block";
break;
case "rectangle":
sketchViewModel.create("rectangle");
dojo.byId("geomdiv").style.display = "block";
break;
}
}
function doIdentify(evt) {
console.log("identify")
showLoading();
drawGraphicsLayer.removeAll();
var lindex = typelookup[geomtype].layer;
var idfield = typelookup[geomtype].idfield;
var namefld = typelookup[geomtype].namefield;
var layerurl = typelookup[geomtype].url;
var bgurl = layerurl + "/" + lindex;
var queryfields = [idfield];
if (idfield != namefld) queryfields.push(namefld);
var query = new Query();
query.returnGeometry = true;
query.outFields = queryfields;
query.geometry = evt.mapPoint;
query.geometryPrecision = 1;
query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
var queryTask = new QueryTask(bgurl);
queryTask.execute(query).then(function (results) {
if (results.features.length > 0) {
var feature = results.features[0];
var featureAttributes = feature.attributes;
areaid = featureAttributes[idfield];
namestr = featureAttributes[namefld];
ejscreenform.areaid.value = areaid;
ejscreenform.namestr.value = namestr;
ejscreenform.geometry.value = "";
ejscreenform.distance.value = "";
var graphic = new Graphic(feature.geometry, polysym);
drawGraphicsLayer.add(graphic);
//track if vals by identify vs text input
valsById = true;
} else {
alert("Did not find a feature!");
}
hideLoading();
}).catch(function (err) {
alert("error occurred when querying block group: " + err);
hideLoading();
});
}
function showLoading() {
dojo.byId("loadingDiv").style.display = "block";
}
function hideLoading() {
dojo.byId("loadingDiv").style.display = "none";
}
function getWinWidth() {
var myWidth = 0;
if (typeof (window.innerWidth) == 'number') {
//Non-IE
myWidth = window.innerWidth;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 compatible
myWidth = document.body.clientWidth;
}
return myWidth;
}
function validateform(frm) {
if (dojo.byId("censusdiv").style.display == "block") {
var idvalue = dojo.trim(frm.areaid.value);
var idtype = frm.areatype.value;
//var idtype= geomtype;
if (idvalue == "") {
alert("Please input FIPS code!");
return false;
} else {
if (idtype == "blockgroup") {
var bgreg = /^\d{12}$/;
if (bgreg.test(idvalue)) {
return true;
} else {
alert("Invalid blockgroup ID. It needs to be 12 digits.");
return false;
}
} else if (idtype == "tract") {
var trreg = /^\d{11}$/;
if (trreg.test(idvalue)) {
return true;
} else {
alert("Invalid tract ID. It needs to be 11 digits.");
return false;
}
} else if (idtype == "city") {
var cityreg = /^\d{7}$/;
if (cityreg.test(idvalue)) {
return true;
} else {
alert("Invalid city FIPS code. It needs to be 7 digits.");
return false;
}
} else if (idtype == "county") {
var cnreg = /^\d{5}$/;
if (cnreg.test(idvalue)) {
return true;
} else {
alert("Invalid county FIPS code. It needs to be 5 digits.");
return false;
}
} else {
alert("Invalid type!");
return false;
}
}
} else {
var gvalue = dojo.trim(frm.geometry.value);
if (gvalue == "") {
alert("Please input geometry string!");
return false;
} else {
try {
var gobj = JSON.parse(gvalue);
var bdist = dojo.trim(frm.distance.value);
if (((gobj.x) || (gobj.paths)) && ((bdist == "") || (bdist == "0"))) {
alert("For point or line geometry, you have to input buffer size!");
return false;
} else {
var distreg = /[a-z]/i;
if (distreg.test(bdist)) {
alert("Buffer Size needs to be numeric value!");
return false;
}
var geometry, gtype;
if (gobj.x) {
gtype = "point";
geometry = new Point(gobj);
} else if (gobj.paths) {
gtype = "polyline";
geometry = new Polyline(gobj);
} else if (gobj.rings) {
gtype = "polygon";
geometry = new Polygon(gobj);
} else {
alert("Invalid geometry.");
return false;
}
var bunit = dojo.trim(frm.unit.value);
var showArea = checkArea(geometry, gtype, bdist, bunit);
if (showArea) {
return true;
} else {
alert("The area is too large to run the analysis report. Please refine the study area.");
return false;
}
}
} catch (e) {
alert("Invalid geometry json string.");
return false;
}
}
}
}
function checkArea(cgeom, gtype, radius, unit) {
var arealimit = 500;
var showanalysis = true;
var geom, mgeom;
if (cgeom.spatialReference.wkid == 4326) {
geom = cgeom;
mgeom = webMercatorUtils.geographicToWebMercator(cgeom);
} else {
geom = webMercatorUtils.webMercatorToGeographic(cgeom);
mgeom = cgeom;
}
if (Number(radius) > 0) {
var bufGeoms;
if (gtype == "point") {
bufGeoms = geometryEngine.geodesicBuffer([geom], [radius], unit, true);
} else {
bufGeoms = geometryEngine.buffer([mgeom], [radius], unit, true);
}
if (bufGeoms.length == 1) {
var polyarea = geometryEngine.geodesicArea(bufGeoms[0], "square-miles");
console.log("area: " + polyarea);
if (parseFloat(polyarea) > arealimit) {
showanalysis = false;
} else {
showanalysis = true;
}
} else {
showanalysis = false;
}
} else {
var polyarea = geometryEngine.geodesicArea(geom, "square-miles");
if (parseFloat(polyarea) > arealimit) {
return false;
} else {
return true;
}
}
return showanalysis;
}
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
});
</script>
</head>
<body>
<div class="container-fluid">
<div class="row padding">
<div class="custompanel">
<h4>EJScreen Report API
<a href="EJAPIinstructions.pdf" class="btn btn-link btn-sm" role="button" target="_blank"
title="Instruction">Help</a>
</h4>
<form id="rform" onsubmit="return false;">
<label class="radio-inline">
<input type="radio" name="inmethod" value="point" checked />Point
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="polyline" />Line
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="polygon" />Polygon
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="rectangle" />Rectangle
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="blockgroup" />Blockgroup
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="tract" />Tract
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="city" />City
</label>
<label class="radio-inline">
<input type="radio" name="inmethod" value="county" />County
</label>
</form>
<div id="methodnote" style="background-color: #EEEEEE; font-size: 10pt; margin: 8px 0px 8px 0px;"></div>
</div>
</div>
<div class="row padding">
<div class="custompanel">
<div id="map" style="position: relative;width: 100%; height: 450px; margin-bottom: 4px;">
<div id="search"></div>
<div id="loadingDiv">Please wait...</div>
</div>
</div>
</div>
<div class="row padding">
<div class="custompanel">
<form id="ejform" onsubmit="return false;">
<input type="hidden" name="namestr" value="" />
<table id="geomdiv" class="formTable">
<tr valign="top">
<td width="90px">Geometry:</td>
<td align="left">
<textarea id="geometry" name="geometry" rows="3"></textarea>
</td>
</tr>
<tr valign="top">
<td nowrap>Buffer Size:</td>
<td align="left">
<input type="text" name="distance" value="" />
</td>
</tr>
<tr valign="top">
<td nowrap>Buffer Unit:</td>
<td align="left">
<select name="unit" size="1">
<option value="9035" selected>mile</option>
<option value="9036">kilometer</option>
</select>
</td>
</tr>
</table>
<table id="censusdiv" class="formTable">
<tr>
<td width="90px" nowrap>FIPS Code:</td>
<td align="left">
<input type="hidden" name="areatype" value="" />
<input type="text" name="areaid" value="" />
</td>
</tr>
</table>
<table class="formTable">
<tr>
<td width="90px">Format:</td>
<td align="left">
<select name="f">
<option value="json" selected>json</option>
<option value="pjson">pjson</option>
<option value="report">report</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<button id="submitget" title="Get result (GET)">Submit (GET)</button>
<button id="submitpost" title="Get result (POST)">Submit (POST)</button>
</td>
</tr>
</table>
</form>
</div>
</div>
<div class="row padding" id="forjson" style="display: none;">
<div class="custompanel">
<div class="panel panel-info">
<div class="panel-heading blackfont">API Url<button style="float: right; cursor: pointer;"
id="copyurl">Copy</button></div>
<div class="panel-body" id="urlcontent">Panel Content</div>
</div>
<div class="panel panel-info" id="jsondiv" style="display: none;">
<div class="panel-heading blackfont">Results (<a href="ejsoefielddesc.html" target="_blank">Field
Description</a>)<button style="float: right; cursor: pointer;" id="copyjson">Copy</button>
</div>
<pre class="panel-body" id="resultjson">Panel Content</pre>
</div>
<div class="panel panel-info" id="reportdiv" style="display: none;">
<div class="panel-heading blackfont">Results</div>
</div>
</div>
</div>
</div>
</body>
</html>