Skip to content

Commit

Permalink
Alter location-based examples to focus on new-location-based components
Browse files Browse the repository at this point in the history
  • Loading branch information
nickw1 committed Dec 6, 2024
1 parent 1925fb0 commit 767d2a5
Show file tree
Hide file tree
Showing 62 changed files with 184 additions and 973 deletions.
26 changes: 15 additions & 11 deletions aframe/examples/location-based/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Location-based examples
# Examples for A-Frame `new-location-based` components

A brief summary of each example follows below. Aside from `hello-world`, the majority of the applications have a simulated lattitude and longitude; please modify the code to use your actual latitude and longitude.
These examples have been written specifically, or adapted, for the `new-location-based` components available in AR.js 3.4.0 upwards.

- `hello-world`: a simple example placing a cube at a given latitude and longitude. You must edit the code to supply your latitude and longitude.
- `hello-world` : A basic Hello World example, using only HTML, which shows a box 0.001 degrees north of your location.

- `projected-based-camera` : version of `hello-world` using `gps-projected-camera` and `gps-projected-entity-place`.
- `multiple-boxes` : An extension of the `hello-world` example with four boxes, to the north, south, east and west of your current location.

- `click-places` - a version of `hello-world` which demonstrates click events on entities. Please look at the code and note how the raycaster is working.
- `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.

- `always-face-user` - shows how you can use A-Frame's `look-at` component to create an entity which always faces the user.
- `click-places` : Demonstrates how you can add click events to your AR objects, making use of A-Frame's `cursor` and `raycaster` components.

- `avoid-shaking` - demonstrates the parameters needed to minimise shaking effects. Please look at the source code for full details.
- `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.

- `show-arbitrary-distant-places` - shows how you can view AR content many kilometres away using the `videoTexture` component. (In fact, currently, all working examples use `videoTexture` due to an issue - pending investigation - which occurs if it's not set)
- `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.

- `places-name` - shows the use of a web API to download local POIs but currently non-operational due to the CORS proxy no longer being available.
- `show-distance` : version of `basic-js` which shows the distance to a given object when you click on it.

- `peakfinder-2d` - shows the use of an OpenStreetMap based web API to download local summits. Does *not* include elevation though, hence the `2d`. Uses a working proxy.
- `poi` : Demonstrates downloading POIs from an OpenStreetMap-based GeoJSON API and adding them to the scene as objects, with text labels.

- `osm-ways` - shows how you can use AR.js to show not just simple point features but more complex geodata such as polylines. Downloads OpenStreetMap ways (roads, footpaths etc) from a server and renders them as polylines.
- `poi-component` : Similar to `poi`, but demonstrating the use of a custom A-Frame component to download and display the POIs.

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

- `avoid-shaking` : A version of `basic-js` with a smoothing factor applied to reduce shaking effects.
40 changes: 24 additions & 16 deletions aframe/examples/location-based/always-face-user/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@

<!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/1.6.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-look-at-component.min.js"></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<title>AR.js A-Frame</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-look-at-component.min.js"></script>
<!-- Assumes AR.js build is in the 'AR.js' directory -->
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
</head>

<body style='margin: 0; overflow: hidden;'>
<a-scene
vr-mode-ui="enabled: false"
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'>

<a-camera gps-camera='simulateLatitude: 51.049; simulateLongitude: -0.723' rotation-reader></a-camera>
<a-text value="This will always face the user." look-at="[gps-camera]" scale="75 75 75" gps-entity-place="latitude: 51.0491; longitude: -0.723;"></a-text>
</a-scene>
<body>
<!--
This is using a simulated location. If testing on a mobile device, remove the
'simulateLatitude' and 'simulateLongitude' properties from 'gps-new-camera' and
change the 'latitude' and 'longitude' properties to a location around 0.001
degrees from your real location.
-->
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
<a-camera gps-new-camera='gpsMinDistance: 5; simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
<!--
Use the third-party A-Frame 'look-at' component to make the text look at the
camera.
-->
<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>
</a-scene>

</body>

</html>
Binary file removed aframe/examples/location-based/assets/map-marker.png
Binary file not shown.
Binary file removed aframe/examples/location-based/assets/place_icon.png
Binary file not shown.
47 changes: 16 additions & 31 deletions aframe/examples/location-based/avoid-shaking/index.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
<!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/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<title>AR.js A-Frame</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<!-- Assumes AR.js build is in the 'AR.js' directory -->
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
<script src='index.js'></script>
</head>

<body style='margin: 0; overflow: hidden;'>
<a-scene
vr-mode-ui="enabled: false"
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'>

<!-- ~ 400m far -->
<a-box material="color: red;" scale="5 5 5" gps-entity-place="latitude: 44.506477; longitude: 11.301524;"></a-box>

<!-- ~ 20m far -->
<a-image src="place.png" gps-entity-place="latitude: 44.504417; longitude: 11.301317;"
></a-image>

<!-- ~ 0m far -->
<a-image src="place.png" gps-entity-place="latitude: 44.504348; longitude: 11.301027;"
></a-image>

<!-- using gpsMinDistance: 5 => update GPS only if user moves by 5 meters or more => avoid shaking for near objects -->
<!-- using accelerationToMove: 1.0 => 'smooth' inertial sensors precision precision in order to avoid distant places shaking -->
<a-camera
rotation-reader
gps-camera="simulateLatitude: 44.50437; simulateLongitude: 11.30106; gpsMinDistance: 10;"
>
</a-camera>
</a-scene>
<body>
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
<a-camera look-controls-enabled='false' arjs-device-orientation-controls='smoothingFactor:0.1' gps-new-camera='gpsMinDistance: 5'></a-camera>
</a-scene>
<div id='setloc' style='position:absolute; left: 10px; bottom: 2%; z-index:999; background-color: blue; color: white; padding: 10px'>
Lat:<input id="lat" value="51.049" />
Lon: <input id="lon" value="-0.723"/>
Min Acc: <input id='minacc' value='1000' /> <input type='button' id='go' value='go' />
</div>
</body>

</html>
15 changes: 15 additions & 0 deletions aframe/examples/location-based/classic-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Location-based examples for classic location-based components

These examples are for the "classic" location-based components, not the `new-location-based` components.

A brief summary of each example follows below. Aside from `hello-world`, the majority of the applications have a simulated lattitude and longitude; please modify the code to use your actual latitude and longitude.

- `always-face-user` - shows how you can use A-Frame's `look-at` component to create an entity which always faces the user.

- `avoid-shaking` - demonstrates the parameters needed to minimise shaking effects. Please look at the source code for full details.

- `click-places` - shows how you can handle click events on places

- `max-min-distance` - how to control the max and min distance you can view an object.

- `peakfinder-2d` - download nearby peaks from an OpenStreetMap-based server (works in Europe and Turkey only) and shows them in AR.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!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/1.6.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-look-at-component.min.js"></script>
<script type='text/javascript' src='../../../../build/aframe-ar-nft.js'></script>
</head>

<body style='margin: 0; overflow: hidden;'>
<a-scene
vr-mode-ui="enabled: false"
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'>

<a-camera gps-camera='simulateLatitude: 51.049; simulateLongitude: -0.723' rotation-reader></a-camera>
<a-text value="This will always face the user." look-at="[gps-camera]" scale="75 75 75" gps-entity-place="latitude: 51.0491; longitude: -0.723;"></a-text>
</a-scene>
</body>

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!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/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../../build/aframe-ar-nft.js'></script>
</head>

<body style='margin: 0; overflow: hidden;'>
<a-scene
vr-mode-ui="enabled: false"
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'>

<!-- ~ 400m far -->
<a-box material="color: red;" scale="5 5 5" gps-entity-place="latitude: 44.506477; longitude: 11.301524;"></a-box>

<!-- ~ 20m far -->
<a-image src="place.png" gps-entity-place="latitude: 44.504417; longitude: 11.301317;"
></a-image>

<!-- ~ 0m far -->
<a-image src="place.png" gps-entity-place="latitude: 44.504348; longitude: 11.301027;"
></a-image>

<!-- using gpsMinDistance: 5 => update GPS only if user moves by 5 meters or more => avoid shaking for near objects -->
<!-- using accelerationToMove: 1.0 => 'smooth' inertial sensors precision precision in order to avoid distant places shaking -->
<a-camera
rotation-reader
gps-camera="simulateLatitude: 44.50437; simulateLongitude: 11.30106; gpsMinDistance: 10;"
>
</a-camera>
</a-scene>
</body>

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
<title>AR.js Click Places Example</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<script type='text/javascript' src='../../../../build/aframe-ar-nft.js'></script>
<script>
AFRAME.registerComponent('clicker', {
init: function() {
Expand All @@ -22,8 +21,8 @@
raycaster='near: 0; far: 50000'
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'
renderer='antialias: true; alpha: true'>
<a-camera gps-new-camera='simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
<a-box gps-new-entity-place='latitude: 51.0596; longitude: -0.7170' color='red' scale='200 200 200' clicker></a-box>
<a-camera gps-projected-camera='simulateLatitude: 51.049; simulateLongitude: -0.723' rotation-reader></a-camera>
<a-box gps-projected-entity-place='latitude: 51.0596; longitude: -0.7170' color='red' scale='200 200 200' clicker></a-box>
</a-scene>
</body>
</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>GeoAR.js demo</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<script type='text/javascript' src='../../../../build/aframe-ar-nft.js'></script>
</head>

<body><!-- style='margin: 0; overflow: hidden;'>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>AR.js Peakfinder (2D - no elevation)</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-look-at-component.min.js"></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<script type='text/javascript' src='../../../../build/aframe-ar-nft.js'></script>
<script type='text/javascript' src='index.js'></script>
</head>
<body>
Expand Down
5 changes: 3 additions & 2 deletions aframe/examples/location-based/click-places/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>AR.js Click Places Example</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<script>
AFRAME.registerComponent('clicker', {
Expand All @@ -21,8 +22,8 @@
raycaster='near: 0; far: 50000'
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'
renderer='antialias: true; alpha: true'>
<a-camera gps-projected-camera='simulateLatitude: 51.049; simulateLongitude: -0.723' rotation-reader></a-camera>
<a-box gps-projected-entity-place='latitude: 51.0596; longitude: -0.7170' color='red' scale='200 200 200' clicker></a-box>
<a-camera gps-new-camera='simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
<a-box gps-new-entity-place='latitude: 51.0596; longitude: -0.7170' color='red' scale='200 200 200' clicker></a-box>
</a-scene>
</body>
</html>
Expand Down
38 changes: 22 additions & 16 deletions aframe/examples/location-based/hello-world/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@

<!DOCTYPE html>
<html>
<head>
<title>AR.js Hello World Example</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
</head>
<body>
<a-scene
vr-mode-ui="enabled: false"
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'
renderer='antialias: true; alpha: true'>
<a-camera gps-camera rotation-reader></a-camera>
<a-box gps-entity-place='latitude: your-latitude; longitude: your-longitude' color='red' scale='20 20 20'></a-box>
</a-scene>
</body>
<html>
<head>
<title>AR.js A-Frame</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<!-- Assumes AR.js build is in the 'AR.js' directory -->
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
</head>
<body>
<!--
This is using a simulated location. If testing on a mobile device, remove the
'simulateLatitude' and 'simulateLongitude' properties from 'gps-new-camera' and
change the 'latitude' and 'longitude' properties to a location around 0.001
degrees from your real location.
-->
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false' renderer='antialias: true; alpha: true'>
<a-camera gps-new-camera='gpsMinDistance: 5; simulateLatitude: 51.049; simulateLongitude: -0.723'></a-camera>
<a-entity material='color: red' geometry='primitive: box' gps-new-entity-place="latitude: 51.05; longitude: -0.723" scale="10 10 10"></a-entity>
</a-scene>

</body>
</html>

21 changes: 0 additions & 21 deletions aframe/examples/location-based/osm-ways/gps-vector-ways.js

This file was deleted.

9 changes: 5 additions & 4 deletions aframe/examples/location-based/osm-ways/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<meta charset='utf-8' />
<title>AR.js osm example</title>
<script src="https://aframe.io/releases/1.6.0/aframe.min.js"></script>
<script type='text/javascript' src='../../../build/aframe-ar-nft.js'></script>
<!-- Assumes AR.js build is in the 'AR.js' directory -->
<script type='text/javascript' src='../../../../three.js/build/ar-threex-location-only.js'></script>
<script type='text/javascript' src='../../../build/aframe-ar.js'></script>
<script type='text/javascript' src='index.js'></script>
<script type='text/javascript' src='osm.js'></script>
<script type='text/javascript' src='osmway.js'></script>
<script type='text/javascript' src='gps-vector-ways.js'></script>
<style type='text/css'>
#status {
font-family: Roboto, sans-serif;
Expand All @@ -24,8 +25,8 @@
<body style='margin: 0; overflow: hidden'>
<a-scene vr-mode-ui='enabled: false' arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false'>
<div id='status'></div>
<a-camera gps-projected-camera='simulateLatitude: 51.049; simulateLongitude: -0.723' rotation-reader position='0 20 0' wasd-controls='acceleration: 1300'></a-camera>
<a-entity id='osmElement' osm gps-vector-ways />
<a-camera gps-new-camera position='0 20 0'></a-camera>
<a-entity osm></a-entity>
</a-scene>
</body>
</html>
9 changes: 1 addition & 8 deletions aframe/examples/location-based/osm-ways/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@

window.onload = () => {
const osmElement = document.getElementById('osmElement');
const osmElement = document.querySelector('[osm]');
document.getElementById('status').innerHTML = 'Loading OpenStreetMap data...';
const gpsProjCamera = document.querySelector('a-camera').components['gps-projected-camera'];

osmElement.setAttribute('osm', {
longitude: gpsProjCamera.data.simulateLongitude,
latitude: gpsProjCamera.data.simulateLatitude
});

osmElement.addEventListener('vector-ways-loaded', e => {
document.getElementById('status').innerHTML = '';
});
Expand Down
Loading

0 comments on commit 767d2a5

Please sign in to comment.