/
App.js
151 lines (127 loc) · 4.66 KB
/
App.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
define([
'app/config',
'app/CurrentLocation',
'app/Layers',
'app/mapController',
'dijit/_TemplatedMixin',
'dijit/_WidgetBase',
'dijit/_WidgetsInTemplateMixin',
'dojo/dom-class',
'dojo/on',
'dojo/query',
'dojo/text!app/templates/App.html',
'dojo/topic',
'dojo/_base/array',
'dojo/_base/declare',
'dojo/_base/lang',
'bootstrap',
'dijit/layout/ContentPane'
], function (
config,
CurrentLocation,
Layers,
mapController,
_TemplatedMixin,
_WidgetBase,
_WidgetsInTemplateMixin,
domClass,
on,
query,
template,
topic,
array,
declare,
lang
) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
// summary:
// The main widget for the app
widgetsInTemplate: true,
templateString: template,
baseClass: 'app',
// childWidgets: Object[]
// container for holding custom child widgets
childWidgets: null,
// map: BaseMap
map: null,
constructor: function () {
// summary:
// first function to fire after page loads
console.info('app.App:constructor', arguments);
config.app = this;
this.childWidgets = [];
this.inherited(arguments);
},
postCreate: function () {
// summary:
// Fires when
console.log('app.App:postCreate', arguments);
this.own(
topic.subscribe('agrc.widgets.locate.FindAddress.OnFind', () => {
if (domClass.contains(this.sideBar, 'expanded')) {
this.toggleMobilePane();
}
})
);
$('.expertLogo').tooltip();
this.currentLocation = new CurrentLocation();
this.childWidgets.push(this.layers = new Layers({}, this.layersDiv));
// hack to wire together the commuter rail layers since
// they don't support feature and dynamic in the same layer
// lightrail rail (hidden)
var syncCheckbox = function (hChbx, evt) {
hChbx.checked = evt.target.checked;
on.emit(hChbx, 'change', {bubbles: true});
};
var hiddenCheckbox = query('.layer input[value="18"]')[0];
// Commuter Rail
var lrCheckbox = query('.layer input[value="17"]')[0];
on(lrCheckbox, 'change', lang.partial(syncCheckbox, hiddenCheckbox));
// commuter rail (hidden)
hiddenCheckbox = query('.layer input[value="24"]')[0];
on(lrCheckbox, 'change', lang.partial(syncCheckbox, hiddenCheckbox));
// commuter rail stations (hidden)
hiddenCheckbox = query('.layer input[value="23"]')[0];
on(lrCheckbox, 'change', lang.partial(syncCheckbox, hiddenCheckbox));
// same thing for airports layers
hiddenCheckbox = query('.layer input[value="21"]')[0];
// Airports
lrCheckbox = query('.layer input[value="5"]')[0];
on(lrCheckbox, 'change', lang.partial(syncCheckbox, hiddenCheckbox));
// national parks
hiddenCheckbox = query('.layer input[value="26"]')[0];
lrCheckbox = query('.layer input[value="20"]')[0];
on(lrCheckbox, 'change', lang.partial(syncCheckbox, hiddenCheckbox));
this.inherited(arguments);
},
toggleMobilePane() {
// summary:
// expands the side bar to fill the screen (mobile only)
console.log('app/App:toggleMobilePane', arguments);
domClass.toggle(this.sideBar, 'expanded');
domClass.toggle(this.mapDiv, 'hidden');
domClass.toggle(this.mobileBtnSpan, 'glyphicon-menu-hamburger');
domClass.toggle(this.mobileBtnSpan, 'glyphicon-globe');
},
startup: function () {
// summary:
// Fires after postCreate when all of the child widgets are finished laying out.
console.log('app.App:startup', arguments);
var that = this;
mapController.initMap(this.mapDiv);
array.forEach(this.childWidgets, function (widget) {
that.own(widget);
widget.startup();
});
this.inherited(arguments);
},
destroy: function () {
// summary:
// description
console.log('app/App:destroy', arguments);
mapController.destroy();
this.currentLocation.destroy();
this.inherited(arguments);
}
});
});