Hello, I was wondering what would be the best way to adapt the query features from FeatureLayerView as seen in Query features from a FeatureLayerView | ArcGIS API for JavaScript 4.12 so that the list on the right simply includes all features rather than just the ones within the view extent. I would like to keep all other parts to this function (zoom to feature when clicked, popup box..), but I just want to make it so all features are displayed on the list, and the list does not change when a feature is clicked then zoomed to.
Thanks!
Hi Ben,
You can also query all features from the featurelayer when the layer loads, which will guarantee that you will get all features in the layer. Though if you have thousands of features, this will affect the app performance. This codepen shows querying features from the layer: https://codepen.io/U_B_U/pen/XWrgWeR?&editable=true&editors=100
In regards to list updating, the app is currently watching for layerView.updating property so that the list will update when the user moves into a different view. If you wanted to query on the layerView, you could use the following method: watchUtils.whenFalseOnce(layerView, "updating", function(){ ... } which would run the logic only once when the app loads (this is commented out in the codepen). Hope this helps!
Thanks,
Anne
Hello Anne, something else has come up since following this method. While my original issue has been resolved (the list continuing to show all available layers - thank you again!), I noticed that the feature itself is no longer "selected" after clicking on one of the items on the populated list. The original code in the Query features from a FeatureLayerView automatically "selects" the feature once an item on the list is clicked. This became an issue because I have since included a "Download Data" button to the pop-up for users to be able to download a zipped GeoTiff of the layer they are viewing, but the Download button does not work unless the feature in question is actually selected.
Long story short, what is the best way to tweak this adapted code so that the feature which is being zoomed to is ALSO automatically selected?
As reference, this is the code I wrote to allow for the downloading of the data. It simply is meant to open the URL (found in the feature's attribute table) of the zipped raster.
view.when(function() { var popup = view.popup; popup.viewModel.on("trigger-action", function(event) { if (event.action.id === "download-dem") { var attributes = popup.viewModel.selectedFeature.attributes; // Get the 'website' field attribute var info = attributes.Download; // Make sure the 'website' field value is not null if (info) { // Open up a new browser using the URL value in the 'website' field window.open(info); } } });});
Awesome, thank you both for your help! That seems to be doing the trick.
Ben,
The FeatureLayerView queryFeatures method states:
Executes a Query against features available for drawing in the layer view and returns a FeatureSet.
If you want all feature that the layer has then you need to query the actual layer and not use the layer view.
Thank you for the response. I have actually tried that (both in my own JS code and in the Arc sandbox), but when I zoom to other features the list on the right still updates to reflect only the features that are in the current view extent. My hope is that the list stays constant with all features, even when I zoom to specific features.
To include all features, remove geometry: view.extent from the parameters of layerView.queryFeatures, then it should show all features instead of just the ones in the view.
layerView.queryFeatures({ geometry: view.extent, returnGeometry: true }).then(function(results) { ... });
See FeatureLayerView.queryFeatures() and Query for more information on creating client-side queries. Hope this helps!
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.