Set background image of goJs diagram dynamically

Hi Walter,

We need to bind the goJs Diagram’s background image to a variable and we are doing it like below :

goJsDiagram.add(
            $$(go.Part,
              {
                name: 'BackgroundImage',
                layerName: "Background",
                position: new go.Point(0, 0),
                selectable: false, pickable: false
              },
              $$(go.Picture, {
                  height: 600,
                  width: 900
              },
                  new go.Binding("source", "", function(data){
                      if(goJsPanel.backgroundImageId)
                          return `/OneView/services/MapImage?id=${goJsPanel.backgroundImageId}`;
                      return '';
                  })
              )
         ));

We are unable to call the above binding with the help of updateAllTargetBindings ( As this works on only node and link template bindings).

Could you help us? Please let us know if you need more information.

That is true – bindings only work when there is model data.

So you could add a node data to your model with a category that names a template that is defined like the Part that you added with Diagram.add. I guess the only other property could be “source” whose value is the URL. So the Binding would just be:
new go.Binding("source"), and you can modify it by call Model.set.

Alternatively, if you cannot change your model, just keep a reference to that Part that you added, and when it is time, find the Picture in it and set its Picture.source property. No Binding needed. Please read GraphObject Manipulation