WAB Chart Widget - Change spatial selection method

708
2
Jump to solution
10-26-2016 08:37 AM
EoghanMcCarthy1
New Contributor II

Is it possible to change how the WAB Chart widget selects features when using the spatial filter? Currently it selects features based on a simple intersect - this is fine for point data but not for polygon features.

Is it possible to change the configuration so the spatial filter is based on a 'within' query rather than 'intersect'? 

Can someone point me to where I might change this? 

Many Thanks

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Eoghan,

   In the Chart widgets Widget.js find the _query function and make this edit (line 14):

      _query: function(where, outFields, /*optional*/ geometry){
        var def = new Deferred();
        var queryParams = new EsriQuery();
        if(!where){
          where = "1=1";
        }
        queryParams.where = where;
        if(geometry){
          queryParams.geometry = geometry;
        }
        queryParams.outSpatialReference = this.map.spatialReference;
        queryParams.returnGeometry = true;
        queryParams.outFields = outFields;
        queryParams.spatialRelationship = EsriQuery.SPATIAL_REL_CONTAINS;
        var url = this.currentAttrs.config.url;
        var queryTask = new QueryTask(url);
        queryTask.execute(queryParams).then(lang.hitch(this, function(featureSet){
          def.resolve(featureSet);
        }), lang.hitch(this, function(err){
          //maybe a joined layer
          if(err && err.code === 400){
            queryParams.outFields = ["*"];
            var queryTask2 = new QueryTask(url);
            queryTask2.execute(queryParams).then(lang.hitch(this, function(featureSet2){
              def.resolve(featureSet2);
            }), lang.hitch(this, function(err2){
              def.reject(err2);
            }));
          }else{
            def.reject(err);
          }
        }));
        return def;
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Eoghan,

   In the Chart widgets Widget.js find the _query function and make this edit (line 14):

      _query: function(where, outFields, /*optional*/ geometry){
        var def = new Deferred();
        var queryParams = new EsriQuery();
        if(!where){
          where = "1=1";
        }
        queryParams.where = where;
        if(geometry){
          queryParams.geometry = geometry;
        }
        queryParams.outSpatialReference = this.map.spatialReference;
        queryParams.returnGeometry = true;
        queryParams.outFields = outFields;
        queryParams.spatialRelationship = EsriQuery.SPATIAL_REL_CONTAINS;
        var url = this.currentAttrs.config.url;
        var queryTask = new QueryTask(url);
        queryTask.execute(queryParams).then(lang.hitch(this, function(featureSet){
          def.resolve(featureSet);
        }), lang.hitch(this, function(err){
          //maybe a joined layer
          if(err && err.code === 400){
            queryParams.outFields = ["*"];
            var queryTask2 = new QueryTask(url);
            queryTask2.execute(queryParams).then(lang.hitch(this, function(featureSet2){
              def.resolve(featureSet2);
            }), lang.hitch(this, function(err2){
              def.reject(err2);
            }));
          }else{
            def.reject(err);
          }
        }));
        return def;
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
EoghanMcCarthy1
New Contributor II

Thank you,

Much appreciated again Robert. 

0 Kudos