Change trigger background color from script

I’m trying to set a background color to my anchor but i can’t get the property. Also I want to know if I can set a name to it and use it to change the background color dynamically.

var viewer = WALK.getViewer();

function anchorClicked() {
   window.alert('clicked');
}

function sceneReadyToDisplay() {
    var anchorConfig = {
      position: [62, 258, 1],
      type: 'sphere',
      radius: 1,
      text: '12',
backgroundColor: '#000',
name: 1
    };
    var anchor = viewer.addAnchor(anchorConfig, anchorClicked);
}

viewer.onSceneReadyToDisplay(sceneReadyToDisplay);

Thanks in advance.

Hi!

backgroundColor isn’t a valid property for setting the background color. To do so, you need to set the color property. Changing your anchorConfig to:

{
      position: [62, 258, 1],
      type: 'sphere',
      radius: 1,
      text: '12',
      color: '#000000',
      textColor: '#ffffff'
};

should do the trick and make the background black with text color white.

I don’t know what you mean by use the name? The name will be ignored as it’s not a property of Anchor, so the actual Anchor object won’t have any notion about the value of the name that you’ve supplied.

If you want to change the color dynamically I’d say the easiest way would be to remove the old anchor and create a new one right after removing the old one with only the color values changed.

I hope this helps!

1 Like

I see. Thanks for your help :smiley: