Skip to content

Commit

Permalink
Merge pull request #204 from ahocevar/lazy-no-ping
Browse files Browse the repository at this point in the history
Instead of pinging a lazy source, try it and remove layers if it fails
  • Loading branch information
ahocevar committed Jul 18, 2013
2 parents 0a506f3 + 285070e commit df41c90
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion externals/geoext
Submodule geoext updated from 3df35b to cb6f51
58 changes: 34 additions & 24 deletions src/script/plugins/WMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,28 +361,9 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
}
});
if (lazy) {
this.lazy = true;
// ping server of lazy source with an incomplete request, to see if
// it is available
Ext.Ajax.request({
method: "GET",
url: this.url,
params: {SERVICE: "WMS"},
callback: function(options, success, response) {
var status = response.status;
// responseText should not be empty (OGCException)
if (status >= 200 && status < 403 && response.responseText) {
this.ready = true;
this.fireEvent("ready", this);
} else {
this.fireEvent("failure", this,
"Layer source not available.",
"Unable to contact WMS service."
);
}
},
scope: this
});
this.lazy = lazy;
this.ready = true;
this.fireEvent("ready", this);
}
},

Expand Down Expand Up @@ -442,13 +423,42 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
cql_filter: config.cql_filter,
format: config.format
}, {
projection: srs
projection: srs,
eventListeners: {
tileloaded: this.countAlive,
tileerror: this.countAlive,
scope: this
}
}
));
record.json = config;
return record;
},


countAlive: function(evt) {
if (!('_alive' in evt.object.metadata)) {
evt.object.metadata._alive = 0;
evt.object.events.register('loadend', this, this.removeDeadLayer);
}
evt.object.metadata._alive += (evt.type == 'tileerror' ? -1 : 1);
},

removeDeadLayer: function(evt) {
evt.object.events.un({
'tileloaded': this.countAlive,
'tileerror': this.countAlive,
'loadend': this.removeDeadLayer,
scope: this
});
if (evt.object.metadata._alive === 0) {
this.target.mapPanel.map.removeLayer(evt.object);
if (window.console) {
console.debug('Unavailable layer ' + evt.object.name + ' removed.');
}
}
delete evt.object.metadata._alive;
},

/** api: method[createLayerRecord]
* :arg config: ``Object`` The application config for this layer.
* :returns: ``GeoExt.data.LayerRecord`` or null when the source is lazy.
Expand Down

0 comments on commit df41c90

Please sign in to comment.