Skip to content

Commit a948253

Browse files
Merge pull request #729 from cmcfadden/master
Add altitude and location simulation to Location mode
2 parents 370477d + ed2b77f commit a948253

File tree

5 files changed

+78
-17
lines changed

5 files changed

+78
-17
lines changed

aframe/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ In addition to that, as you can see on the example above, we also have to add `r
6969
| alert | Whether to show a message when GPS signal is under the `positionMinAccuracy` | false | | true |
7070
| positionMinAccuracy | Minimum accuracy allowed for position signal | 100 |
7171
| minDistance | If set, places with a distance from the user lower than this value, are not showed. Only a positive value is allowed. Value is in meters. | 0 (disabled) |
72+
| simulateLatitude | Setting this allows you to simulate the latitude of the camera, to aid in testing. | 0 (disabled) |
73+
| simulateLongitude | Setting this allows you to simulate the longitude of the camera, to aid in testing. | 0 (disabled) |
74+
| simulateAltitude | Setting this allows you to simulate the altitude of the camera in meters above sea level, to aid in testing. | 0 (disabled) |
7275

7376

7477
### `gps-entity-place`
@@ -84,6 +87,14 @@ It requires latitude and longitude as a single string parameter (example with `a
8487
<a-box color="yellow" gps-entity-place="latitude: <your-latitude>; longitude: <your-longitude>"/>
8588
```
8689

90+
In addition, you can use the a-frame "position" parameter to assign a y-value or altitude to the entity. This value should be entered in meters above or below sea level. For example, this would assign a height of 300 meters above sea level, and will be displayed relative to the gps-camera's current altitude:
91+
92+
```HTML
93+
<a-box color="yellow" gps-entity-place="latitude: <your-latitude>; longitude: <your-longitude>" position="0 300 0"/>
94+
```
95+
96+
97+
8798
| Custom Attribute | Description | Default Value |
8899
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
89100
| distance | Distance from user, updated at every user position update. Value in meters. | 0 |

aframe/build/aframe-ar.js

Lines changed: 33 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aframe/build/aframe-ar.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aframe/src/location-based/gps-camera.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ AFRAME.registerComponent('gps-camera', {
44
currentCoords: null,
55
lookControls: null,
66
heading: null,
7-
87
schema: {
8+
simulateLatitude: {
9+
type: 'number',
10+
default: 0,
11+
},
12+
simulateLongitude: {
13+
type: 'number',
14+
default: 0,
15+
},
16+
simulateAltitude: {
17+
type: 'number',
18+
default: 0,
19+
},
920
positionMinAccuracy: {
1021
type: 'int',
1122
default: 100,
@@ -17,7 +28,7 @@ AFRAME.registerComponent('gps-camera', {
1728
minDistance: {
1829
type: 'int',
1930
default: 0,
20-
},
31+
}
2132
},
2233

2334
init: function () {
@@ -58,7 +69,7 @@ AFRAME.registerComponent('gps-camera', {
5869

5970
document.addEventListener('touchend', function () { handler() }, false);
6071

61-
alert('After camera permission prompt, please tap the screen to active geolocation.');
72+
alert('After camera permission prompt, please tap the screen to activate geolocation.');
6273
} else {
6374
var timeout = setTimeout(function () {
6475
alert('Please enable device orientation in Settings > Safari > Motion & Orientation Access.')
@@ -72,7 +83,18 @@ AFRAME.registerComponent('gps-camera', {
7283
window.addEventListener(eventName, this._onDeviceOrientation, false);
7384

7485
this._watchPositionId = this._initWatchGPS(function (position) {
75-
this.currentCoords = position.coords;
86+
if(this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
87+
localPosition = Object.assign({}, position.coords);
88+
localPosition.longitude = this.data.simulateLongitude;
89+
localPosition.latitude = this.data.simulateLatitude;
90+
localPosition.altitude = this.data.simulateAltitude;
91+
this.currentCoords = localPosition;
92+
}
93+
else {
94+
this.currentCoords = position.coords;
95+
}
96+
97+
7698
this._updatePosition();
7799
}.bind(this));
78100
},

aframe/src/location-based/gps-entity-place.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
AFRAME.registerComponent('gps-entity-place', {
22
_cameraGps: null,
33
schema: {
4-
latitude: {
4+
longitude: {
55
type: 'number',
66
default: 0,
77
},
8-
longitude: {
8+
latitude: {
99
type: 'number',
1010
default: 0,
11-
},
11+
}
1212
},
1313
init: function () {
1414
window.addEventListener('gps-camera-origin-coord-set', function () {
@@ -80,7 +80,10 @@ AFRAME.registerComponent('gps-entity-place', {
8080

8181
position.z = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
8282
position.z *= this.data.latitude > this._cameraGps.originCoords.latitude ? -1 : 1;
83-
83+
if(position.y !== 0) {
84+
position.y = position.y - this._cameraGps.originCoords.altitude;
85+
}
86+
8487
// update element's position in 3D world
8588
this.el.setAttribute('position', position);
8689
},

0 commit comments

Comments
 (0)