-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
1068 lines (979 loc) · 41.3 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
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
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require([
"esri/layers/FeatureLayer",
"esri/dijit/FeatureTable",
"esri/dijit/Search",
"esri/dijit/HomeButton",
"esri/dijit/BasemapLayer", "esri/dijit/Basemap",
"esri/dijit/BasemapGallery",
"esri/geometry/Extent",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/Color",
"esri/map",
"dojo/dom-construct",
"dojo/dom",
"dojo/number",
"dojo/parser",
"dojo/ready",
"dojo/on",
"dojo/_base/lang",
"dojo/io-query",
"dijit/registry",
"dijit/form/Button",
"dijit/layout/ContentPane",
"dijit/layout/BorderContainer",
"dijit/form/TextBox",
"esri/graphicsUtils",
"esri/tasks/query",
"esri/renderers/UniqueValueRenderer",
"esri/symbols/SimpleFillSymbol"
], function (
FeatureLayer, FeatureTable, Search, HomeButton, BasemapLayer, Basemap, BasemapGallery, Extent, SimpleMarkerSymbol, SimpleLineSymbol, Color, Map,
domConstruct, dom, dojoNum, parser, ready, on, lang, ioQuery,
registry, Button, ContentPane, BorderContainer, TextBox, gracphiUtils, Query, UniqueValueRenderer, SimpleFillSymbol
) {
parser.parse();
ready(function () {
var uri = window.location.href;
var query = uri.substring(uri.indexOf("?") + 1, uri.length);
var queryObject = ioQuery.queryToObject(query);
var viewType = queryObject.view ? queryObject.view : 'compact';
if (viewType === 'compact') {
//var topPanel = dijit.byId('top');
//dijit.byId('container-all').removeChild(topPanel);
window.setTimeout(function () {
var topPanel = dijit.byId('top');
dijit.byId('container-all').removeChild(topPanel);
//dojo.byId('top').style.display = viewType === 'full' ? 'block' : 'none';
}, 150);
} else {
//hide full screen button
dojo.byId('Fullscreen').style.display = 'none';
}
//var coastal_research_fs_url = "https://services.arcgis.com/uUvqNMGPm7axC2dD/arcgis/rest/services/survey123_ffd27bbc80b544198433b60a5a33d710_fieldworker/FeatureServer/0";
//var coastal_research_fs_url = "https://services.arcgis.com/uUvqNMGPm7axC2dD/arcgis/rest/services/survey123_f15a151e1f8a4739b9e092c4188d3211_fieldworker/FeatureServer/0";
//var coastal_research_fs_url = "https://services.arcgis.com/uUvqNMGPm7axC2dD/arcgis/rest/services/survey123_f15a151e1f8a4739b9e092c4188d3211_stakeholder/FeatureServer/0";
var coastal_research_fs_url = "https://services.arcgis.com/uUvqNMGPm7axC2dD/ArcGIS/rest/services/survey123_e3b56beaf4ea4296ab4845b4ffb73445_fieldworker/FeatureServer/0";
var map = new Map("map", {
basemap: "topo",
center: [-122.45, 45], // longitude, latitude
zoom: 4
});
var featureTable;
var featureLayer;
//OLD FIELD INFOS////
//var field_infos = [
// {
// name: "field_8",
// alias: "Research Project Title",
// showTable: true,
// showDetails: true
// }, {
// name: "field_1",
// alias: "Name",
// showTable: true,
// showDetails: true
// }, {
// name: "field_2",
// alias: "Email Address",
// showTable: true,
// showDetails: true
// }, {
// name: "field_3",
// alias: "Phone Number",
// format: {
// template: "${value}"
// },
// showTable: false,
// showDetails: true
// }, {
// name: "field_4",
// alias: "Institution",
// showTable: true,
// showDetails: true
// }, {
// name: "field_4_other",
// alias: "Other - Institution",
// showTable: false,
// showDetails: true
// }, {
// name: "field_5",
// alias: "Department",
// showTable: true,
// showDetails: true
// }, {
// name: "field_9",
// alias: "Personal Research Category(s)",
// showTable: false,
// showDetails: true
// }, {
// name: "field_6",
// alias: "Project research category(s)",
// showTable: false,
// showDetails: true
// }, {
// name: "field_10",
// alias: "Project status",
// showTable: true,
// showDetails: true
// }, {
// name: "field_11",
// alias: "Project start date",
// showTable: false,
// showDetails: true
// }, {
// name: "field_12",
// alias: "Project end date",
// showTable: false,
// showDetails: true
// }, {
// name: "field_13",
// alias: "Funding Source(s)",
// showTable: true,
// showDetails: true
// }, {
// name: "field_13_other",
// alias: "Other - Funding Source(s)",
// showTable: false,
// showDetails: true
// }, {
// name: "field_14",
// alias: "Affiliations and Partnerships",
// showTable: false,
// showDetails: true
// }, {
// name: "field_15",
// alias: "Principle Investigator",
// showTable: true,
// showDetails: true
// }, {
// name: "field_16",
// alias: "Data Manager",
// showTable: false,
// showDetails: true
// }, {
// name: "field_17",
// alias: "Research description",
// showTable: false,
// showDetails: true
// }, {
// name: "field_18",
// alias: "Data availability",
// showTable: true,
// showDetails: true
// }, {
// name: "field_18_other",
// alias: "Other - Data availability",
// showTable: false,
// showDetails: true
// }, {
// name: "field_19",
// alias: "URL for accessible research",
// showTable: true,
// showDetails: true
// }, {
// name: "field_20",
// alias: "Future plans for availability",
// showTable: false,
// showDetails: true
// }, {
// name: "field_20_other",
// alias: "Yes, explain - Future plans for availability",
// showTable: false,
// showDetails: true
// }, {
// name: "field_22",
// alias: "Status of data collection.",
// showTable: false,
// showDetails: true
// }, {
// name: "field_22_other",
// alias: "Other - Status of data collection.",
// showTable: false,
// showDetails: true
// }, {
// name: "field_24",
// alias: "Type of Data",
// showTable: true,
// showDetails: true
// }, {
// name: "field_25",
// alias: "Data Description",
// showTable: true,
// showDetails: true
// }, {
// name: "field_26",
// alias: "Type of technologies used",
// showTable: false,
// showDetails: true
// }, {
// name: "field_26_other",
// alias: "Other - Type of technologies used",
// showTable: false,
// showDetails: true
// }, {
// name: "field_27",
// alias: "Technology description",
// showTable: false,
// showDetails: true
// }, {
// name: "field_28",
// alias: "Associated metadata or a description of associated data",
// showTable: false,
// showDetails: true
// }, {
// name: "field_32",
// alias: "Geographic area description",
// showTable: true,
// showDetails: true
// }, {
// name: "field_33",
// alias: "Geographic type measured ",
// showTable: false,
// showDetails: true
// }, {
// name: "field_33_other",
// alias: "Other - Geographic type measured ",
// showTable: false,
// showDetails: true
// }, {
// name: "field_36",
// alias: "Additional information associated with this project.",
// showTable: false,
// showDetails: true
// }, {
// name: "field_35",
// alias: "Please suggest other researchers to include in this network.",
// showTable: false,
// showDetails: true
// }];
//NEW FIELD INFOS////
var field_infos = [
{
name: "field_8",
alias: "Research Project Title",
showTable: true,
showDetails: true
},
{
name: "field_15",
alias: "Principal Investigator",
showTable: true,
showDetails: true
},
{
name: "field_51",
alias: "Principal Investigator Last Name",
showTable: false,
showDetails: true
},
{
name: "field_52",
alias: "Principal Investigator Email",
showTable: false,
showDetails: true
}, {
name: "field_56",
alias: "Start Year",
showTable: true,
showDetails: true,
format: {
template: "${value}"
}
},
{
name: "field_57",
alias: "End Year",
showTable: true,
showDetails: true,
format: {
template: "${value}"
}
},
{
name: "field_1",
alias: "Survey Respondent",
showTable: false,
showDetails: true
},
{
name: "field_2",
alias: "Email Address",
showTable: true,
showDetails: true
},
{
name: "field_4",
alias: "Institution",
showTable: true,
showDetails: true
},
{
name: "field_4_other",
alias: "Other - Institution",
showTable: false,
showDetails: true
},
{
name: "field_5",
alias: "Department",
showTable: true,
showDetails: true
},
{
name: "field_9",
alias: "Personal Research Category(s)",
showTable: false,
showDetails: true
},
{
name: "field_6",
alias: "Project research category(s)",
showTable: false,
showDetails: true
},
{
name: "field_10",
alias: "Project status",
showTable: true,
showDetails: true
},
{
name: "field_13",
alias: "Funding Source(s)",
showTable: true,
showDetails: true
},
{
name: "field_13_other",
alias: "Other - Funding Source(s)",
showTable: false,
showDetails: true
},
{
name: "field_14",
alias: "Affiliations and Partnerships",
showTable: false,
showDetails: true
},
{
name: "field_17",
alias: "Research description",
showTable: false,
showDetails: true
},
{
name: "field_18",
alias: "Data availability",
showTable: true,
showDetails: true
},
{
name: "field_18_other",
alias: "Other - Data availability",
showTable: false,
showDetails: true
},
{
name: "field_19",
alias: "URL for accessible data",
showTable: true,
showDetails: true
},
{
name: "field_20",
alias: "Future plans for data availability",
showTable: false,
showDetails: true
},
{
name: "field_20_other",
alias: "Yes, explain - Future plans for data availability",
showTable: false,
showDetails: true
},
{
name: "field_24",
alias: "Type of Data",
showTable: true,
showDetails: true
},
{
name: "field_25",
alias: "Data Description",
showTable: true,
showDetails: true
},
{
name: "field_26",
alias: "Data collection method(s)",
showTable: false,
showDetails: true
},
{
name: "field_26_other",
alias: "Other - Data collection method(s)",
showTable: false,
showDetails: true
},
{
name: "field_27",
alias: "Method(s) description",
showTable: false,
showDetails: true
},
{
name: "field_32",
alias: "Geographic area description",
showTable: true,
showDetails: true
},
{
name: "field_33",
alias: "Geographic type measured ",
showTable: false,
showDetails: true
},
{
name: "field_33_other",
alias: "Other - Geographic type measured ",
showTable: false,
showDetails: true
},
{
name: "field_36",
alias: "Additional information associated with this project.",
showTable: false,
showDetails: true
},
{
name: "field_35",
alias: "Please suggest other researchers to include in this network.",
showTable: false,
showDetails: true
},
{
name: "field_37",
alias: "Does this project fit under the category of Coastal Hazards and Resilience?",
showTable: false,
showDetails: true
},
{
name: "field_45",
alias: "Which \"Coastal Hazards and Resilience\" subtopic describes this project?",
showTable: false,
showDetails: true
},
{
name: "field_43",
alias: "Does this project fit under the category of Marine Fisheries Research?",
showTable: false,
showDetails: true
},
{
name: "field_46",
alias: "Which \"Marine Fisheries\" subtopic describes this project?",
showTable: false,
showDetails: true
},
{
name: "field_42",
alias: "Does this project fit under the category of Coastal Pollution and Water Quality Research?",
showTable: false,
showDetails: true
},
{
name: "field_47",
alias: "Which \"Coastal Pollution and Water Quality\" subtopic describes this project?",
showTable: false,
showDetails: true
},
{
name: "field_41",
alias: "Does this project fit under the category of Coastal Human Uses and Benefits Research?",
showTable: false,
showDetails: true
},
{
name: "field_48",
alias: "Which \"Coastal Human Uses and Benefits\" subtopic describes this project?",
showTable: false,
showDetails: true
},
{
name: "field_40",
alias: "Does this project fit under the category of Marine Biophysical Conditions and Processes Research?",
showTable: false,
showDetails: true
},
{
name: "field_49",
alias: "Which \"Marine Biophysical Conditions and Processes \" subtopic describes this project?",
showTable: false,
showDetails: true
},
{
name: "field_39",
alias: "Does this project fit under the category of Marine Species, Ecosystems, and Functions Research?",
showTable: false,
showDetails: true
},
{
name: "field_50",
alias: "Which \"Marine Species, Ecosystems, and Functions \" subtopic describes this project?",
showTable: false,
showDetails: true
}
];
map.on("load", loadMapTableWidgets);
function loadMapTableWidgets() {
////////////////////////////////////
// Home Button
////////////////////////////////////
var home = new HomeButton({
map: map
}, "HomeButton");
home.startup();
////////////////////////////////////
// Full screen
////////////////////////////////////
var fullscreen = document.getElementById('Fullscreen');
on(fullscreen, 'click', function (e) {
window.open('index.html?view=full', '_blank');
});
////////////////////////////////////
// Basemap Gallery
////////////////////////////////////
//add the basemap gallery, in this case we'll display maps from ArcGIS.com including bing maps
var basemaps = [];
var imgeryLayer = new BasemapLayer({
url: "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
});
var ImageryBasemap = new Basemap({
layers: [imgeryLayer],
title: "Imagery",
thumbnailUrl: "https://www.arcgis.com/sharing/rest/content/items/86de95d4e0244cba80f0fa2c9403a7b2/info/thumbnail/tempimagery.jpg"
});
var streetsLayer = new BasemapLayer({
url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
});
var StreetsBasemap = new Basemap({
layers: [streetsLayer],
title: "Streets",
thumbnailUrl: "https://www.arcgis.com/sharing/rest/content/items/d8855ee4d3d74413babfb0f41203b168/info/thumbnail/world_street_map.jpg"
});
var topoLayer = new BasemapLayer({
url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"
});
var TopoBasemap = new Basemap({
layers: [topoLayer],
title: "Topographic",
thumbnailUrl: "https://www.arcgis.com/sharing/rest/content/items/6e03e8c26aad4b9c92a87c1063ddb0e3/info/thumbnail/topo_map_2.jpg"
});
basemaps.push(ImageryBasemap);
basemaps.push(StreetsBasemap);
basemaps.push(TopoBasemap);
var basemapGallery = new BasemapGallery({
showArcGISBasemaps: false,
basemaps: basemaps,
map: map
}, "basemapGallery");
basemapGallery.startup();
basemapGallery.on("error", function (msg) {
console.log("basemap gallery error: ", msg);
});
///////////////////////////////////
// Feature Layer
///////////////////////////////////
//setup renderer
var uvrJson = {
"type": "uniqueValue",
"field1": "field_10",
"defaultSymbol": {
"angle": 0,
"color": [255, 0, 0, 255],
"outline": {
"color": [255, 255, 255, 255],
"width": 1
},
"size": 8,
"style": "esriSMSCircle",
"type": "esriSMS",
"xoffset": 0,
"yoffset": 0
},
"uniqueValueInfos": [{
"value": "choice0",
"symbol": {
"angle": 0,
"color": [255, 0, 0, 255],
"outline": {
"color": [255, 255, 255, 255],
"width": 1
},
"size": 8,
"style": "esriSMSCircle",
"type": "esriSMS",
"xoffset": 0,
"yoffset": 0
}
}, {
"value": "choice1",
"symbol": {
"angle": 0,
"color": [0, 255, 0, 255],
"outline": {
"color": [255, 255, 255, 255],
"width": 1
},
"size": 8,
"style": "esriSMSCircle",
"type": "esriSMS",
"xoffset": 0,
"yoffset": 0
},
}, {
"value": "choice2",
"symbol": {
"angle": 0,
"color": [0, 0, 255, 255],
"outline": {
"color": [255, 255, 255, 255],
"width": 1
},
"size": 8,
"style": "esriSMSCircle",
"type": "esriSMS",
"xoffset": 0,
"yoffset": 0
}
}]
}
var renderer = new UniqueValueRenderer(uvrJson);
featureLayer = new FeatureLayer(coastal_research_fs_url, {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
visible: true,
id: "fLayer"
});
featureLayer.setDefinitionExpression("field_1 <> 'Test 1'");
featureLayer.setRenderer(renderer);
featureLayer.syncSelection = true;
// set a selection symbol for the featurelayer
var line = new SimpleLineSymbol();
line.setColor(new Color([0, 255, 197, 1]));
line.setWidth(5);
var marker = new SimpleMarkerSymbol();
//marker.setColor(new Color([0, 0, 0, 0]));
marker.setOutline(line);
marker.setAngle(360);
//var selectionSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,
// new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 255, 197, 1])));
featureLayer.setSelectionSymbol(marker);
map.addLayer(featureLayer);
///////////////////////////////////
// Feature Layer Events
///////////////////////////////////
featureLayer.on("click", function (evt) {
var idProperty = featureLayer.objectIdField,
feature,
featureId,
query;
if (evt.graphic && evt.graphic.attributes && evt.graphic.attributes[idProperty]) {
feature = evt.graphic,
featureId = feature.attributes[idProperty];
showProjectDetails(feature.attributes);
query = new Query();
query.returnGeometry = false;
query.objectIds = [featureId];
query.where = "1=1";
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);
}
});
///////////////////////////////////
// Feature Table
///////////////////////////////////
// create new FeatureTable and set its properties
var outFields = field_infos.map(function (field) {
return field.name;
});
var hiddenFields = field_infos
.filter(function (field) {
return field.showTable === false;
})
.map(function (fieldmap) {
return fieldmap.name;
});
featureTable = new FeatureTable({
featureLayer: featureLayer,
map: map,
showAttachments: false,
// only allows selection from the table to the map
syncSelection: true,
zoomToSelection: true,
gridOptions: {
allowSelectAll: true,
allowTextSelection: true,
},
dateOptions: {
// set date options at the feature table level
// all date fields will adhere this
datePattern: "MMMM d, y"
},
// define order of available fields. If the fields are not listed in 'outFields'
// then they will not be available when the table starts.
//outFields: ["field_8", "field_2", "field_3", "field_4", 'field_5',
// "field_6", "field_7", "field_1", "field_9", "field_10"
//],
outFields: outFields,
hiddenFields: hiddenFields,
// use fieldInfos property to change field's label (column header),
// the editability of the field, and to format how field values are displayed
fieldInfos: field_infos,
menuFunctions: [
//Add new Export to CSV menu function
{ label: "Export to CSV", callback: customExportCSV }
]
}, 'featureTableNode');
featureTable.startup();
///////////////////////////////////
// Feature Table Events
///////////////////////////////////
featureTable.on('load', function (evt) {
window.setTimeout(function () {
dojo.byId('filteredProjects').innerHTML = featureTable.dataStore.totalCount;
featureTable.featureLayer.name = 'Research Projects';
//featureTable.refresh();
}, 500);
});
featureTable.on("row-select", function (evt) {
if (evt.rows.length > 0) {
showProjectDetails(evt.rows[0].data);
}
});
featureTable.on("row-deselect", function (evt) {
document.getElementById('detail-wrapper').style.display = 'none';
document.getElementById('no-selection-wrapper').style.display = 'block';
});
////////////////////////////////////
// Search
////////////////////////////////////
var search = new Search({
enableButtonMode: false, //this enables the search widget to display as a single button
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: true,
sources: [],
map: map
}, "search");
var sources = search.get("sources");
//Push the sources used to search, by default the ArcGIS Online World geocoder is included. In addition there is a feature layer of US congressional districts. The districts search is set up to find the "DISTRICTID". Also, a feature layer of senator information is set up to find based on the senator name.
sources.push({
featureLayer: featureLayer,
searchFields: ["field_8", "field_10", "field_17","field_32"], // Project Title, Status, Description, Geographic Area
displayField: "field_8",
exactMatch: false,
outFields: ["field_8"],
name: "Research Project",
placeholder: "Search research projects",
maxResults: 6,
maxSuggestions: 6,
//Create an InfoTemplate and include three fields
enableSuggestions: true,
minCharacters: 0
});
//Set the sources above to the search widget
search.set("sources", sources);
search.startup();
on(search, 'select-result', function (e) {
//featureTable.dataStore;
let row_idx;
featureTable.dataStore.data.forEach(function (row, idx) {
row_idx = row.attributes['field_8'] === e.result.feature.attributes['field_8'] ? idx : row_idx;
})
featureTable.selectRows(row_idx, true);
map.setLevel(8);
console.log('selected result', e);
});
////////////////////////////////////
// Filter
////////////////////////////////////
var filter = document.getElementById('filter-select');
var filterStatus = document.getElementById('filter-select-status');
on(filter, 'change', function (e) {
filterTable();
});
on(filterStatus, 'change', function (e) {
filterTable();
});
var clearFilter = dojo.byId("clear-filter-btn");
on(clearFilter, 'click', function (e) {
filterTable(true);
});
////////////////////////////////////
// Add research btn click
////////////////////////////////////
var addResearch = dojo.byId("add-research");
on(addResearch, 'click', function (e) {
window.open('https://survey123.arcgis.com/share/e3b56beaf4ea4296ab4845b4ffb73445', '_blank');
});
}
function filterTable(clear) {
//get selected value from categories and status
//featureTable.clearFilter();
if (clear) {
featureTable.clearFilter();
dojo.byId('filter-select').value = 'All';
dojo.byId('filter-select-status').value = 'All';
}
var selectedCategory = document.getElementById('filter-select').value;
dojo.byId('selectedFilter').innerHTML = ['', 'All'].indexOf(selectedCategory) !== -1
? 'All Project Research Categories'
: selectedCategory;
selectedCategory = selectedCategory === 'All'
? ''
: selectedCategory; //.replace(/\ /g, '_');
var selectedStatus = document.getElementById('filter-select-status').value;
selectedStatus = selectedStatus === 'All' ? '' : selectedStatus;
dojo.byId('selectedStatusFilter').innerHTML = statusLookup(selectedStatus) !== ''
? 'Status: ' + statusLookup(selectedStatus)
: '';
var oidFld = featureLayer.objectIdField;
var query = new Query();
var where = "field_1 <> 'Test 1'"
+ (selectedCategory === ''
? ''
: " AND " + projectCategoryLookup(selectedCategory) + " = 'choice0'")
+ (selectedStatus === ''
? ''
: " AND field_10 like '%" + selectedStatus + "%'");
query.where = where;
featureLayer.setDefinitionExpression(where);
featureLayer.queryIds(query, lang.hitch(this, function (objectIds) {
dojo.byId('filteredProjects').innerHTML = objectIds.length;
featureTable.filterRecordsByIds(objectIds);
}));
}
function projectCategoryLookup(category) {
switch (category) {
case "Coastal Hazards and Resilience":
return "field_37";
case "Marine Fisheries Research":
return "field_43";
case "Coastal Pollution and Water Quality Research":
return "field_42";
case "Coastal Human Uses and Benefits Research":
return "field_41";
case "Marine Biophysical Conditions and Processes Research":
return "field_40";
case "Marine Species, Ecosystems, and Functions Research":
return "field_39";
default:
return "";
}
}
function statusLookup(status) {
switch (status) {
case 'choice0':
return 'Completed';
break;
case 'choice1':
return 'Ongoing';
break;
case 'choice2':
return 'New / Unstarted';
break;
case 'All':
default:
return '';
break;
}
}
function showProjectDetails(featureAttributes) {
document.getElementById('detail-wrapper').style.display = 'block';
document.getElementById('no-selection-wrapper').style.display = 'none';
map.setLevel(map.getLevel() >= 8 ? map.getLevel() : 8);
if (featureAttributes) {
let detail_obj = {};
field_infos.forEach(function (field) {
if (field.showDetails) {
detail_obj[field.alias] = featureAttributes[field.name]
? featureAttributes[field.name].toString().replace(/\_/g, ' ')
: null;
}
});
document.getElementById('detail-proj-title').innerHTML = detail_obj['Research Project Title'];
document.getElementById('detail-desc').innerHTML = detail_obj['Research description'];
//var startTime = new Date(parseInt(detail_obj['Year project started/will start']));
//var formattedTime = startTime.toLocaleDateString();
document.getElementById('detail-start-date').innerHTML = detail_obj['Start Year'];
document.getElementById('detail-status').innerHTML = statusLookup(detail_obj['Project status']);
document.getElementById('detail-pi').innerHTML = detail_obj['Principal Investigator'];
document.getElementById('detail-institution').innerHTML = detail_obj['Institution'];
if (detail_obj['URL for accessible data']) {
document.getElementById('data_url').style.display = 'block';
document.getElementById('detail-data-url').innerHTML = '<a href="' + detail_obj['URL for accessible data'] + '" target="_blank">URL for accessible data</a>';
} else {
document.getElementById('data_url').style.display = 'none';
}
}
}
function customExportCSV(evt) {
//var gridData = myFeatureTable.selectedRows;