-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
Copy pathviewer.js
718 lines (698 loc) · 25.9 KB
/
viewer.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
define([
'esri/units',
'esri/geometry/Extent',
'esri/config',
/*'esri/urlUtils',*/
'esri/tasks/GeometryService',
'esri/layers/ImageParameters',
'gis/plugins/Google',
'dojo/i18n!./nls/main',
'dojo/topic',
'dojo/sniff'
], function (units, Extent, esriConfig, /*urlUtils,*/ GeometryService, ImageParameters, GoogleMapsLoader, i18n, topic, has) {
// url to your proxy page, must be on same machine hosting you app. See proxy folder for readme.
esriConfig.defaults.io.proxyUrl = 'proxy/proxy.ashx';
esriConfig.defaults.io.alwaysUseProxy = false;
// add a proxy rule to force specific domain requests through proxy
// be sure the domain is added in proxy.config
/*urlUtils.addProxyRule({
urlPrefix: 'www.example.com',
proxyUrl: 'proxy/proxy.ashx'
});*/
// url to your geometry server.
esriConfig.defaults.geometryService = new GeometryService('https://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer');
// Use your own Google Maps API Key.
// https://developers.google.com/maps/documentation/javascript/get-api-key
GoogleMapsLoader.KEY = GoogleMapsLoader.KEY || 'NOT-A-REAL-API-KEY';
// helper function returning ImageParameters for dynamic layers
// example:
// imageParameters: buildImageParameters({
// layerIds: [0],
// layerOption: 'show'
// })
function buildImageParameters (config) {
config = config || {};
var ip = new ImageParameters();
//image parameters for dynamic services, set to png32 for higher quality exports
ip.format = 'png32';
for (var key in config) {
if (config.hasOwnProperty(key)) {
ip[key] = config[key];
}
}
return ip;
}
//some example topics for listening to menu item clicks
//these topics publish a simple message to the growler
//in a real world example, these topics would be used
//in their own widget to listen for layer menu click events
topic.subscribe('layerControl/hello', function (event) {
topic.publish('growler/growl', {
title: 'Hello!',
message: event.layer._titleForLegend + ' ' +
(event.subLayer ? event.subLayer.name : '') +
' says hello'
});
});
topic.subscribe('layerControl/goodbye', function (event) {
topic.publish('growler/growl', {
title: 'Goodbye!',
message: event.layer._titleForLegend + ' ' +
(event.subLayer ? event.subLayer.name : '') +
' says goodbye'
});
});
// simple clustering example now. should be replaced with a layerControl plugin
topic.subscribe('layerControl/toggleClustering', function (event) {
var layer = event.layer;
if (layer.getFeatureReduction()) {
if (layer.isFeatureReductionEnabled()) {
layer.disableFeatureReduction();
} else {
layer.enableFeatureReduction();
}
}
});
return {
// used for debugging your app
isDebug: true,
//default mapClick mode, mapClickMode lets widgets know what mode the map is in to avoid multipult map click actions from taking place (ie identify while drawing).
defaultMapClickMode: 'identify',
// map options, passed to map constructor. see: https://developers.arcgis.com/javascript/jsapi/map-amd.html#map1
mapOptions: {
basemap: 'streets',
center: [-96.59179687497497, 39.09596293629694],
zoom: 5,
sliderStyle: 'small'
},
//webMapId: 'ef9c7fbda731474d98647bebb4b33c20', // High Cost Mortgage
// webMapOptions: {},
// panes: {
// left: {
// splitter: true
// },
// right: {
// id: 'sidebarRight',
// placeAt: 'outer',
// region: 'right',
// splitter: true,
// collapsible: true
// },
// bottom: {
// id: 'sidebarBottom',
// placeAt: 'outer',
// splitter: true,
// collapsible: true,
// region: 'bottom'
// },
// top: {
// id: 'sidebarTop',
// placeAt: 'outer',
// collapsible: true,
// splitter: true,
// region: 'top'
// }
// },
// collapseButtonsPane: 'center', //center or outer
// custom titles
titles: {
header: i18n.viewer.titles.header,
subHeader: i18n.viewer.titles.subHeader,
pageTitle: i18n.viewer.titles.pageTitle
},
layout: {
/* possible options for sidebar layout:
true - always use mobile sidebar, false - never use mobile sidebar,
'mobile' - use sidebar for phones and tablets, 'phone' - use sidebar for phones,
'touch' - use sidebar for all touch devices, 'tablet' - use sidebar for tablets only (not sure why you'd do this?),
other feature detection supported by dojo/sniff and dojo/has- http://dojotoolkit.org/reference-guide/1.10/dojo/sniff.html
default value is 'phone'
*/
//sidebar: 'phone'
},
// user-defined layer types
/*
layerTypes: {
myCustomLayer: 'widgets/MyCustomLayer'
},
*/
// user-defined widget types
/*
widgetTypes: [
'myWidgetType'
],
*/
// ignore the visibility of group layers in dynamic layers? default = true
//ignoreDynamicGroupVisibility: false,
// operationalLayers: Array of Layers to load on top of the basemap: valid 'type' options: 'dynamic', 'tiled', 'feature'.
// The 'options' object is passed as the layers options for constructor. Title will be used in the legend only. id's must be unique and have no spaces.
// 3 'mode' options: MODE_SNAPSHOT = 0, MODE_ONDEMAND = 1, MODE_SELECTION = 2
operationalLayers: [{
type: 'feature',
url: 'https://services.arcgis.com/doC3DvW5p9jGtDST/arcgis/rest/services/RestaurantInspections_April2018/FeatureServer/0/',
title: i18n.viewer.operationalLayers.restaurants,
options: {
id: 'restaurants',
opacity: 1.0,
visible: true,
outFields: ['*'],
featureReduction: has('phone') ? null : {
type: 'cluster',
clusterRadius: 10
},
mode: 0
},
editorLayerInfos: {
disableGeometryUpdate: false
},
legendLayerInfos: {
exclude: false,
layerInfo: {
title: i18n.viewer.operationalLayers.restaurants
}
},
layerControlLayerInfos: {
layerGroup: 'Grouped Feature Layers',
menu: [{
id: 'toggle-clustering-menu',
topic: 'toggleClustering',
label: 'Toggle Clustering',
iconClass: 'fas fa-fw fa-toggle-on'
}]
}
}, {
type: 'feature',
url: 'https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/SF311/FeatureServer/0',
title: i18n.viewer.operationalLayers.sf311Incidents,
options: {
id: 'sf311Incidents',
opacity: 1.0,
visible: false,
outFields: ['req_type', 'req_date', 'req_time', 'address', 'district'],
mode: 0
},
layerControlLayerInfos: {
layerGroup: 'Grouped Feature Layers',
menu: [{
topic: 'hello',
label: 'Say Hello Custom',
iconClass: 'far fa-fw fa-smile'
}]
}
}, {
type: 'dynamic',
url: 'https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyOperationalLayers/MapServer',
title: i18n.viewer.operationalLayers.louisvillePubSafety,
options: {
id: 'louisvillePubSafety',
opacity: 1.0,
visible: true,
imageParameters: buildImageParameters({
// include only sub layer ids.
// group layers omitted
layerIds: [2, 4, 5, 8, 12, 21],
layerOption: 'show'
})
},
identifyLayerInfos: {
layerIds: [2, 4, 5, 8, 12, 21]
},
layerControlLayerInfos: {
// group layers included to maintain folder hierarchy, not visibility.
layerIds: [0, 2, 4, 5, 8, 9, 10, 12, 21]
},
legendLayerInfos: {
layerInfo: {
hideLayers: [21]
}
}
}, {
type: 'dynamic',
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/MapServer',
title: i18n.viewer.operationalLayers.damageAssessment,
options: {
id: 'damageAssessment',
opacity: 1.0,
visible: true,
imageParameters: buildImageParameters()
},
identifyLayerInfos: {
returnFieldName: true
},
legendLayerInfos: {
exclude: true
},
layerControlLayerInfos: {
swipe: true,
metadataUrl: true,
expanded: true,
//override the menu on this particular layer
subLayerMenu: [{
topic: 'hello',
label: 'Say Hello',
iconClass: 'far fa-fw fa-smile'
}]
}
}, {
type: 'dynamic',
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer',
title: i18n.viewer.operationalLayers.cities,
options: {
id: 'cities',
visible: false
}
/*
//examples of vector tile layers (beta in v3.15)
}, {
type: 'vectortile',
title: 'Light Gray Canvas Vector',
url: 'https//www.arcgis.com/sharing/rest/content/items/bdf1eec3fa79456c8c7c2bb62f86dade/resources/styles/root.json',
options: {
id: 'vectortile1',
opacity: 0.8,
visible: true
}
}, {
// taken from this demo: https://github.com/ycabon/presentations/blob/gh-pages/2015-berlin-plenary/demos/3.15-vectortile/create-by-style-object.html
type: 'vectortile',
title: 'Custom Vector Style',
options: {
id: 'vectortile2',
opacity: 1.0,
visible: true,
'glyphs': 'https://www.arcgis.com/sharing/rest/content/items/00cd8e843bae49b3a040423e5d65416b/resources/fonts/{fontstack}/{range}.pbf',
'sprite': 'https://www.arcgis.com/sharing/rest/content/items/00cd8e843bae49b3a040423e5d65416b/resources/sprites/sprite',
'version': 8,
'sources': {
'esri': {
'url': 'https://basemapsdev.arcgis.com/arcgis/rest/services/World_Basemap/VectorTileServer',
'type': 'vector'
}
},
'layers': [{
'id': 'background',
'type': 'background',
'paint': {
'background-color': '#556688'
}
}, {
'id': 'Land',
'type': 'fill',
'source': 'esri',
'source-layer': 'Land',
'paint': {
'fill-color': '#273344'
},
}, {
'id': 'roads',
'type': 'line',
'source': 'esri',
'source-layer': 'Road',
'layout': {
'line-join': 'round'
},
'paint': {
'line-width': 1,
'line-color': '#131622'
}
}]
}
*/
}],
// set include:true to load. For titlePane type set position the the desired order in the sidebar
widgets: {
growler: {
include: true,
id: 'growler',
type: 'layout',
path: 'gis/dijit/Growler',
placeAt: document.body,
options: {
style: 'position:absolute;top:15px;' + (has('phone') ? 'left:50%;transform:translate(-50%,0);' : 'right:15px;')
}
},
search: {
include: true,
type: has('phone') ? 'titlePane' : 'ui',
path: 'esri/dijit/Search',
placeAt: has('phone') ? null : 'top-center',
title: i18n.viewer.widgets.search,
iconClass: 'fas fa-search',
position: 0,
options: {
map: true,
visible: true,
enableInfoWindow: false,
enableButtonMode: has('phone') ? false : true,
expanded: has('phone') ? true : false
}
},
reverseGeocoder: {
include: true,
type: 'invisible',
path: 'gis/dijit/ReverseGeocoder',
options: {
map: true,
mapRightClickMenu: true
}
},
basemaps: {
include: true,
id: 'basemaps',
type: 'ui',
path: 'gis/dijit/Basemaps',
placeAt: 'top-right',
position: 'first',
options: 'config/basemaps'
},
identify: {
include: true,
id: 'identify',
type: 'titlePane',
path: 'gis/dijit/Identify',
title: i18n.viewer.widgets.identify,
iconClass: 'fas fa-fw fa-info-circle',
open: false,
preload: true,
position: 3,
options: 'config/identify'
},
mapInfo: {
include: false,
id: 'mapInfo',
type: 'domNode',
path: 'gis/dijit/MapInfo',
srcNodeRef: 'mapInfoDijit',
options: {
map: true,
mode: 'dms',
firstCoord: 'y',
unitScale: 3,
showScale: true,
xLabel: '',
yLabel: '',
minWidth: 286
}
},
scalebar: {
include: true,
id: 'scalebar',
type: 'map',
path: 'esri/dijit/Scalebar',
options: {
map: true,
attachTo: 'bottom-left',
scalebarStyle: 'line',
scalebarUnit: 'dual'
}
},
locateButton: {
include: true,
id: 'locateButton',
type: 'ui',
path: 'gis/dijit/LocateButton',
placeAt: 'top-left',
position: 'last',
options: {
map: true,
publishGPSPosition: true,
highlightLocation: true,
useTracking: true,
geolocationOptions: {
maximumAge: 0,
timeout: 15000,
enableHighAccuracy: true
}
}
},
overviewMap: {
include: has('phone') ? false : true,
id: 'overviewMap',
type: 'map',
path: 'esri/dijit/OverviewMap',
options: {
map: true,
attachTo: 'bottom-right',
color: '#0000CC',
height: 100,
width: 125,
opacity: 0.30,
visible: false
}
},
homeButton: {
include: true,
id: 'homeButton',
type: 'ui',
path: 'esri/dijit/HomeButton',
placeAt: 'top-left',
options: {
map: true,
extent: new Extent({
xmin: -180,
ymin: -85,
xmax: 180,
ymax: 85,
spatialReference: {
wkid: 4326
}
})
}
},
legend: {
include: true,
id: 'legend',
type: 'titlePane',
path: 'gis/dijit/Legend',
title: i18n.viewer.widgets.legend,
iconClass: 'far fa-fw fa-images',
open: false,
position: 1,
options: {
map: true,
legendLayerInfos: true
}
},
layerControl: {
include: true,
id: 'layerControl',
type: 'titlePane',
path: 'gis/dijit/LayerControl',
title: i18n.viewer.widgets.layerControl,
iconClass: 'fas fa-fw fa-th-list',
open: false,
position: 0,
options: {
map: true,
layerControlLayerInfos: true,
separated: true,
vectorReorder: true,
overlayReorder: true,
// create a custom menu entry in all of these feature types
// the custom menu item will publish a topic when clicked
menu: {
feature: [{
topic: 'hello',
iconClass: 'fas fa-fw fa-smile',
label: 'Say Hello'
}]
},
//create a example sub layer menu that will
//apply to all layers of type 'dynamic'
subLayerMenu: {
dynamic: [{
topic: 'goodbye',
iconClass: 'fas fa-fw fa-frown',
label: 'Say goodbye'
}]
}
}
},
bookmarks: {
include: true,
id: 'bookmarks',
type: 'titlePane',
path: 'gis/dijit/Bookmarks',
title: i18n.viewer.widgets.bookmarks,
iconClass: 'fas fa-fw fa-bookmark',
open: false,
position: 2,
options: 'config/bookmarks'
},
find: {
include: true,
id: 'find',
type: 'titlePane',
canFloat: true,
path: 'gis/dijit/Find',
title: i18n.viewer.widgets.find,
iconClass: 'fas fa-fw fa-search',
open: false,
position: 3,
options: 'config/find'
},
draw: {
include: true,
id: 'draw',
type: 'titlePane',
canFloat: true,
path: 'gis/dijit/Draw',
title: i18n.viewer.widgets.draw,
iconClass: 'fas fa-fw fa-paint-brush',
open: false,
position: 4,
options: {
map: true,
mapClickMode: true
}
},
measure: {
include: true,
id: 'measurement',
type: 'titlePane',
canFloat: true,
path: 'gis/dijit/Measurement',
title: i18n.viewer.widgets.measure,
iconClass: 'fas fa-fw fa-expand',
open: false,
position: 5,
options: {
map: true,
mapClickMode: true,
defaultAreaUnit: units.SQUARE_MILES,
defaultLengthUnit: units.MILES
}
},
print: {
include: true,
id: 'print',
type: 'titlePane',
canFloat: true,
path: 'gis/dijit/Print',
title: i18n.viewer.widgets.print,
iconClass: 'fas fa-fw fa-print',
open: false,
position: 6,
options: {
map: true,
printTaskURL: 'https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task',
copyrightText: 'Copyright ' + new Date().getFullYear(),
authorText: 'Me',
defaultTitle: 'Viewer Map',
defaultFormat: 'PDF',
defaultLayout: 'Letter ANSI A Landscape',
customTextElements: [
//property name should match the custom element in the mxd. Value should be what you want the label to be.
/*
{
subTitle: 'Subtitle'
}
*/
]
}
},
directions: {
include: true,
id: 'directions',
type: 'titlePane',
path: 'gis/dijit/Directions',
title: i18n.viewer.widgets.directions,
iconClass: 'fas fa-fw fa-map-signs',
open: false,
position: 7,
options: {
map: true,
mapRightClickMenu: true,
options: {
routeTaskUrl: 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route',
routeParams: {
directionsLanguage: 'en-US',
directionsLengthUnits: units.MILES
},
active: false //for 3.12, starts active by default, which we dont want as it interfears with mapClickMode
}
}
},
editor: {
include: has('phone') ? false : true,
id: 'editor',
type: 'titlePane',
path: 'gis/dijit/Editor',
title: i18n.viewer.widgets.editor,
iconClass: 'fas fa-fw fa-pencil-alt',
open: false,
position: 8,
options: {
map: true,
mapClickMode: true,
editorLayerInfos: true,
settings: {
toolbarVisible: true,
showAttributesOnClick: true,
enableUndoRedo: true,
createOptions: {
polygonDrawTools: ['freehandpolygon', 'autocomplete']
},
toolbarOptions: {
reshapeVisible: true,
cutVisible: true,
mergeVisible: true
}
}
}
},
streetview: {
include: true,
id: 'streetview',
type: 'titlePane',
canFloat: true,
position: 9,
path: 'gis/dijit/StreetView',
title: i18n.viewer.widgets.streetview,
iconClass: 'fas fa-fw fa-street-view',
paneOptions: {
resizable: true,
resizeOptions: {
minSize: {
w: 250,
h: 250
}
}
},
options: {
map: true,
mapClickMode: true,
mapRightClickMenu: true
}
},
locale: {
include: true,
type: has('phone') ? 'titlePane' : 'domNode',
id: 'locale',
position: 0,
srcNodeRef: 'geocodeDijit',
path: 'gis/dijit/Locale',
title: i18n.viewer.widgets.locale,
iconClass: 'fas fa-fw fa-flag',
options: {
style: has('phone') ? null : 'margin-left: 30px;'
}
},
help: {
include: has('phone') ? false : true,
id: 'help',
type: 'floating',
path: 'gis/dijit/Help',
title: i18n.viewer.widgets.help,
iconClass: 'fas fa-fw fa-info-circle',
paneOptions: {
draggable: false,
html: '<a href="#"><i class="fas fa-fw fa-info-circle"></i>link</a>'.replace('link', i18n.viewer.widgets.help),
domTarget: 'helpDijit',
style: 'height:345px;width:450px;'
},
options: {}
}
}
};
});