Click events on GeoJSON layer: How to access properties from click events?

2690
3
Jump to solution
05-03-2020 10:06 AM
KevinCheriyan
Occasional Contributor

Hi everyone, 

I have a GeoJSON layer that I have added to my webmap. I want to be able to click on the layer features and populate a sidepanel with elements based on the feature's properties (make request to db from app with Express query, populate sidepanel with returned array). How can I access the GeoJSON layer's properties for the feature that is being clicked? I looked at hitTest(), a MapView method. But surprised to see that GeoJSON is not a supported type of layer for the method. 

Does anyone have any ideas on how I could achieve this? I'm able to access the properties on the popupTemplate fine. But I need more features than what the popupTemplate is giving me.

TLDR: Need to access GeoJSON properties from clicking element on map. 

Thanks!


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

Looks like it's just an omission in the docs. hitTest works with GeoJSONLayer.

Here is a demo.

View solution in original post

3 Replies
ReneRubalcava
Frequent Contributor

Looks like it's just an omission in the docs. hitTest works with GeoJSONLayer.

Here is a demo.

KevinCheriyan
Occasional Contributor

Thanks, Rene! Wish I'd given it a try before I switched my entire application to render Feature Layer instead.

Now I'm facing a problem where client-side graphics added to the feature layer cannot recognize click events for hitTest() or popupTemplate.

I believe this is a bug that was recognized in the API a couple of years ago, but still hasn't been fixed. See view.hitTest returning 0 results and PopupTemplate from Client Side Graphics Not Working 


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
ReneRubalcava
Frequent Contributor

I'm not sure.

This sample works with popups.

I tried with hitTest and it works.