Can I have the filter widget zoom to features ? Thanks.
Solved! Go to Solution.
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
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();
},
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.
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.
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?
Helen,
What is the geometry type of this layer?
It's polygon feature layer. I tested with the point feature layer too.
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).