Filter widget: zoom to features

3480
24
Jump to solution
10-13-2016 08:36 AM
helenchu
Occasional Contributor II

Can I have the filter widget zoom to features ?   Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Helen,

   OK so I found the difference between your data and mine that I was testing. Mine was using wkid 102100 like the maps wkid.

So make this change (line 6):

//Add RJS Now zoom to the results
      var qt = QueryTask(layerInfo.getUrl());
      var q = Query();
      q.returnGeometry = true;
      q.where = layerFilterExpr;
      q.outSpatialReference = this.map.spatialReference;
      qt.execute(q, lang.hitch(this, function(fs){
          this.map.setExtent(graphicsUtils.graphicsExtent(fs.features), true);
      }));
//End RJS‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

24 Replies
RobertScheitlin__GISP
MVP Emeritus

Helen,

   This has been MINIMALLY tested:

Widget.js

define([
    'dojo/_base/declare',
    'dojo/_base/array',
    'dojo/_base/html',
    'dojo/_base/lang',
    'dojo/query',
    'dojo/on',
    'dijit/_WidgetsInTemplateMixin',
    'jimu/BaseWidget',
    'jimu/filterUtils',
    'jimu/dijit/FilterParameters',
    'jimu/LayerInfos/LayerInfos',
    'jimu/FilterManager',
    'esri/request',
//Add RJS
    'esri/tasks/QueryTask',
    'esri/tasks/query',
    'esri/graphicsUtils',
//end RJS
    'dojo/NodeList',
    'dojo/NodeList-dom'
  ],
  function(declare, array, html, lang, query, on,
    _WidgetsInTemplateMixin,
    BaseWidget, FilterUtils, FilterParameters, LayerInfos, FilterManager,
    esriRequest, QueryTask, Query, graphicsUtils) { //Added , QueryTask, Query, graphicsUtils

    return declare([BaseWidget, _WidgetsInTemplateMixin], {

      applyFilterValues: function(node, filterObj, evt) {
        var expr = node.filterParams && (node.expr || node.filterParams.getFilterExpr());
        if (expr) {
          node.expr = expr;
          // getFilterExpr
          var layerId = filterObj.layerId;
          var idx = html.getAttr(node, 'data-index');
          var layerInfo = this.layerInfosObj.getLayerInfoById(layerId);
          if (layerInfo.isShowInMap() && layerInfo.isInScale()) {
            this._bindMapUpdateEvents(node, true);
          } else {
            html.addClass(node, 'applied');
          }
          this._setItemFilter(layerId, idx, node.expr);
          var layerFilterExpr = this._getExpr(layerId);
          this.filterManager.applyWidgetFilter(layerId, this.id, layerFilterExpr);
//Add RJS Now zoom to the results         
          var qt = QueryTask(layerInfo.getUrl());
          var q = Query();
          q.returnGeometry = true;
          q.where = layerFilterExpr;
          qt.execute(q, lang.hitch(this, function(fs){
            this.map.setExtent(graphicsUtils.graphicsExtent(fs.features), true);
          }));
//End RJS          
        }
        evt.stopPropagation();
      },
helenchu
Occasional Contributor II

It doesn't work on my end.  No error, just not zoom to the desired extent.  I tested on all different browsers,  same results.  

I debugged but I guess I don't know enough to see anything wrong with the codes.  Attached is the screen shot. The number of features returned is correct.  Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   I just tested the code again and it zoomed for me after the filter was applied. Maybe you should attach your filter widget with your changes for me to look at.

0 Kudos
helenchu
Occasional Contributor II

Strange!  I created new clean app with filter widget, tested with different layers, did text compare: identical

Attached is my widget.js.  Much appreciated!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   I took your code and overwrote mine with it and it worked for me using my data a filter expression. So it has to be something with your expression or data then. Can you provide your config_Filter.json file for me to look at?

0 Kudos
helenchu
Occasional Contributor II

Here it is.  Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

   What is the geometry type of this layer?

0 Kudos
helenchu
Occasional Contributor II

It's polygon feature layer.  I tested with the point feature layer too.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

That is so strange as I tested with a polygon layer as well. Is there a filter expression you can try that returns less results (your earlier was returning 218 polygons).

0 Kudos