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

trying with gps-camera-ready event

上级 434f2ff6
......@@ -8733,7 +8733,7 @@ AFRAME.registerComponent('gps-camera', {
minDistance: {
type: 'int',
default: 0,
}
},
},
init: function () {
......@@ -8772,6 +8772,9 @@ AFRAME.registerComponent('gps-camera', {
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.currentCoords = position.coords;
this._updatePosition();
......@@ -9020,6 +9023,10 @@ AFRAME.registerComponent('gps-entity-place', {
},
},
init: function () {
window.addEventListener('gps-camera-ready', () => {
this._updatePosition();
});
this._positionXDebug = 0;
this.debugUIAddedHandler = function () {
......@@ -9041,8 +9048,6 @@ AFRAME.registerComponent('gps-entity-place', {
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,36 +2,33 @@
window.onload = () => {
let method = 'dynamic';
// if you want to statically add places, de-comment following line
// method = 'static';
if (method === 'static') {
// setTimeout is a temporary fix
setTimeout(() => {
window.addEventListener('gps-camera-ready', () => {
// if you want to statically add places, de-comment following line:
method = 'static';
if (method === 'static') {
let places = staticLoadPlaces();
renderPlaces(places);
}, 3000);
}
if (method !== 'static') {
return renderPlaces(places);
}
// first get current user location
return navigator.geolocation.getCurrentPosition(function (position) {
if (method !== 'static') {
// first get current user location
return navigator.geolocation.getCurrentPosition(function (position) {
// than use it to load from remote APIs some places nearby
dynamicLoadPlaces(position.coords)
.then((places) => {
renderPlaces(places);
})
},
(err) => console.error('Error in retrieving position', err),
{
enableHighAccuracy: true,
maximumAge: 0,
timeout: 27000,
}
);
}
// than use it to load from remote APIs some places nearby
dynamicLoadPlaces(position.coords)
.then((places) => {
renderPlaces(places);
})
},
(err) => console.error('Error in retrieving position', err),
{
enableHighAccuracy: true,
maximumAge: 0,
timeout: 27000,
}
);
}
});
};
function staticLoadPlaces() {
......@@ -39,17 +36,10 @@ function staticLoadPlaces() {
{
name: "Your place name",
location: {
lat: 0, // add here latitude if using static data
lng: 0, // add here longitude if using static data
lat: 44.496470, // change here latitude 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', {
minDistance: {
type: 'int',
default: 0,
}
},
},
init: function () {
......@@ -56,6 +56,9 @@ AFRAME.registerComponent('gps-camera', {
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.currentCoords = position.coords;
this._updatePosition();
......
......@@ -11,6 +11,10 @@ AFRAME.registerComponent('gps-entity-place', {
},
},
init: function () {
window.addEventListener('gps-camera-ready', () => {
this._updatePosition();
});
this._positionXDebug = 0;
this.debugUIAddedHandler = function () {
......@@ -32,8 +36,6 @@ AFRAME.registerComponent('gps-entity-place', {
return;
}
this._updatePosition();
return true;
},
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册