|
31 | 31 | root.define([ |
32 | 32 | 'backbone', |
33 | 33 | 'communicator', |
| 34 | + 'views/AuthView', |
| 35 | + 'models/AuthModel', |
34 | 36 | 'globals', |
| 37 | + 'app', |
35 | 38 | 'hbs!tmpl/BulletLayer', |
| 39 | + 'hbs!tmpl/iFrame', |
36 | 40 | 'underscore' |
37 | 41 | ], |
38 | | - function( Backbone, Communicator, globals, BulletLayerTmpl) { |
| 42 | + function( Backbone, Communicator, av, am, globals, App, BulletLayerTmpl, iFrameTmpl) { |
39 | 43 | var LayerItemView = Backbone.Marionette.ItemView.extend({ |
40 | 44 | tagName: "li", |
41 | 45 | events: { |
|
86 | 90 | if (this.model.get('view').isBaseLayer) |
87 | 91 | isBaseLayer = true; |
88 | 92 | var options = { name: this.model.get('name'), isBaseLayer: isBaseLayer, visible: evt.target.checked }; |
89 | | - |
90 | | - var product = globals.products.find(function(model) { return model.get('name') == options.name; }); |
91 | | - |
92 | | - if (product){ |
93 | | - |
94 | | - if (options.visible && product.get("view").protocol=="WMS"){ |
95 | | - var getmap = "?LAYERS="+product.get("view").id+"&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.0&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&BBOX=33.75,56.25,39.375,61.875&WIDTH=256&HEIGHT=256&TIME=2014-02-19T00:00:00Z/2014-02-19T00:00:00Z" |
96 | | - $.get(product.get("view").urls[0] + getmap, function (){ |
97 | | - Communicator.mediator.trigger('map:layer:change', options); |
98 | | - }, 'text'); |
99 | | - } else { |
100 | | - Communicator.mediator.trigger('map:layer:change', options); |
101 | | - } |
102 | | - }else{ |
103 | | - Communicator.mediator.trigger('map:layer:change', options); |
104 | | - } |
| 93 | + if( !isBaseLayer && evt.target.checked ){ |
| 94 | + var layer = globals.products.find(function(model) { return model.get('name') == options.name; }); |
| 95 | + if (layer != -1) { |
| 96 | + var url = layer.get('view').urls[0]+"?"; |
| 97 | + |
| 98 | + if (url.indexOf('https') > -1){ |
| 99 | + |
| 100 | + var layer = layer.get('view').id; |
| 101 | + var req = "LAYERS=" + layer + "&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326"; |
| 102 | + req += "&BBOX=33.75,56.25,33.80,56.50&WIDTH=2&HEIGHT=2"; |
| 103 | + req = url + req; |
| 104 | + |
| 105 | + $.ajax({ |
| 106 | + url: req, |
| 107 | + type: "GET", |
| 108 | + suppressErrors: true, |
| 109 | + xhrFields: { |
| 110 | + withCredentials: true |
| 111 | + }, |
| 112 | + success: function(xml, textStatus, xhr) { |
| 113 | + Communicator.mediator.trigger('map:layer:change', options); |
| 114 | + }, |
| 115 | + error: function(jqXHR, textStatus, errorThrown) { |
| 116 | + if (jqXHR.status == 403){ |
| 117 | + $("#error-messages").append( |
| 118 | + '<div class="alert alert-warning alert-danger">'+ |
| 119 | + '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'+ |
| 120 | + '<strong>Warning!</strong> You are not authorized to access this product' + |
| 121 | + '</div>' |
| 122 | + ); |
| 123 | + }else{ |
| 124 | + |
| 125 | + this.authview = new av.AuthView({ |
| 126 | + model: new am.AuthModel({url:req}), |
| 127 | + template: iFrameTmpl, |
| 128 | + layerprop: options |
| 129 | + }); |
| 130 | + |
| 131 | + Communicator.mediator.trigger("progress:change", false); |
| 132 | + |
| 133 | + App.info.show(this.authview); |
| 134 | + |
| 135 | + } |
| 136 | + } |
| 137 | + }); |
| 138 | + }else{ |
| 139 | + Communicator.mediator.trigger('map:layer:change', options); |
| 140 | + } |
| 141 | + } |
| 142 | + } else if (!evt.target.checked){ |
| 143 | + Communicator.mediator.trigger('map:layer:change', options); |
| 144 | + } |
105 | 145 | }, |
106 | 146 |
|
107 | 147 | drop: function(event, index) { |
|
0 commit comments