Skip to content

Commit

Permalink
Use debouncing instead of aborting.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonseyock committed Jun 14, 2021
1 parent 9d955f5 commit 254be2a
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions src/data/store/WfsFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,20 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
cacheFeatureCount: false,

/**
* The outputFormat sent with the resultType=hits request.
* Defaults to GML3 as some WFS servers do not support this
* request type when using application/json.
* Only has an effect if #cacheFeatureCount is set to `true`
* @cfg {Boolean}
*/
* The outputFormat sent with the resultType=hits request.
* Defaults to GML3 as some WFS servers do not support this
* request type when using application/json.
* Only has an effect if #cacheFeatureCount is set to `true`
* @cfg {Boolean}
*/
featureCountOutputFormat: 'gml3',

/**
* Any currently executing request to the WFS server.
* A reference to this is kept so any new requests can
* abort the previous request to ensure only the most recently
* requested results are returned.
* @cfg {Ext.data.request.Ajax}
*/
activeRequest: null,
* Time any request gets debounced so there are not fired to
* many request at once.
* @cfg {number}
*/
debounce: 300,

/**
* Constructs the WFS feature store.
Expand All @@ -185,8 +183,7 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
if (config.pageSize > 0) {
// calculate initial page
var startIndex = config.startIndex || me.startIndex;
var currentPage = Math.floor(startIndex / config.pageSize) + 1;
config.currentPage = currentPage;
config.currentPage = Math.floor(startIndex / config.pageSize) + 1;
}

// avoid creation of vector layer by parent class (raises error when
Expand All @@ -197,6 +194,8 @@ Ext.define('GeoExt.data.store.WfsFeatures', {

me.callParent([config]);

me.loadWfsTask_ = new Ext.util.DelayedTask();

if (!me.url) {
Ext.raise('No URL given to WfsFeaturesStore');
}
Expand Down Expand Up @@ -317,13 +316,11 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
if (filters.length === 0) {
return null;
}
var wfsGetFeatureFilter = GeoExt.util.OGCFilter.
getOgcWfsFilterFromExtJsFilter(
filters,
me.logicalFilterCombinator,
me.version
);
return wfsGetFeatureFilter;
return GeoExt.util.OGCFilter.getOgcWfsFilterFromExtJsFilter(
filters,
me.logicalFilterCombinator,
me.version
);
},

/**
Expand Down Expand Up @@ -385,9 +382,18 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
loadWfs: function() {
var me = this;

if (me.activeRequest) {
me.activeRequest.abort();
if (me.loadWfsTask_.id === null) {
me.loadWfsTask_.delay(me.debounce, function() {});
me.loadWfsInternal();
} else {
me.loadWfsTask_.delay(me.debounce, function() {
me.loadWfsInternal();
});
}
},

loadWfsInternal: function() {
var me = this;

var url = me.url;
var params = {
Expand Down Expand Up @@ -432,9 +438,8 @@ Ext.define('GeoExt.data.store.WfsFeatures', {

// apply paging parameters if necessary
if (me.pageSize) {
var fromRecord =
((me.currentPage - 1) * me.pageSize) + me.startIndexOffset;
me.startIndex = fromRecord;
me.startIndex = ((me.currentPage - 1) * me.pageSize) +
me.startIndexOffset;
params.startIndex = me.startIndex;
params.count = me.pageSize;
}
Expand All @@ -446,15 +451,15 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
}

// request features from WFS
me.activeRequest = Ext.Ajax.request({
Ext.Ajax.request({
url: url,
method: me.requestMethod,
params: params,
success: function(resp) {

if (!me.format) {
Ext.Logger.warn('No format given for WfsFeatureStore. ' +
'Skip parsing feature data.');
'Skip parsing feature data.');
return;
}

Expand All @@ -474,7 +479,7 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
wfsFeats = me.format.readFeatures(resp.responseText);
} catch (error) {
Ext.Logger.warn('Error parsing features into the ' +
'OpenLayers format. Check the server response.');
'OpenLayers format. Check the server response.');
}

// set data for store
Expand All @@ -491,7 +496,7 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
failure: function(resp) {
if (resp.aborted !== true) {
Ext.Logger.warn('Error while requesting features from WFS: '
+ resp.responseText + ' Status: ' + resp.status);
+ resp.responseText + ' Status: ' + resp.status);
}
me.fireEvent('gx-wfsstoreload', me, null, false);
}
Expand All @@ -502,8 +507,8 @@ Ext.define('GeoExt.data.store.WfsFeatures', {
doDestroy: function() {
var me = this;

if (me.activeRequest) {
me.activeRequest.destroy();
if (me.loadWfsTask_.id !== null) {
me.loadWfsTask_.cancel();
}

me.callParent(arguments);
Expand Down

0 comments on commit 254be2a

Please sign in to comment.