Skip to content

Commit b1e0631

Browse files
committed
Add module example to new-location-based examples
1 parent 6788fe3 commit b1e0631

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

aframe/examples/new-location-based/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ These examples have been written specifically, or adapted, for the `new-location
1212

1313
- `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.
1414

15+
- `basic-js-modules` : version of `basic-js` which uses an ES6 import to include AR.js. Requires building using Webpack: a `webpack.config.js` is provided.
16+
1517
- `poi` : Demonstrates downloading POIs from an OpenStreetMap-based GeoJSON API and adding them to the scene as objects, with text labels.
1618

1719
- `poi-component` : Similar to `poi`, but demonstrating the use of a custom A-Frame component to download and display the POIs.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>AR.js A-Frame</title>
5+
<script src='dist/bundle.js'></script>
6+
</head>
7+
<body>
8+
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
9+
<a-camera gps-new-camera='gpsMinDistance: 5'></a-camera>
10+
</a-scene>
11+
<div id='setloc' style='position:absolute; left: 10px; bottom: 2%; z-index:999; background-color: blue; color: white; padding: 10px'>
12+
Lat:<input id="lat" value="51.049" />
13+
Lon: <input id="lon" value="-0.723"/>
14+
Min Acc: <input id='minacc' value='1000' /> <input type='button' id='go' value='go' />
15+
</div>
16+
</body>
17+
</html>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import '../../../build/aframe-ar.js';
2+
3+
window.onload = () => {
4+
let testEntitiesAdded = false;
5+
alert('If testing the lat/lon manual input on a mobile device, please turn off your GPS to avoid the real location being detected.');
6+
const el = document.querySelector("[gps-new-camera]");
7+
el.addEventListener("gps-camera-update-position", e => {
8+
if(!testEntitiesAdded) {
9+
alert(`Got first GPS position: lon ${e.detail.position.longitude} lat ${e.detail.position.latitude}`);
10+
// Add four boxes to the north (red), south (yellow), west (blue)
11+
// and east (red) of the initial GPS position
12+
const properties = [{
13+
color: 'red',
14+
latDis: 0.001,
15+
lonDis: 0
16+
},{
17+
color: 'yellow',
18+
latDis: -0.001,
19+
lonDis: 0
20+
},{
21+
color: 'blue',
22+
latDis: 0,
23+
lonDis: -0.001
24+
},{
25+
color: 'green',
26+
latDis: 0,
27+
lonDis: 0.001
28+
}
29+
];
30+
for(const prop of properties) {
31+
const entity = document.createElement("a-box");
32+
entity.setAttribute("scale", {
33+
x: 20,
34+
y: 20,
35+
z: 20
36+
});
37+
entity.setAttribute('material', { color: prop.color } );
38+
entity.setAttribute('gps-new-entity-place', {
39+
latitude: e.detail.position.latitude + prop.latDis,
40+
longitude: e.detail.position.longitude + prop.lonDis
41+
});
42+
43+
document.querySelector("a-scene").appendChild(entity);
44+
}
45+
testEntitiesAdded = true;
46+
}
47+
});
48+
49+
document.getElementById("go").addEventListener("click", e=> {
50+
const lat = document.getElementById('lat').value;
51+
const lon = document.getElementById('lon').value;
52+
const minacc = document.getElementById('minacc').value;
53+
54+
el.setAttribute('gps-new-camera', { simulateLatitude: lat, simulateLongitude: lon, positionMinAccuracy: minacc } );
55+
});
56+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
mode: 'development',
5+
entry: path.resolve(__dirname, 'index.js'),
6+
output: {
7+
path: path.resolve(__dirname, 'dist'),
8+
filename: 'bundle.js'
9+
},
10+
optimization: {
11+
minimize: false
12+
}
13+
};

0 commit comments

Comments
 (0)