Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous use of pointsData() wipes labels set via labelsData() #52

Closed
snshn opened this issue Jun 21, 2021 · 2 comments
Closed

Continuous use of pointsData() wipes labels set via labelsData() #52

snshn opened this issue Jun 21, 2021 · 2 comments

Comments

@snshn
Copy link
Contributor

snshn commented Jun 21, 2021

Describe the bug
Calling .pointsData() on an already rendered globe causes it to lose its labels previously set via .labelsData().

To Reproduce
Steps to reproduce the behavior:
1.

<head>
  <script src="//unpkg.com/globe.gl"></script>
</head>
<body style="margin:0">
  <div id="viewport"></div>
</body>
// Gen random data
const N = 300;
const gData = [...Array(N).keys()].map(() => ({
  lat: (Math.random() - 0.5) * 180,
  lng: (Math.random() - 0.5) * 360,
  size: Math.random() / 3,
  color: ['red', 'white', 'blue', 'green'][Math.round(Math.random() * 3)]
}));

const globe = Globe()
  .globeImageUrl('//unpkg.com/three-globe/example/img/earth-night.jpg')
  .pointsData(gData)
  .labelsData(gData)
  .labelText(() => "Text")
  .labelSize(2)
  .pointAltitude('size')
  .pointColor('color')
  (document.getElementById('viewport'));

setTimeout(() => {
  globe.pointsData(gData);
  // globe.labelsData(gData);
}, 5000);

Expected behavior
Labels should not disappear.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: N/A
  • Browser: N/A
  • Version: N/A

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context
Calling .labelsData() right after .pointsData() seems to be bringing back labels and render them again after a second or two, but it's definitely a bug that points data interferes with labels data.

@vasturiano
Copy link
Owner

@snshn thanks for reaching out.

The real issue is the sharing of data objects between layers. Each layer will associate some meta attributes to the data arrays passed onto it, and these are required for proper functioning. If you pass the exact same object reference to multiple layers it is very possible that they will conflict, and doing this is disadvised.

You can simply solve this by cloning the data structure, for instance:

const labelData = gData.map(d => Object.assign({}, d));

@snshn
Copy link
Contributor Author

snshn commented Jun 23, 2021

@vasturiano

that makes sense, thank you for the explanation and code snippet. I assumed the supplied data was cloned internally by default.

@snshn snshn closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants