-1

I have this code below:

 evt.target.forEachFeatureAtPixel(
    evt.pixel,
    (feature, layer) => {
  });

when I click on a feature it returns me array of features like

features: Array(1)
0: Feature {disposed: false, eventTarget_: undefined, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, …}

but I want to identity a specific feature where I click.

is it possible?

user10496245
  • 217
  • 3
  • 17

1 Answers1

0

you will always get an array. If there is only one feature at this pixel the array will have the count of 1. And if there are multiple features you have to identify the one you want to acces by any special attribute or id you gave the feature before you added it to the map.

for example

    const array1 = [5, 12, 8, 130, 44];

    const found = array1.find(element => element > 10);
    
    console.log(found);
Sebastian
  • 315
  • 1
  • 10