0

I am currently working on DataVizExtension, specifically on the sprites feature. I created an extension in the viewer that allows users to add and delete the sprites on the viewer itself. An error occurs each time I delete a sprite. The sprites' information is basically stored inside a Map in a file. Deleting the sprite means removing information about that sprite from that map. After that deletion is complete, I would refresh reload all the viewable with this function:

_refreshSprites() {
this._dataVizExt.removeAllViewables();
if (!this.dataView) {
  console.log("No data view available");
  return;
}
console.log("Data view available");
const viewableData = new Autodesk.DataVisualization.Core.ViewableData();
viewableData.spriteSize = 32;
this._dbIdToSensorId.clear();
let dbid = 1000000;
for (const [sensorId, sensor] of this.dataView.getSensors().entries()) {
  this._dbIdToSensorId.set(dbid, sensorId);
  const { x, y, z } = sensor.location;
  const style = this._style;
  const viewable = new Autodesk.DataVisualization.Core.SpriteViewable(
    new THREE.Vector3(x, y, z),
    style,
    dbid++
  );
  viewableData.addViewable(viewable);
}
viewableData.finish().then(() => {
  this._dataVizExt.addViewables(viewableData);
});

}

This function would basically get the updated sensor data and load it back to the viewer. It would be called once the selected sprite is deleted from the Map. It is used to update the sprites on the screen.

So the features actually work just fine, as in when I delete the selected sprite information from the Map, the sprite disappears from the screen. However, after it disappears, when I click on the viewer, this error occurs:

core.mjs:6485 ERROR TypeError: Cannot read properties of undefined (reading 'style')
at T.getViewableUV (CustomViewables.js:319:44)
at SceneTool.js:241:65

Basically, after I deleted the sprites and then I click at any point on the viewer, the function getViewableUV() is called, which causes the error. Can anyone help me on this matter?

Just some addition, one thing I notice is that when a sprite is clicked, it will be enlarged, then if we click on other items, the size will become small again. Maybe if I can find a way to remove this feature where the sprite becomes big/small when clicked, I can fix this problem. Does anyone know how I can do this?

There was a similar question on Stack Overflow on this, but I'm not sure how that user fix it. This is the link to the related question: DataVizExtention: issue with clearing viewables while a sprite is selected

Brytista
  • 3
  • 2
  • If this issue can be reproduced when the sprite is selected, then could you try calling [DataVizExt#clearHighlightedViewables()](https://aps.autodesk.com/en/docs/dataviz/v1/reference/DataVisualization/DataVisualization/#clearhighlightedviewables) before removing? – Eason Kang Jul 07 '23 at 08:15

0 Answers0