Search code examples
webglopenlayersmapbox-gl-jsmvt

How to get features in openlayers with mapbox?


I try to do it but it doesn't work, below is my main code.

enter image description here

enter image description here


Solution

  • You need to query the features on the Mapbox map

    map.on('click', (e) => {
      const point = new mapboxgl.Point(e.pixel[0], e.pixel[1]);
      const features = mbMap.queryRenderedFeatures(point);
      console.log(features);
    });
    

    https://codesandbox.io/s/mapbox-layer-forked-x8mocy?file=/main.js