How to hide points that are NOT selected from a Query Task?

1265
4
07-21-2016 02:26 PM
GeoffreyWest
Occasional Contributor III

I have an application with a query task that I configured with AGOL WebAppBuilder.  I have a simple CONTAINS query that selects all features that contain a certain value of an attribute.  How can I adjust the JS so that the features which are NOT selected are not shown when I the query is executed? Is this possible/practical using WebAppBuilder

0 Kudos
4 Replies
ChenLi2
New Contributor III

hi Geoffrey,

First, i think you will need to use Web app builder developer edition, which is easier for customizing purpose.

And if you have developer version, you can actually modify the widget.js file inside the widgets\Query folder.

I think there might be several steps to achieve it:

1. you could find where it is getting the response of the query, then you can get all the selected features from response.features.

2. you could build an array of the objectids from all the response.features.

3. then setDefinitionEXpression based on the objectids, for example:

this.map.itemInfo.itemData.operationalLayers[0].layerObject.setDefinitionExpression("objectid=1 or objectid =2");

There might be other tons of better ways to do that though.

Thanks

Chen

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Geoffery,

  One option is to get the eSearch widget and configure the widget for that layer and make sure that layer is not part of your map. The eSearch does not require the searched layer to be part of the map and thus the result graphics will only be those that match the search criteria.

GeoffreyWest
Occasional Contributor III

Robert,

I don't quite understand.  I am executing the search against a layer that is a part of the map.  I am familiar with the search widget, however, not the ​e​Search widget.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Geoffrey,

  There are several custom widgets out there for users of WAB Dev edition. The eSearch is one of them. If you have a web map that already has the layer as part of the map then your only options are to do as Chen suggests or add the eSearch and turn off that layer in the map that way the results of the eSearch will only show the searched results on the map.

Enhanced Search Widget Version 2.1 - 07/22/16

0 Kudos