vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
1.97k stars 293 forks source link

Polygon clicks not working for "type":"MultiPolygon" countries #156

Open rajeshthomasp opened 1 year ago

rajeshthomasp commented 1 year ago

I have tried using the https://globe.gl/example/choropleth-countries/ and I tried to show some information while clicking on the countries. But while I use 'onPolygonClick' , it is not working for some countries in which the "type":"MultiPolygon" in the json.

Can you please check and let me know. test.txt

vasturiano commented 1 year ago

@rajeshthomasp thanks for reaching out.

I looked briefly at your code, and I believe the onPolygonClick is working fine. The issue is in your code where you extract the country's central coords here:

const middleIndex = Math.floor(
  clickD.geometry.coordinates[0].length / 2
)
const middleElement = clickD.geometry.coordinates[0][middleIndex]

MultiPolygon geometries have an additional array in the coordinates, one for each polygon, so your code should account for that.

rajeshthomasp commented 1 year ago

@vasturiano Thank you for your reply. I will check and for the multipolygon, I will change the coordinates. Thanks for your fast reply.