Selecting Features from DataSource

925
9
Jump to solution
02-09-2024 05:09 PM
Labels (2)
PartyPelican
New Contributor III

Hello!

I am trying to create a widget that can select multiple layers based on a click event and show them in a series of tabs with a feature widget inside, however, I am new to development in experience builder. Currently I establish a click event listener on the map view and when the view is clicked, I query each FeatureLayerDataSource that is saved in state. I want to be able to select those results on the map but when I use datasource.selectRecordsByIds() with the object ids of the results, I dont see any highlighting on the map, and it appears as though my component renders twice. Its not clear to me why but you can see in the console that the tabs for each datasource gets rendered twice upon the click. This only happens when I use that selectRecordsByIds() method. Does anyone have any advice on how I can fix this or what I can do to make this work properly?

I appreciate any feedback, thank you.

PartyPelican_0-1707527257062.png

 

 

2 Solutions

Accepted Solutions
PartyPelican
New Contributor III

I was on the right track with the selectRecordsByIds() method, I just forgot to pass in the array of records to select from as the second parameter. Once I did that, the feature was highlighted in the map. 

 

PartyPelican_0-1707958801549.png

 

View solution in original post

0 Kudos
PartyPelican
New Contributor III

If anyone is interested, I have attached the working widget. I am still developing it and will share it again once I have made more improvements. Feel free to refactor the code and suggest ways to make it better. 

Currently, you can supply it layers to select from on a mouse click (the mouse click uses a 10 ft buffer). The selection is applied to the data source so the selection can be seen by other widgets like the table widget. 

 

Update:

I did some refactoring and added the option to change the buffer radius and units.

View solution in original post

9 Replies
FredericPoliart_EsriAU
Occasional Contributor II

 you share the src code in a .zip ? 

 

0 Kudos
JeffreyThompson2
MVP Regular Contributor

I am working on the same widget concept right now. Most of the work is done and I should be ready to release on here in a few days. Here is a preview.

JeffreyThompson2_0-1707745530149.png

 

GIS Developer
City of Arlington, Texas
PartyPelican
New Contributor III

Awesome! do you mind sharing a snippet of how you went about querying and selecting the records? Eventually, I'd like to incorporate querying the related tables of a layer as well. 

JeffreyThompson2
MVP Regular Contributor

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#fetchFeatures

It's based around the popup.fetchFeatures() method. The earliest version of my widget was based on this sample, but I think they have re-written some of it since I copied it.

GIS Developer
City of Arlington, Texas
0 Kudos
PartyPelican
New Contributor III

I was on the right track with the selectRecordsByIds() method, I just forgot to pass in the array of records to select from as the second parameter. Once I did that, the feature was highlighted in the map. 

 

PartyPelican_0-1707958801549.png

 

0 Kudos
PartyPelican
New Contributor III

If anyone is interested, I have attached the working widget. I am still developing it and will share it again once I have made more improvements. Feel free to refactor the code and suggest ways to make it better. 

Currently, you can supply it layers to select from on a mouse click (the mouse click uses a 10 ft buffer). The selection is applied to the data source so the selection can be seen by other widgets like the table widget. 

 

Update:

I did some refactoring and added the option to change the buffer radius and units.

RachappaBellappa1
New Contributor III

Hello I am in the same boat, although selected features show the number of records selected but features are not selected in the map. I see the url's are updated with features. If i refresh the url then it shows selected features. Please check the code snippet.

RachappaBellappa1_0-1710953231366.png

Any thoughts

 

 

0 Kudos
PartyPelican
New Contributor III

Can you share your code please? 

0 Kudos
RachappaBellappa1
New Contributor III

Please check the screenshot above, i have a JSON object and i am binding that to featuredatalayersource by passing objectids. In Network i can see it's doing query call and also in select widget it shows selected features count but features are not highlighted

0 Kudos