Friday, 22 January 2021

Display distance to marker in AR.js

I'm trying to display the distance to text markers (underneath the markers) in AR.js; according to the docs, distanceMsg is a custom attribute from gps-entity-place, so I thought it could be retrieved with getAttribute and then set with setAttribute, but I'm having no success; besides, I'm just beginning to learn JS.

The following code produces a text marker with the word "null":

<!doctype html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <script src="https://aframe.io/releases/1.1.0/aframe.min.js"></script>
        <script src="https://unpkg.com/aframe-look-at-component@0.8.0/dist/aframe-look-at-component.min.js"></script>
        <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
        <script src="https://raw.githack.com/donmccurdy/aframe-extras/master/dist/aframe-extras.loaders.min.js"></script>
    <script>

   window.onload = () => {
    const distanceMsg = document.querySelector('[gps-entity-place]').getAttribute('distanceMsg');
    document.querySelector('a-text').setAttribute('value', distanceMsg);
    };
      </script>    </head>

    <body style="margin: 0; overflow: hidden;">
        <a-scene
            renderer="logarithmicDepthBuffer: true;"
            embedded
            loading-screen="enabled: false;"
            arjs="sourceType: webcam; debugUIEnabled: false;"
        >
         <a-text
        look-at="[gps-camera]"
            scale="50 50 50"
            gps-entity-place="latitude: 18.45030; longitude: -96.96152;"
              ></a-text> 
            <a-entity 
        text="value: place1;"
            look-at="[gps-camera]"
                scale="35 35 35"
                gps-entity-place="latitude: 18.45045; longitude: -96.96160;"
                ></a-entity>

            <a-camera gps-camera rotation-reader></a-camera>
        </a-scene>
    </body>
</html>


from Display distance to marker in AR.js

No comments:

Post a Comment