Skip to content

Commit

Permalink
street-label cleanup
Browse files Browse the repository at this point in the history
fix binding

I have to keep this in or it raises an error `Cannot read properties of undefined (reading 'width')`. My guess is there is a race condition such that when the scene is loaded the dom attribute is added but the a-frame component hasn't been initialized thus the segment is returned as matching the querySelector but not from a-frame getattribute? I changed the logic a bit to check if the street-segment component exist and to also return if no width for a segment:
```
      const segmentWidth = segmentEl.getAttribute('street-segment')?.width;
      if (!segmentWidth) return;
```
  • Loading branch information
kfarr committed Jan 9, 2025
1 parent 2e90f1d commit de662b8
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/components/street-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ AFRAME.registerComponent('street-label', {
// Create and setup canvas
this.createAndSetupCanvas();

// Listen for segment changes
this.el.addEventListener('segments-changed', this.updateLabels.bind(this));

// Listen for alignment changes
this.el.addEventListener('alignment-changed', this.updateLabels.bind(this));

// Initial update
this.updateLabels();
// Listen for segment & alignment changes
this.updateLabels = this.updateLabels.bind(this);
this.el.addEventListener('segments-changed', this.updateLabels);
this.el.addEventListener('alignment-changed', this.updateLabels);

// Handle loading from saved scene
setTimeout(() => {
Expand Down Expand Up @@ -64,9 +60,9 @@ AFRAME.registerComponent('street-label', {
const labelsArray = [];

segments.forEach((segmentEl) => {
if (!segmentEl.getAttribute('street-segment')) return;
const segmentWidth = segmentEl.getAttribute('street-segment')?.width;
if (!segmentWidth) return;

const segmentWidth = segmentEl.getAttribute('street-segment').width;
widthsArray.push(segmentWidth);
labelsArray.push(segmentEl.getAttribute('data-layer-name') || '');
});
Expand Down

0 comments on commit de662b8

Please sign in to comment.