vasturiano / three-globe

WebGL Globe Data Visualization as a ThreeJS reusable 3D object
https://vasturiano.github.io/three-globe/example/links/
MIT License
1.2k stars 146 forks source link

Missing __threeObj in polygon callbacks #19

Open lslzl3000 opened 3 years ago

lslzl3000 commented 3 years ago

Describe the bug For all other layers, we can access d.__threeObj in property callbacks, but missing in polygon layer

Expected behavior Can access __threeObj in polygon property callbacks

lslzl3000 commented 3 years ago

I think the reason why you leave __threeObj empty in polygon, is that one data may contains more than one geometries/groups.

I think using an array to hold all geo groups is a good solution. e.g. add some lines in https://github.com/vasturiano/three-globe/blob/1c0d38901a5b9ccdd71113c68743440d30c1e91a/src/layers/polygons.js#L116

        obj.__globeObjType = 'polygon'; // Add object type
        if(!d.data.__threeObj)
          d.data.__threeObj = [obj]
        else
          d.data.__threeObj.push(obj)
vasturiano commented 3 years ago

@lslzl3000 yes, the reason why this internal attribute is not present in each polygon datum is because it's not a 1-1 relationship. A geojson item can be a single or multiple polygon, in which case it needs to be split across multiple three objects.

But also, this attribute is internal to the library and I wouldn't recommend relying on it to access and even less modify the associated three objects. What is your particular use case that you'd need to access the underlying three objects? And which specific callback methods are you referring to?

yd021976 commented 1 year ago

@vasturiano I think we need to access the associated three object because of customization/computing needs. For example, I would like to scale a Label depending on polygon (country) size (e.g with three boxHelper to get the "box" size of polygon). At this time, I can't do this as I can't get access to the associated three JS polygon object.

So you don't recommend users to use associated three object, but how can we customize globe behavior without accessing underlying three objects ?

vasturiano commented 1 year ago

@yd021976 you have access to the geojson object that you input per data point. From that geoJson you can extract the coordinates bounding box of the polygon. That might actually be an easier computation than getting it from the ThreeJS computed geometries.

As an aid to calculate the bounding box of a geoJson object you have d3-geo geoBounds for example.

yd021976 commented 1 year ago

Thank you for your help. You are right, I can re-use geojson data from my input array. I'm newbie in 3d, so I figured that I only should use three objects because they are drown on globe... I'll give a try to your way :-)