|
67 | 67 | show:{ effect: false, delay: 700} |
68 | 68 | }); |
69 | 69 |
|
70 | | - var v = {}; //views |
71 | | - var m = {}; //models |
72 | | - var t = {}; //templates |
73 | | - |
74 | 70 | var colors = d3.scale.category10(); |
75 | 71 | var color_index = 0; |
76 | 72 |
|
|
86 | 82 | }, this); |
87 | 83 |
|
88 | 84 | //Load all configured views |
89 | | - _.each(config.views, function(viewDef) { |
90 | | - var View = require(viewDef); |
91 | | - $.extend(v, View); |
92 | | - }, this); |
| 85 | + var views = {}; |
| 86 | + _.each(config.views, function(item){ $.extend(views,require(item)); }, this); |
93 | 87 |
|
94 | 88 | //Load all configured models |
95 | | - _.each(config.models, function(modelDef) { |
96 | | - var Model = require(modelDef); |
97 | | - $.extend(m, Model); |
98 | | - }, this); |
| 89 | + var models = {} |
| 90 | + _.each(config.models, function(item){ $.extend(models,require(item)); }, this); |
99 | 91 |
|
100 | 92 | //Load all configured templates |
101 | | - _.each(config.templates, function(tmplDef) { |
102 | | - var Tmpl = require(tmplDef.template); |
103 | | - t[tmplDef.id] = Tmpl; |
104 | | - }, this); |
| 93 | + var templates = {}; //templates |
| 94 | + _.each(config.templates, function(item){ templates[item.id] = require(item.template); }, this); |
105 | 95 |
|
106 | 96 |
|
107 | 97 | //Map attributes are loaded and added to the global map model |
108 | | - globals.objects.add('mapmodel', new m.MapModel({ |
109 | | - visualizationLibs : config.mapConfig.visualizationLibs, |
110 | | - center: config.mapConfig.center, |
111 | | - zoom: config.mapConfig.zoom |
112 | | - }) |
113 | | - ); |
| 98 | + globals.objects.add('mapmodel', models.parseMapConfig(config.mapConfig)); |
114 | 99 |
|
115 | 100 | //Base Layers are loaded and added to the global collection |
116 | | - _.each(config.mapConfig.baseLayers, function(baselayer) { |
117 | | - |
118 | | - globals.baseLayers.add( |
119 | | - new m.LayerModel({ |
120 | | - name: baselayer.name, |
121 | | - visible: baselayer.visible, |
122 | | - view: { |
123 | | - id : baselayer.id, |
124 | | - urls : baselayer.urls, |
125 | | - protocol: baselayer.protocol, |
126 | | - projection: baselayer.projection, |
127 | | - attribution: baselayer.attribution, |
128 | | - matrixSet: baselayer.matrixSet, |
129 | | - style: baselayer.style, |
130 | | - format: baselayer.format, |
131 | | - resolutions: baselayer.resolutions, |
132 | | - maxExtent: baselayer.maxExtent, |
133 | | - gutter: baselayer.gutter, |
134 | | - buffer: baselayer.buffer, |
135 | | - units: baselayer.units, |
136 | | - transitionEffect: baselayer.transitionEffect, |
137 | | - isphericalMercator: baselayer.isphericalMercator, |
138 | | - isBaseLayer: true, |
139 | | - wrapDateLine: baselayer.wrapDateLine, |
140 | | - zoomOffset: baselayer.zoomOffset, |
141 | | - time: baselayer.time, |
142 | | - requestEncoding: baselayer.requestEncoding |
143 | | - } |
144 | | - }) |
145 | | - ); |
146 | | - console.log("Added baselayer " + baselayer.id ); |
| 101 | + _.each(config.mapConfig.baseLayers, function(item) { |
| 102 | + globals.baseLayers.add( models.parseBaseLayer(item) ); |
| 103 | + console.log("Added base-layer " + item.id ); |
147 | 104 | }, this); |
148 | 105 |
|
149 | | - //Productsare loaded and added to the global collection |
150 | | - _.each(config.mapConfig.products, function(products) { |
151 | | - |
152 | | - if (! products.info ) { |
153 | | - products.info = {} ; |
154 | | - } |
155 | | - |
156 | | - var is_wms = ( products.view.protocol == 'WMS' ) |
157 | | - |
158 | | - // parse extra wms layers |
159 | | - var extraLayers = {}; |
160 | | - if ( products.view.extraLayers && typeof products.view.extraLayers == 'object' ) { |
161 | | - extraLayers = _.extend({},products.view.extraLayers); |
162 | | - } |
163 | | - |
164 | | - globals.products.add( |
165 | | - new m.LayerModel({ |
166 | | - name: products.name, |
167 | | - description: (products.description ? products.description: null), |
168 | | - visible: products.visible, |
169 | | - timeSlider: products.timeSlider, |
170 | | - // Default to WMS if no protocol is defined (allowed protocols: WMS|EOWCS|WPS) |
171 | | - timeSliderProtocol: (products.timeSliderProtocol) ? products.timeSliderProtocol : 'WMS', |
172 | | - color: (products.color) ? products.color : colors(color_index++), |
173 | | - time: products.time, |
174 | | - opacity: 1, |
175 | | - view:{ |
176 | | - id : products.view.id, |
177 | | - protocol: products.view.protocol, |
178 | | - urls : products.view.urls, |
179 | | - visualization: products.view.visualization, |
180 | | - projection: products.view.projection, |
181 | | - attribution: products.view.attribution, |
182 | | - matrixSet: products.view.matrixSet, |
183 | | - style: products.view.style, |
184 | | - format: products.view.format, |
185 | | - resolutions: products.view.resolutions, |
186 | | - maxExtent: products.view.maxExtent, |
187 | | - gutter: products.view.gutter, |
188 | | - buffer: products.view.buffer, |
189 | | - units: products.view.units, |
190 | | - transitionEffect: products.view.transitionEffect, |
191 | | - isphericalMercator: products.view.isphericalMercator, |
192 | | - isBaseLayer: false, |
193 | | - wrapDateLine: products.view.wrapDateLine, |
194 | | - zoomOffset: products.view.zoomOffset, |
195 | | - requestEncoding: products.view.requestEncoding, |
196 | | - extraLayers: extraLayers |
197 | | - }, |
198 | | - download: { |
199 | | - id : products.download.id, |
200 | | - protocol: products.download.protocol, |
201 | | - url : products.download.url, |
202 | | - rectified: ( products.rectified != null ? products.rectified : true ) |
203 | | - }, |
204 | | - info: { |
205 | | - // NOTE: If the wiew protocol is WMS info default to getFeatureInfo() |
206 | | - // on the same layer. |
207 | | - id: products.info.id ? products.info.id : ( is_wms ? products.view.id : null ), |
208 | | - protocol: products.info.protocol ? products.info.protocol : ( is_wms ? 'WMS' : null ), |
209 | | - url: products.info.url ? products.info.url : ( is_wms ? products.view.urls[0] : null ) |
210 | | - } |
211 | | - }) |
212 | | - ); |
213 | | - console.log("Added product " + products.view.id ); |
| 106 | + //Overlays are loaded and added to the global collection |
| 107 | + _.each(config.mapConfig.overlays, function(item) { |
| 108 | + globals.overlays.add( models.parseOverlayLayer(item) ); |
| 109 | + console.log("Added overlay-layer " + item.id ); |
214 | 110 | }, this); |
215 | 111 |
|
216 | | - //Overlays are loaded and added to the global collection |
217 | | - _.each(config.mapConfig.overlays, function(overlay) { |
218 | | - |
219 | | - globals.overlays.add( |
220 | | - new m.LayerModel({ |
221 | | - name: overlay.name, |
222 | | - visible: overlay.visible, |
223 | | - view: { |
224 | | - id : overlay.id, |
225 | | - urls : overlay.urls, |
226 | | - protocol: overlay.protocol, |
227 | | - projection: overlay.projection, |
228 | | - attribution: overlay.attribution, |
229 | | - matrixSet: overlay.matrixSet, |
230 | | - style: overlay.style, |
231 | | - format: overlay.format, |
232 | | - resolutions: overlay.resolutions, |
233 | | - maxExtent: overlay.maxExtent, |
234 | | - gutter: overlay.gutter, |
235 | | - buffer: overlay.buffer, |
236 | | - units: overlay.units, |
237 | | - transitionEffect: overlay.transitionEffect, |
238 | | - isphericalMercator: overlay.isphericalMercator, |
239 | | - isBaseLayer: false, |
240 | | - wrapDateLine: overlay.wrapDateLine, |
241 | | - zoomOffset: overlay.zoomOffset, |
242 | | - time: overlay.time, |
243 | | - requestEncoding: overlay.requestEncoding |
244 | | - } |
245 | | - }) |
246 | | - ); |
247 | | - console.log("Added overlay " + overlay.id ); |
| 112 | + //Productsare loaded and added to the global collection |
| 113 | + _.each(config.mapConfig.products, function(item) { |
| 114 | + globals.products.add( models.parseProductLayer(item) ); |
| 115 | + console.log("Added data-layer " + item.view.id ); |
248 | 116 | }, this); |
249 | 117 |
|
250 | 118 |
|
251 | 119 | // Create map view and execute show of its region |
252 | | - this.map.show(new v.MapView({el: $("#map")})); |
| 120 | + this.map.show(new views.MapView({el: $("#map")})); |
253 | 121 |
|
254 | 122 | // If Navigation Bar is set in configuration go through the |
255 | 123 | // defined elements creating a item collection to rendered |
256 | 124 | // by the marionette collection view |
257 | 125 | if (config.navBarConfig) { |
258 | 126 |
|
259 | | - var navBarItemCollection = new m.NavBarCollection; |
| 127 | + var navBarItemCollection = new models.NavBarCollection(); |
260 | 128 |
|
261 | | - _.each(config.navBarConfig.items, function(list_item){ |
262 | | - navBarItemCollection.add( |
263 | | - new m.NavBarItemModel({ |
264 | | - name:list_item.name, |
265 | | - icon:list_item.icon, |
266 | | - eventToRaise:list_item.eventToRaise |
267 | | - })); |
| 129 | + _.each(config.navBarConfig.items, function(item){ |
| 130 | + navBarItemCollection.add(models.parseNavBarItemConfig(item)); |
268 | 131 | }, this); |
269 | 132 |
|
270 | | - this.topBar.show(new v.NavBarCollectionView( |
271 | | - {template: t.NavBar({ |
| 133 | + this.topBar.show(new views.NavBarCollectionView( |
| 134 | + {template: templates.NavBar({ |
272 | 135 | title: config.navBarConfig.title, |
273 | 136 | url: config.navBarConfig.url}), |
274 | 137 | className:"navbar navbar-inverse navbar-opaque navbar-fixed-top not-selectable", |
275 | | - itemView: v.NavBarItemView, tag: "div", |
| 138 | + itemView: views.NavBarItemView, tag: "div", |
276 | 139 | collection: navBarItemCollection})); |
277 | 140 |
|
278 | 141 | }; |
279 | 142 |
|
280 | 143 | // Added region to test combination of backbone |
281 | 144 | // functionality combined with jQuery UI |
282 | 145 | this.addRegions({dialogRegion: DialogRegion.extend({el: "#viewContent"})}); |
283 | | - this.DialogContentView = new v.ContentView({ |
284 | | - template: {type: 'handlebars', template: t.Info}, |
| 146 | + this.DialogContentView = new views.ContentView({ |
| 147 | + template: {type: 'handlebars', template: templates.Info}, |
285 | 148 | id: "about", |
286 | 149 | className: "modal fade", |
287 | 150 | attributes: { |
|
295 | 158 | }); |
296 | 159 |
|
297 | 160 | // Create the views - these are Marionette.CollectionViews that render ItemViews |
298 | | - this.baseLayerView = new v.BaseLayerSelectionView({ |
| 161 | + this.baseLayerView = new views.BaseLayerSelectionView({ |
299 | 162 | collection:globals.baseLayers, |
300 | | - itemView: v.LayerItemView.extend({ |
| 163 | + itemView: views.LayerItemView.extend({ |
301 | 164 | template: { |
302 | 165 | type:'handlebars', |
303 | | - template: t.BulletLayer}, |
| 166 | + template: templates.BulletLayer |
| 167 | + }, |
304 | 168 | className: "radio" |
305 | 169 | }) |
306 | 170 | }); |
307 | 171 |
|
308 | | - this.productsView = new v.LayerSelectionView({ |
| 172 | + this.productsView = new views.LayerSelectionView({ |
309 | 173 | collection:globals.products, |
310 | | - itemView: v.LayerItemView.extend({ |
| 174 | + itemView: views.LayerItemView.extend({ |
311 | 175 | template: { |
312 | 176 | type:'handlebars', |
313 | | - template: t.CheckBoxLayer}, |
| 177 | + template: templates.CheckBoxLayer |
| 178 | + }, |
314 | 179 | className: "sortable-layer" |
315 | 180 | }), |
316 | 181 | className: "sortable" |
317 | 182 | }); |
318 | 183 |
|
319 | | - this.overlaysView = new v.BaseLayerSelectionView({ |
| 184 | + this.overlaysView = new views.BaseLayerSelectionView({ |
320 | 185 | collection:globals.overlays, |
321 | | - itemView: v.LayerItemView.extend({ |
| 186 | + itemView: views.LayerItemView.extend({ |
322 | 187 | template: { |
323 | 188 | type:'handlebars', |
324 | | - template: t.CheckBoxOverlayLayer}, |
| 189 | + template: templates.CheckBoxOverlayLayer |
| 190 | + }, |
325 | 191 | className: "checkbox" |
326 | 192 | }), |
327 | 193 | className: "check" |
|
332 | 198 |
|
333 | 199 |
|
334 | 200 | // Define collection of selection tools |
335 | | - var selectionToolsCollection = new m.ToolCollection(); |
336 | | - _.each(config.selectionTools, function(selTool) { |
337 | | - selectionToolsCollection.add( |
338 | | - new m.ToolModel({ |
339 | | - id: selTool.id, |
340 | | - description: selTool.description, |
341 | | - icon:selTool.icon, |
342 | | - enabled: true, |
343 | | - active: false, |
344 | | - type: "selection" |
345 | | - })); |
| 201 | + var selectionToolsCollection = new models.ToolCollection(); |
| 202 | + _.each(config.selectionTools, function(item) { |
| 203 | + selectionToolsCollection.add( models.parseSelectionTool(item) ); |
346 | 204 | }, this); |
347 | 205 |
|
348 | 206 | // Define collection of visualization tools |
349 | | - var visualizationToolsCollection = new m.ToolCollection(); |
350 | | - _.each(config.visualizationTools, function(visTool) { |
351 | | - visualizationToolsCollection.add( |
352 | | - new m.ToolModel({ |
353 | | - id: visTool.id, |
354 | | - eventToRaise: visTool.eventToRaise, |
355 | | - description: visTool.description, |
356 | | - disabledDescription: visTool.disabledDescription, |
357 | | - icon:visTool.icon, |
358 | | - enabled: visTool.enabled, |
359 | | - active: visTool.active, |
360 | | - type: "tool" |
361 | | - })); |
| 207 | + var visualizationToolsCollection = new models.ToolCollection(); |
| 208 | + _.each(config.visualizationTools, function(item) { |
| 209 | + visualizationToolsCollection.add( models.parseVisualizationTool(item) ); |
362 | 210 | }, this); |
363 | 211 |
|
364 | 212 | // Create Collection Views to hold set of views for selection tools |
365 | | - this.visualizationToolsView = new v.ToolSelectionView({ |
| 213 | + this.visualizationToolsView = new views.ToolSelectionView({ |
366 | 214 | collection:visualizationToolsCollection, |
367 | | - itemView: v.ToolItemView.extend({ |
| 215 | + itemView: views.ToolItemView.extend({ |
368 | 216 | template: { |
369 | 217 | type:'handlebars', |
370 | | - template: t.ToolIcon} |
| 218 | + template: templates.ToolIcon |
| 219 | + } |
371 | 220 | }) |
372 | 221 | }); |
373 | 222 |
|
374 | 223 | // Create Collection Views to hold set of views for visualization tools |
375 | | - this.selectionToolsView = new v.ToolSelectionView({ |
| 224 | + this.selectionToolsView = new views.ToolSelectionView({ |
376 | 225 | collection:selectionToolsCollection, |
377 | | - itemView: v.ToolItemView.extend({ |
| 226 | + itemView: views.ToolItemView.extend({ |
378 | 227 | template: { |
379 | 228 | type:'handlebars', |
380 | | - template: t.ToolIcon} |
| 229 | + template: templates.ToolIcon |
| 230 | + } |
381 | 231 | }) |
382 | 232 | }); |
383 | 233 |
|
384 | 234 |
|
385 | | - |
386 | 235 | // Create layout to hold collection views |
387 | 236 | this.toolLayout = new ToolControlLayout(); |
388 | 237 |
|
389 | 238 |
|
390 | | - this.timeSliderView = new v.TimeSliderView(config.timeSlider); |
| 239 | + this.timeSliderView = new views.TimeSliderView(config.timeSlider); |
391 | 240 | this.bottomBar.show(this.timeSliderView); |
392 | 241 |
|
393 | 242 | // Add a trigger for ajax calls in order to display loading state |
|
430 | 279 |
|
431 | 280 | } |
432 | 281 |
|
433 | | - |
434 | | - |
435 | 282 | }); |
436 | 283 |
|
437 | 284 | return new Application(); |
|
0 commit comments