提交 30a5491d 编写于 作者: N nicolo.carpignoli

trying with gps-camera-ready event

上级 434f2ff6
...@@ -8733,7 +8733,7 @@ AFRAME.registerComponent('gps-camera', { ...@@ -8733,7 +8733,7 @@ AFRAME.registerComponent('gps-camera', {
minDistance: { minDistance: {
type: 'int', type: 'int',
default: 0, default: 0,
} },
}, },
init: function () { init: function () {
...@@ -8772,6 +8772,9 @@ AFRAME.registerComponent('gps-camera', { ...@@ -8772,6 +8772,9 @@ AFRAME.registerComponent('gps-camera', {
window.addEventListener(eventName, this._onDeviceOrientation, false); window.addEventListener(eventName, this._onDeviceOrientation, false);
window.dispatchEvent(new CustomEvent('gps-camera-ready'));
console.debug('gps-camera-ready');
this._watchPositionId = this._initWatchGPS(function (position) { this._watchPositionId = this._initWatchGPS(function (position) {
this.currentCoords = position.coords; this.currentCoords = position.coords;
this._updatePosition(); this._updatePosition();
...@@ -9020,6 +9023,10 @@ AFRAME.registerComponent('gps-entity-place', { ...@@ -9020,6 +9023,10 @@ AFRAME.registerComponent('gps-entity-place', {
}, },
}, },
init: function () { init: function () {
window.addEventListener('gps-camera-ready', () => {
this._updatePosition();
});
this._positionXDebug = 0; this._positionXDebug = 0;
this.debugUIAddedHandler = function () { this.debugUIAddedHandler = function () {
...@@ -9041,8 +9048,6 @@ AFRAME.registerComponent('gps-entity-place', { ...@@ -9041,8 +9048,6 @@ AFRAME.registerComponent('gps-entity-place', {
return; return;
} }
this._updatePosition();
return true;
}, },
/** /**
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>GeoAR.js demo</title>
<script src='https://aframe.io/releases/0.9.2/aframe.min.js'></script>
<script src='../../build/aframe-ar.js'></script>
<script>
THREEx.ArToolkitContext.baseURL = 'https://raw.githack.com/jeromeetienne/ar.js/master/three.js/'
</script>
</head>
<link rel="stylesheet" href="../../src/location-based/stylesheets/index.css">
<!-- Dynamically add places from Javascript -->
<script src="./places.js"></script>
<body style='margin: 0; overflow: hidden;'>
<a-scene
cursor='rayOrigin: mouse; fuse: true; fuseTimeout: 0;'
raycaster="objects: [gps-entity-place];"
vr-mode-ui="enabled: false"
embedded
arjs='sourceType: webcam; sourceWidth:1280; sourceHeight:960; displayWidth: 1280; displayHeight: 960; debugUIEnabled: false;'>
<a-box gps-entity-place="latitude: 44.496470; longitude: 11.320220;"></a-box>
<a-camera gps-camera="minDistance: 40;" rotation-reader>
</a-camera>
</a-scene>
</body>
...@@ -2,19 +2,15 @@ ...@@ -2,19 +2,15 @@
window.onload = () => { window.onload = () => {
let method = 'dynamic'; let method = 'dynamic';
// if you want to statically add places, de-comment following line window.addEventListener('gps-camera-ready', () => {
// method = 'static'; // if you want to statically add places, de-comment following line:
method = 'static';
if (method === 'static') { if (method === 'static') {
// setTimeout is a temporary fix
setTimeout(() => {
let places = staticLoadPlaces(); let places = staticLoadPlaces();
renderPlaces(places); return renderPlaces(places);
}, 3000);
} }
if (method !== 'static') { if (method !== 'static') {
// first get current user location // first get current user location
return navigator.geolocation.getCurrentPosition(function (position) { return navigator.geolocation.getCurrentPosition(function (position) {
...@@ -32,6 +28,7 @@ window.onload = () => { ...@@ -32,6 +28,7 @@ window.onload = () => {
} }
); );
} }
});
}; };
function staticLoadPlaces() { function staticLoadPlaces() {
...@@ -39,17 +36,10 @@ function staticLoadPlaces() { ...@@ -39,17 +36,10 @@ function staticLoadPlaces() {
{ {
name: "Your place name", name: "Your place name",
location: { location: {
lat: 0, // add here latitude if using static data lat: 44.496470, // change here latitude if using static data
lng: 0, // add here longitude if using static data lng: 11.320220, // change here longitude if using static data
} }
}, },
{
name: 'Another place name',
location: {
lat: 0,
lng: 0,
}
}
]; ];
} }
......
...@@ -17,7 +17,7 @@ AFRAME.registerComponent('gps-camera', { ...@@ -17,7 +17,7 @@ AFRAME.registerComponent('gps-camera', {
minDistance: { minDistance: {
type: 'int', type: 'int',
default: 0, default: 0,
} },
}, },
init: function () { init: function () {
...@@ -56,6 +56,9 @@ AFRAME.registerComponent('gps-camera', { ...@@ -56,6 +56,9 @@ AFRAME.registerComponent('gps-camera', {
window.addEventListener(eventName, this._onDeviceOrientation, false); window.addEventListener(eventName, this._onDeviceOrientation, false);
window.dispatchEvent(new CustomEvent('gps-camera-ready'));
console.debug('gps-camera-ready');
this._watchPositionId = this._initWatchGPS(function (position) { this._watchPositionId = this._initWatchGPS(function (position) {
this.currentCoords = position.coords; this.currentCoords = position.coords;
this._updatePosition(); this._updatePosition();
......
...@@ -11,6 +11,10 @@ AFRAME.registerComponent('gps-entity-place', { ...@@ -11,6 +11,10 @@ AFRAME.registerComponent('gps-entity-place', {
}, },
}, },
init: function () { init: function () {
window.addEventListener('gps-camera-ready', () => {
this._updatePosition();
});
this._positionXDebug = 0; this._positionXDebug = 0;
this.debugUIAddedHandler = function () { this.debugUIAddedHandler = function () {
...@@ -32,8 +36,6 @@ AFRAME.registerComponent('gps-entity-place', { ...@@ -32,8 +36,6 @@ AFRAME.registerComponent('gps-entity-place', {
return; return;
} }
this._updatePosition();
return true;
}, },
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册