Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to display distanceMsg in Location based #453

Open
MilosGlisovic opened this issue Sep 11, 2022 · 1 comment
Open

How to display distanceMsg in Location based #453

MilosGlisovic opened this issue Sep 11, 2022 · 1 comment

Comments

@MilosGlisovic
Copy link

MilosGlisovic commented Sep 11, 2022

Hello everyone, I would like to do the same example as in this clip https://www.youtube.com/watch?v=biCKHVefIe8
@nickw1 @kalwalt Can you please see this
I would like to set the distanceMsg attribute in the a-text value, so that it is always visible, and a-text as a child element of a-image, so that the distance is always below. Aframe has special rules for child elements so I'm wondering how I could do this in JS?

This is my code but dont work

const model = document.createElement('a-image'); model.setAttribute('gps-entity-place',latitude: ${latitude}; longitude: ${longitude}`);
model.setAttribute('name', name2);
model.setAttribute('src', logo);
model.setAttribute('width', wdt);
model.setAttribute('height', hg);
model.setAttribute('look-at', '[gps-camera]');

               // for debug purposes, just show in a bigger scale, otherwise I have to personally go on places...
               model.setAttribute('scale', '20, 20');
               //model.setAttribute('position', '0, 0, 0');

              
               model.addEventListener('loaded', () => {
                window.dispatchEvent(new CustomEvent('gps-entity-place-loaded'))
            });
               
  

   const text = document.createElement('a-text');
   text.setAttribute('gps-entity-place', `latitude: ${latitude}; longitude: ${longitude}`);
   text.setAttribute('color', "blue");

  
   text.addEventListener('gps-entity-place-update-positon', (event) => {
    const distanceMsg = document.querySelector('[gps-entity-place]').getAttribute('distanceMsg');
   
   text.setAttribute('value', distanceMsg);

   textl.addEventListener('loaded', () => {
    window.dispatchEvent(new CustomEvent('gps-entity-place-loaded'))
});
     model.addEventListener('click', clickListener);
   scene.appendChild(model);
   model.appendChild(text);

});

`

@linshenqi
Copy link

<script type="text/javascript">
    window.addEventListener('load', () => {
      document.querySelector('[gps-entity-place]').addEventListener('gps-entity-place-update-position', (payload) => {
        let v = parseInt(payload.detail.distance);
        alert(`${v} meter`);
        // you may show the distance in the value of <a-text>
        // document.getElementById("id-of-a-text").setAttribute('value', `${v} meter`);
      });
    })
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants