autodesk-viewerautodeskautodesk-data-visualization

How to select a SpriteViewable (change svg url to highlightedUrl) via code?


Environment: JS client side.

I have some issues made with Data Visualization SpriteViewables in my model, and the selection works, changing the svg url to the highlightedUrl, example:

example selected issue

In my application, I have an issues list like this:

issues list

I want that on click in an issue in this list, select the current sprite issue in model (changing the svg url to the highlightedUrl), I already have an auxiliary list containing all sprites dbIds and issue.id, with this list I have the relation between the clicked issue on the list (second image) and the sprite in model.

Having a closer look into the viewable data in data visualization, the Sprite Viewable object doesn't have a key like 'currentUrl' to change:

enter image description here

So it has to be another way.


Solution

  • When selecting/clicking on a sprite viewable, the icon of the clicked sprite viewable will become the highlightedUrl one in the style with my test. On the contrary, the icon will be changed back to the url one.

    To do this programmatically, we can do the following:

    let dataVizExt = viewer.getExtension('Autodesk.DataVisualization');
    
    // Select a sprite viewable
    dataVizExt.highlightViewables( [ spriteViewableDbId ] );
    viewer.impl.invalidate( false, false, true );
    
    // Deselect viewables
    dataVizExt.clearHighlightedViewables();