Skip to content

Commit dfec849

Browse files
committed
Merge branch 'dev' into latlontoworld
2 parents 964b0ab + 6a0f0b6 commit dfec849

File tree

13 files changed

+216
-20
lines changed

13 files changed

+216
-20
lines changed
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# Examples for A-Frame `new-location-based` components
22

3-
- `basic` : Basic example which creates four boxes to the north, south, east and west of your initial GPS position. Allows you to enter a "fake" latitude and longitude for testing on a desktop.
3+
These examples have been written specifically, or adapted, for the `new-location-based` components available in AR.js 3.4.0 upwards.
4+
5+
- `hello-world` : A basic Hello World example, using only HTML, which shows a box 0.001 degrees north of your location.
6+
7+
- `multiple-boxes` : An extension of the `hello-world` example with four boxes, to the north, south, east and west of your current location.
8+
9+
- `always-face-user` : Displays text 0.001 degrees north of your current location, using the third-party A-Frame look-at component to make the text always face the camera.
10+
11+
- `click-places` : Demonstrates how you can add click events to your AR objects, making use of A-Frame's `cursor` and `raycaster` components.
12+
13+
- `basic-js` : Basic JavaScript example which dynamically creates four boxes to the north, south, east and west of your initial GPS position (whatever that is). Allows you to enter a "fake" latitude and longitude for testing on a desktop.
414

515
- `poi` : Demonstrates downloading POIs from an OpenStreetMap-based GeoJSON API and adding them to the scene as objects, with text labels.
616

17+
- `poi-component` : Similar to `poi`, but demonstrating the use of a custom A-Frame component to download and display the POIs.
18+
719
- `osm-ways` : A more complex example showing how more specialised geodata can be rendered with AR.js. Downloads OpenStreetMap ways (roads, paths) from a GeoJSON API, reprojects them into Spherical Mercator, and adds them to the scene as polylines made up of individual triangles.
20+
21+
## Coming soon!
22+
23+
The use of smoothing to reduce "shaking" artefacts, currently implemented in the "classic" AR.js location-based components, has been implemented as a PR for the `new-location-based` components. It is likely to be available in the next release (3.4.3).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>AR.js A-Frame</title>
6+
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
7+
<script src="https://unpkg.com/[email protected]/dist/aframe-look-at-component.min.js"></script>
8+
<!-- Assumes AR.js build is in the 'AR.js' directory -->
9+
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
10+
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
11+
</head>
12+
<body>
13+
<!--
14+
This is using a simulated location. If testing on a mobile device, remove the
15+
'simulateLatitude' and 'simulateLongitude' properties from 'gps-new-camera' and
16+
change the 'latitude' and 'longitude' properties to a location around 0.001
17+
degrees from your real location.
18+
-->
19+
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
20+
<a-camera gps-new-camera='gpsMinDistance: 5; simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
21+
<!--
22+
Use the third-party A-Frame 'look-at' component to make the text look at the
23+
camera.
24+
-->
25+
<a-text value='This will always face the user.' look-at='[gps-new-camera]' gps-new-entity-place="latitude: 51.05; longitude: -0.723" scale="50 50 50"></a-entity>
26+
</a-scene>
27+
28+
</body>
29+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>AR.js Click Places Example</title>
5+
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
6+
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
7+
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
8+
<script>
9+
AFRAME.registerComponent('clicker', {
10+
init: function() {
11+
this.el.addEventListener('click', e => {
12+
alert('Box clicked!');
13+
});
14+
}
15+
});
16+
</script>
17+
</head>
18+
<body>
19+
<a-scene
20+
vr-mode-ui="enabled: false"
21+
cursor='rayOrigin: mouse'
22+
raycaster='near: 0; far: 50000'
23+
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'
24+
renderer='antialias: true; alpha: true'>
25+
<a-camera gps-new-camera='simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
26+
<a-box gps-new-entity-place='latitude: 51.0596; longitude: -0.7170' color='red' scale='200 200 200' clicker></a-box>
27+
</a-scene>
28+
</body>
29+
</html>
30+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>AR.js A-Frame</title>
6+
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
7+
<!-- Assumes AR.js build is in the 'AR.js' directory -->
8+
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
9+
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
10+
</head>
11+
<body>
12+
<!--
13+
This is using a simulated location. If testing on a mobile device, remove the
14+
'simulateLatitude' and 'simulateLongitude' properties from 'gps-new-camera' and
15+
change the 'latitude' and 'longitude' properties to a location around 0.001
16+
degrees from your real location.
17+
-->
18+
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
19+
<a-camera gps-new-camera='gpsMinDistance: 5; simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
20+
<a-entity material='color: red' geometry='primitive: box' gps-new-entity-place="latitude: 51.05; longitude: -0.723" scale="10 10 10"></a-entity>
21+
</a-scene>
22+
23+
</body>
24+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>AR.js A-Frame</title>
6+
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
7+
<!-- Assumes AR.js build is in the 'AR.js' directory -->
8+
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
9+
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
10+
</head>
11+
<body>
12+
<!--
13+
This is using a simulated location. If testing on a mobile device, remove the
14+
'simulateLatitude' and 'simulateLongitude' properties from 'gps-new-camera' and
15+
change the 'latitude' and 'longitude' properties to a location around 0.001
16+
degrees from your real location.
17+
-->
18+
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
19+
<a-camera gps-new-camera='gpsMinDistance: 5; simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
20+
<a-entity material='color: red' geometry='primitive: box' gps-new-entity-place="latitude: 51.05; longitude: -0.723" scale="10 10 10"></a-entity>
21+
<a-entity material='color: yellow' geometry='primitive: box' gps-new-entity-place="latitude: 51.048; longitude: -0.723" scale="10 10 10"></a-entity>
22+
<a-entity material='color: blue' geometry='primitive: box' gps-new-entity-place="latitude: 51.049; longitude: -0.724" scale="10 10 10"></a-entity>
23+
<a-entity material='color: green' geometry='primitive: box' gps-new-entity-place="latitude: 51.049; longitude: -0.722" scale="10 10 10"></a-entity>
24+
</a-scene>
25+
26+
</body>
27+
</html>

aframe/examples/new-location-based/osm-ways/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<head>
44
<meta charset='utf-8' />
55
<title>AR.js osm example</title>
6-
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
7-
<!-- Assumes AR.js build is in the 'AR.js' directory -->
8-
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
9-
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
6+
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
7+
<!-- Assumes AR.js build is in the 'AR.js' directory -->
8+
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
9+
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
1010
<script type='text/javascript' src='index.js'></script>
1111
<script type='text/javascript' src='osm.js'></script>
1212
<script type='text/javascript' src='osmway.js'></script>
@@ -26,7 +26,7 @@
2626
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false'>
2727
<div id='status'></div>
2828
<a-camera gps-new-camera='simulateLatitude: 51.049; simulateLongitude: -0.723' position='0 20 0' wasd-controls='acceleration: 1300'></a-camera>
29-
<a-entity id='osmElement' osm />
29+
<a-entity osm></a-entity>
3030
</a-scene>
3131
</body>
3232
</html>

aframe/examples/new-location-based/osm-ways/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11

22
window.onload = () => {
3-
const osmElement = document.getElementById('osmElement');
3+
const osmElement = document.querySelector('[osm]');
44
document.getElementById('status').innerHTML = 'Loading OpenStreetMap data...';
5-
const gpsProjCamera = document.querySelector('a-camera').components['gps-projected-camera'];
6-
7-
window.addEventListener("gps-camera-update-position", e=> {
8-
osmElement.setAttribute('osm', {
9-
longitude: e.detail.position.longitude,
10-
latitude: e.detail.position.latitude
11-
});
12-
});
13-
145
osmElement.addEventListener('vector-ways-loaded', e => {
156
document.getElementById('status').innerHTML = '';
167
});

aframe/examples/new-location-based/osm-ways/osm.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ AFRAME.registerComponent('osm', {
1111
}
1212
},
1313

14+
init: function() {
15+
this.downloaded = false;
16+
this.camera = document.querySelector("[gps-new-camera]");
17+
this.camera.addEventListener("gps-camera-update-position", e=> {
18+
if(!this.downloaded) {
19+
this._readOsm(e.detail.position.latitude, e.detail.position.longitude);
20+
this.downloaded = true;
21+
}
22+
});
23+
},
24+
1425
update: function() {
1526
if (this.data.latitude >= -90 && this.data.latitude <= 90 && this.data.longitude >= -180 && this.data.longitude <= 180) {
1627
this._readOsm(this.data.latitude, this.data.longitude);
1728
}
1829
},
1930

2031
_readOsm: function(lat, lon) {
21-
const camera = document.querySelector("[gps-new-camera]");
22-
const gpsCameraComponent = camera.components["gps-new-camera"];
32+
const gpsCameraComponent = this.camera.components["gps-new-camera"];
2333
if(!gpsCameraComponent) {
2434
alert('gps-new-camera component not initialised');
2535
return;
@@ -36,7 +46,7 @@ AFRAME.registerComponent('osm', {
3646
'track': { color: '#ff8080' },
3747
'cycleway': { color: '#00ffff' },
3848
};
39-
const features = [];
49+
const objectIds = [];
4050
json.features.forEach((f, i) => {
4151
const line = [];
4252
let projectedCoords;
@@ -56,9 +66,13 @@ AFRAME.registerComponent('osm', {
5666
color: color
5767
}));
5868
this.el.setObject3D(f.properties.osm_id, mesh);
69+
objectIds.push(f.properties.osm_id);
5970
}
6071
}
6172
});
73+
this.el.emit('vector-ways-loaded', {
74+
objectIds: objectIds
75+
});
6276
});
6377
}
6478
});

0 commit comments

Comments
 (0)