Hello how are you?
I would like to know how I can access the click event on triggers and anchors. I want to be able to generate custom pop ups in html with content referring to the element I click on.
I would also like to access your id and the content previously configured in the editor.
I’d appreciate your help. Thanks a lot
To capture clicks in objects in the scenes, you can use the API described here (take a look also at the sample body-end.html file linked from that section(.
In case of the anchors, it is only possible to capture clicks on anchors that your JavaScrtipt code added. Take a look at this example. It is not possible to capture clicks on anchors added from the editor.
Thank you very much for the reply.
Perfect, but how could I then access the identifier of that Anchor. For example, if you wanted to save the number of clicks that were made on that anchor.
That linked example doesn’t show this, but anchor is passed at the first argument to the anchorClicked callback. You can also use a separate callback function per anchor:
var anchor1 = viewer.addAnchor(anchorConfig, function() {/*your click handler for the anchor 1*/});
var anchor2 = viewer.addAnchor(anchorConfig, function() {/*your different click handler for the anchor 2*/});
            Thank you very much!
I tried the following way to add custom anchor in my shapespark scene in this manner, but the anchor button do not seem to be visible. Has there been some change in the way of adding custom anchor?
    viewer.onSceneReadyToDisplay = () => {
      function anchorClicked() {
          window.alert('clicked');
      }
      var anchorConfig = {
        position: [1.0, 2.0, 2.5],
        type: 'sphere',
        radius: 0.07,
        text: 'foobar'
      };
      var anchor = viewer.addAnchor(anchorConfig, anchorClicked);
    };
Is there something I am doing wrong?
onSceneReadyToDisplay is a function, not an assignable property. Please call it passing a callback argument as in the Trigger Extensions via Javascript - #2 by jan example. Also, make sure that the given position is within your scene.