Back to the Shapespark home page

How to access the event click on Trigger and Anchor

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.

1 Like

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!