ghettovoice / vuelayers

Web map Vue components with the power of OpenLayers
https://vuelayers.github.io/
MIT License
682 stars 230 forks source link

forEachFeatureAtPixel layerFilter not excute in right way #537

Closed erDuo10 closed 10 months ago

erDuo10 commented 11 months ago

image

onMapPointerMove(e) {
  let hitFeature = this.$refs.map.$map.forEachFeatureAtPixel(
    e.pixel,
    this.handleDemanderFeatureClick,
    { layerFilter: function(layer) {
        const id = layer.get("id");
        return id != undefined && id.startsWith('wells-status');
      }
    }
  )

  console.error('onMapPointerMove hitFeature:', hitFeature);
},
 handleDemanderFeatureClick(feature, layer ){
   console.error('handleDemanderFeatureClick feature:', feature);
   console.error('handleDemanderFeatureClick layer:', layer);

   return feature;
 },

as the code show, layerFilter do not implement filter use, the filter code could not trigger the callbak method handleDemanderFeatureClick.

after delete the filter, the onMapPointerMove trigger many a time

ghettovoice commented 11 months ago

Hello @erDuo10 ,

You should check layer id is correct, and is it "managed"(not added as overlay) layer, is it vector layer and etc. There is extended documentation https://openlayers.org/en/v6.15.1/apidoc/module-ol_Map-Map.html#forEachFeatureAtPixel, when call though this.$refs.map.$map.forEachFeatureAtPixel. There is also a demo https://jsfiddle.net/ghettovoice/Ln9qr135/460/

erDuo10 commented 11 months ago

Thank you! That helps a lot.

github-actions[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.