Skip to content

Commit d4b3616

Browse files
committed
GetFeatureInfo: improving the cross-browser support.
1 parent 229b86b commit d4b3616

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

app/scripts/models/LayerInfoModel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
}) ;
7676

7777
this.set({responses: resps});
78-
7978
},
8079

8180
finish: function() {

app/scripts/views/LayerInfoView.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848

4949
initialize: function() {
5050

51-
this.model.on('change:lonlat',this.update,this);
51+
this.model.on('change:responseExpected',this.update,this);
52+
this.model.on('change:lonlat',this.updateLonLat,this);
5253
this.model.on('change:responses',this.update,this);
5354

5455
},
@@ -68,9 +69,7 @@
6869

6970
onClose: function() {},
7071

71-
update: function() {
72-
73-
// local utilities
72+
updateLonLat: function() {
7473

7574
function dec2dg(v,neg,pos){
7675
var tmp = v;
@@ -82,6 +81,14 @@
8281
return dg+'° '+mn+'′ '+tmp.toFixed(2)+'″ '+ltr;
8382
}
8483

84+
// update click location
85+
var ll = this.model.get('lonlat') ;
86+
$('#layer-info-location-lon').html( ll ? dec2dg(ll.lon,'W','E') : 'n/a' );
87+
$('#layer-info-location-lat').html( ll ? dec2dg(ll.lat,'S','N') : 'n/a' );
88+
},
89+
90+
update: function() {
91+
8592
function getFirstValidResp( list ){
8693
for ( var i = 0 ; i < list.length ; ++i ) {
8794
if ( list[i].data ) { return list[i] ; }
@@ -90,40 +97,37 @@
9097
}
9198

9299
// update the view
100+
var inProgress = this.model.get('responseExpected');
101+
var products = this.model.get('products');
102+
var response = getFirstValidResp( this.model.get('responses') );
93103

94-
// click location
95-
var ll = this.model.get('lonlat') ;
96-
$('#layer-info-location-lon').html( ll ? dec2dg(ll.lon,'W','E') : 'n/a' );
97-
$('#layer-info-location-lat').html( ll ? dec2dg(ll.lat,'S','N') : 'n/a' );
98-
99-
// content
100-
var prds = this.model.get('products');
101-
var rsp = getFirstValidResp( this.model.get('responses') );
104+
// abort update if no valid response received yet
105+
if ( inProgress && !response ) { $('#layer-info-view-alert').html("Query in progress ...") ; return ; }
102106

103107
var msg_common = "<br>Clict on the map to update this view."
104-
var msg = ( rsp ? '' : ( prds.length > 0 ? 'No feature has been selected.' :
108+
var msg = ( response ? '' : ( products.length > 0 ? 'No feature has been selected.' :
105109
'There is no layer selected.<br>Select one in the <strong>Layers</strong> overlay.')+msg_common);
106110

107111
$('#layer-info-view-alert').html(msg)
108112

109-
$('#layer-info-layer-name').html( rsp ? rsp.info.name : "n/a");
110-
$('#layer-info-layer-descr').html( rsp ? rsp.info.description : "n/a");
113+
$('#layer-info-layer-name').html( response ? response.info.name : "n/a");
114+
$('#layer-info-layer-descr').html( response ? response.info.description : "n/a");
111115

112116
// display layer's overlay
113-
if ( !rsp && prds.length == 0 ) {
117+
if ( !response && products.length == 0 ) {
114118
Communicator.mediator.trigger('ui:open:layercontrol');
115119
}
116120

117121
var frame = $('#layer-info-frame') ;
118122

119-
if ( rsp && rsp.protocol == 'WMS' && rsp.request.type == 'GET' ) {
123+
if ( response && response.protocol == 'WMS' && response.request.type == 'GET' ) {
120124
frame.css('display','block');
121-
//frame.attr('src',rsp.request.url);
122-
frame.attr('srcdoc',rsp.data); // HTML5 feature
125+
frame.attr('srcdoc',response.data); // HTML5 feature - overides 'src' attribute when supported by the browser
126+
frame.attr('src',response.request.url);
123127
} else {
124128
frame.css('display','none');
125-
frame.attr('srcdoc','');
126-
frame.attr('src','about:blank');
129+
frame.removeAttr('srcdoc');
130+
frame.removeAttr('src')
127131
}
128132

129133
},

0 commit comments

Comments
 (0)