Adding a filter

783
4
Jump to solution
10-10-2018 08:01 PM
ErinnHasselgren
New Contributor

Hi there,

What is the best way to add filter functionality (to limit a layer based on a particular attribute) to the MapViewer template? I found a few things in the Qt documentation, but I'm pretty new to development and was wondering if you have any suggestions or recommendations for how to accomplish this.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
ErwinSoekianto
Esri Regular Contributor

Erinn, 

I see, now I understand a little bit more about what you are looking for. 

I have a different idea, that I think might be better and more make-sense. Are you using the "Graticules" panel? If you are not using the Graticules panel, we can re-purpose the panel to this, you can change the wording "Graticules" to Filter, and then the option in the Graticules panel from "None", "Lat/Long Grid", etc to "Beaches", "Boat Ramps", etc. 

And then when the user picks "Beaches", it would perform the filter instead of adding the Grid. 

What do you think? 

The content of Graticules panel can be found in MapViewer/views/GraticulesView.qml, the list of Grid can be modified in the model "mapView.gridListModel", and then the functionality that you need to change from assigning grid to mapView to do the custom filter would be at MapPage.qml around line ~2060

mapView.grid = ArcGISRuntimeEnvironment.createObject(currentItem.gridObject, {labelPosition: Enums.GridLabelPositionAllSides})

I hope this is helpful,

Erwin. 

View solution in original post

0 Kudos
4 Replies
ErwinSoekianto
Esri Regular Contributor

Errin, 

Can you be little more specific on where do you want to add the filter functionality? Screenshots would be helpful. 

And then hopefully we could point you to the specific qml file and component that you need to add the code to. 

Erwin

0 Kudos
ErinnHasselgren
New Contributor

Hi Erwin!

I'm looking to I'm actually not too picky about where this appears in the app--whatever the easiest option is. I was considering was adding the two filter options to the hamburger button on the top left. In this case, the two filters would appear under the About the App selection. I also thought about adding a button along the top bar that would open a drop down menu with the two filter options, but I think this might be beyond my skill level. Again, I don't feel strongly about where this appears, I'm mostly looking for the easiest and most logical place to add this functionality.

For reference, there are two columns in the the attribute table of my data that I would like to be able to filter on. Both are populated with only YES or NO. I'm hoping to create one option for beaches, where the map only displays sites where there's a YES in the beaches column. The other filter will be boat ramps, with the same logic applied.

We also considered using the gallery in order to accomplish showing all three variations (all sites, beaches, and boat ramps), but we don't think that will be as user friendly for our end-users.

Thanks!

-Erinn

Filter placement 1

Filter placement 2

Attribute table columns for filter

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Erinn, 

I see, now I understand a little bit more about what you are looking for. 

I have a different idea, that I think might be better and more make-sense. Are you using the "Graticules" panel? If you are not using the Graticules panel, we can re-purpose the panel to this, you can change the wording "Graticules" to Filter, and then the option in the Graticules panel from "None", "Lat/Long Grid", etc to "Beaches", "Boat Ramps", etc. 

And then when the user picks "Beaches", it would perform the filter instead of adding the Grid. 

What do you think? 

The content of Graticules panel can be found in MapViewer/views/GraticulesView.qml, the list of Grid can be modified in the model "mapView.gridListModel", and then the functionality that you need to change from assigning grid to mapView to do the custom filter would be at MapPage.qml around line ~2060

mapView.grid = ArcGISRuntimeEnvironment.createObject(currentItem.gridObject, {labelPosition: Enums.GridLabelPositionAllSides})

I hope this is helpful,

Erwin. 

0 Kudos
ErinnHasselgren
New Contributor

Hi Erwin, 

Thank you so much--this was so helpful and exactly what I was looking for! I do have an additional question. As you mentioned above, I need to modify the gridListModel in order to make the filter work. I think I need to use the FeatureQueryResult Class, since I would like the map to display any features where the beaches column = YES when the filter is selected. Does this sound right? Would it be possible to point me to any examples? 

Thanks,

Erinn

0 Kudos