From e488f033b57a5d66a26b2aa8a78dcc7362b9e4eb Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 17 Jul 2013 17:37:45 +0200 Subject: [PATCH 1/6] Instead of pinging a lazy source, try it and remove layers if it fails --- src/script/plugins/WMSSource.js | 55 +++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/script/plugins/WMSSource.js b/src/script/plugins/WMSSource.js index 3ca9ee22..4c16a35f 100644 --- a/src/script/plugins/WMSSource.js +++ b/src/script/plugins/WMSSource.js @@ -361,28 +361,8 @@ 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.fireEvent("ready", this); } }, @@ -442,13 +422,40 @@ 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); + this.fireEvent('failure', this, 'Layer unavailable', 'Could not load ' + evt.object.name); + } + 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. From 017427ba20078dc5d30e47351d7aab5d6cb06d13 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 18 Jul 2013 10:44:05 +0200 Subject: [PATCH 2/6] Latest from submodules --- externals/geoext | 2 +- externals/openlayers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/externals/geoext b/externals/geoext index 3df35b1d..cb6f51a7 160000 --- a/externals/geoext +++ b/externals/geoext @@ -1 +1 @@ -Subproject commit 3df35b1ddaed9aab8e1ccc76bf7fa35b83b6a865 +Subproject commit cb6f51a79e22b7b5b698f23e1d86254bb35ddf18 diff --git a/externals/openlayers b/externals/openlayers index cc6dbd4b..10e922b4 160000 --- a/externals/openlayers +++ b/externals/openlayers @@ -1 +1 @@ -Subproject commit cc6dbd4b7ac5e6c3805894b4e730d098a80676b0 +Subproject commit 10e922b46798749f4c6fc17a397189fde1d2e8de From eef708d1f306a0c07dbd9acc6df9a9c69190f10e Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 18 Jul 2013 10:58:04 +0200 Subject: [PATCH 3/6] Do not mark source unavailable when a layer fails --- src/script/plugins/WMSSource.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/script/plugins/WMSSource.js b/src/script/plugins/WMSSource.js index 4c16a35f..251c0321 100644 --- a/src/script/plugins/WMSSource.js +++ b/src/script/plugins/WMSSource.js @@ -451,7 +451,9 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, { }); if (evt.object.metadata._alive === 0) { this.target.mapPanel.map.removeLayer(evt.object); - this.fireEvent('failure', this, 'Layer unavailable', 'Could not load ' + evt.object.name); + window.setTimeout(function() { + throw new Error('Unavailable layer ' + evt.object.name + ' removed.'); + }, 0); } delete evt.object.metadata.alive_; }, From e698bd100aa99ab1d64d47b00a7d8b1e0f8fa7c0 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 18 Jul 2013 12:24:17 +0200 Subject: [PATCH 4/6] Setting ready when firing ready event --- src/script/plugins/WMSSource.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/plugins/WMSSource.js b/src/script/plugins/WMSSource.js index 251c0321..94913b60 100644 --- a/src/script/plugins/WMSSource.js +++ b/src/script/plugins/WMSSource.js @@ -362,6 +362,7 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, { }); if (lazy) { this.lazy = lazy; + this.ready = true; this.fireEvent("ready", this); } }, From 00ec9f8161efc9d4294b45c35e46f3ee0d9ef608 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 18 Jul 2013 12:32:15 +0200 Subject: [PATCH 5/6] Don't throw on non fatal incidents --- src/script/plugins/WMSSource.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script/plugins/WMSSource.js b/src/script/plugins/WMSSource.js index 94913b60..dd2494c7 100644 --- a/src/script/plugins/WMSSource.js +++ b/src/script/plugins/WMSSource.js @@ -452,9 +452,9 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, { }); if (evt.object.metadata._alive === 0) { this.target.mapPanel.map.removeLayer(evt.object); - window.setTimeout(function() { - throw new Error('Unavailable layer ' + evt.object.name + ' removed.'); - }, 0); + if (window.console) { + console.debug('Unavailable layer ' + evt.object.name + ' removed.'); + } } delete evt.object.metadata.alive_; }, From 285070efce4d2cbe8e418f93a272e9b773d64c36 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 18 Jul 2013 12:52:57 +0200 Subject: [PATCH 6/6] It's _alive, not alive_ --- src/script/plugins/WMSSource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/plugins/WMSSource.js b/src/script/plugins/WMSSource.js index dd2494c7..94aa7850 100644 --- a/src/script/plugins/WMSSource.js +++ b/src/script/plugins/WMSSource.js @@ -456,7 +456,7 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, { console.debug('Unavailable layer ' + evt.object.name + ' removed.'); } } - delete evt.object.metadata.alive_; + delete evt.object.metadata._alive; }, /** api: method[createLayerRecord]