Select to view content in your preferred language

Query On Click help

396
1
04-03-2024 07:15 AM
BenjaminMittler
Frequent Contributor

Hello, 

I am new to using Javascript and i'm trying to change this ESRI example to use a click event as input for the query rather than a view change. 

 

The code i've been working on can be found here:  https://codepen.io/bmittler/pen/jORYZOR 

I seem to be have issues with the for loop, im guess that data isnt being fed into the for loop correctly but im not sure why. 

 

Any help is appreciated.

 

Ben

0 Kudos
1 Reply
UndralBatsukh
Esri Regular Contributor

You are not waiting for the queryFeatures method to resolve to return the results. You can make the following changes to get your codepen working. Notice that I added async to the click event handler and await to the layerView.queryFeatures...

 

 reactiveUtils.on(
  () => view,  "click", async (event) => {
    console.log("Click event emitted: ", event);
    try {
      const featureSet = await layerView.queryFeatures({
        geometry: event.mapPoint,
        returnGeometry: true,
        orderByFields: ["GEOID"]
      });
     // rest of the code