visgl / react-map-gl

React friendly API wrapper around MapboxGL JS
http://visgl.github.io/react-map-gl/
Other
7.88k stars 1.35k forks source link

[Bug] Clustering example - onClick returning undefined #2096

Open JamesLeBoeuf opened 1 year ago

JamesLeBoeuf commented 1 year ago

Description

The clustering example onClick function is returning undefined when clicking outside of clusters and on empty map space.

Expected Behavior

OnClick function to not return undefined.

Steps to Reproduce

  1. Go to react-map-gl clustering example: http://visgl.github.io/react-map-gl/examples/clusters
  2. Open up console
  3. Click on a specific point or any empty map space
  4. Notice error in console

Environment

Logs

Uncaught TypeError: Cannot read properties of undefined (reading 'properties') at onClick (component---examples-clusters-src-app-tsx-ae435c98aa31b91df409.js:1:1591) at Map._onPointerEvent (834b8338ea35f2c3d17eb82aef29032efb222d04-d473b88aba9c068a3050.js:1:20732) at Map.fire (27-9fafbe3fd9a64912bea8.js:1:18842) at t._fireEvent (834b8338ea35f2c3d17eb82aef29032efb222d04-d473b88aba9c068a3050.js:1:25834) at Qr.click (27-9fafbe3fd9a64912bea8.js:1:813462) at Rn.handleEvent (27-9fafbe3fd9a64912bea8.js:1:838674)

kamami commented 11 months ago

Is there any news about this? One year passed and it is still an issue I am facing.

lswainemoore commented 9 months ago

The issue is that the event.features should be checked before indexing here.

FWIW changing that alone would prevent the error, but would leave the example short of reproducing the example here, which is the stated intention. To do that, we'd need to add the other layers in interactiveLayerIds, and actually create the popup.