Skip to content

Commit c6661e2

Browse files
Merge pull request #262 from nickw1/dev
Allow minDistance and maxDistance to work with simulated GPS position
2 parents 9f4d3c2 + cb0b755 commit c6661e2

File tree

6 files changed

+173
-150
lines changed

6 files changed

+173
-150
lines changed

aframe/build/aframe-ar-location-only.js

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -816,25 +816,28 @@ AFRAME.registerComponent('gps-camera', {
816816
},
817817

818818
play: function() {
819-
this._watchPositionId = this._initWatchGPS(function (position) {
820-
var localPosition = {
821-
latitude: position.coords.latitude,
822-
longitude: position.coords.longitude,
823-
altitude: position.coords.altitude,
824-
accuracy: position.coords.accuracy,
825-
altitudeAccuracy: position.coords.altitudeAccuracy,
826-
};
827-
819+
if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
820+
localPosition.latitude = this.data.simulateLatitude;
821+
localPosition.longitude = this.data.simulateLongitude;
828822
if (this.data.simulateAltitude !== 0) {
829823
localPosition.altitude = this.data.simulateAltitude;
830824
}
825+
this.currentCoords = localPosition;
826+
this._updatePosition();
827+
} else {
828+
this._watchPositionId = this._initWatchGPS(function (position) {
829+
var localPosition = {
830+
latitude: position.coords.latitude,
831+
longitude: position.coords.longitude,
832+
altitude: position.coords.altitude,
833+
accuracy: position.coords.accuracy,
834+
altitudeAccuracy: position.coords.altitudeAccuracy,
835+
};
836+
837+
if (this.data.simulateAltitude !== 0) {
838+
localPosition.altitude = this.data.simulateAltitude;
839+
}
831840

832-
if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
833-
localPosition.latitude = this.data.simulateLatitude;
834-
localPosition.longitude = this.data.simulateLongitude;
835-
this.currentCoords = localPosition;
836-
this._updatePosition();
837-
} else {
838841
this.currentCoords = localPosition;
839842
var distMoved = this._haversineDist(
840843
this.lastPosition,
@@ -848,8 +851,8 @@ AFRAME.registerComponent('gps-camera', {
848851
latitude: this.currentCoords.latitude
849852
};
850853
}
851-
}
852-
}.bind(this));
854+
}.bind(this));
855+
}
853856
},
854857

855858
tick: function () {
@@ -1017,7 +1020,7 @@ AFRAME.registerComponent('gps-camera', {
10171020
if (isPlace && this.data.maxDistance && this.data.maxDistance > 0 && distance > this.data.maxDistance) {
10181021
return Number.MAX_SAFE_INTEGER;
10191022
}
1020-
1023+
10211024
return distance;
10221025
},
10231026

@@ -1380,26 +1383,29 @@ AFRAME.registerComponent('gps-projected-camera', {
13801383
window.addEventListener(eventName, this._onDeviceOrientation, false);
13811384
},
13821385

1383-
play: function() {
1384-
this._watchPositionId = this._initWatchGPS(function (position) {
1385-
var localPosition = {
1386-
latitude: position.coords.latitude,
1387-
longitude: position.coords.longitude,
1388-
altitude: position.coords.altitude,
1389-
accuracy: position.coords.accuracy,
1390-
altitudeAccuracy: position.coords.altitudeAccuracy,
1391-
};
1392-
1386+
play: function() {
1387+
if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
1388+
localPosition.latitude = this.data.simulateLatitude;
1389+
localPosition.longitude = this.data.simulateLongitude;
13931390
if (this.data.simulateAltitude !== 0) {
13941391
localPosition.altitude = this.data.simulateAltitude;
13951392
}
1393+
this.currentCoords = localPosition;
1394+
this._updatePosition();
1395+
} else {
1396+
this._watchPositionId = this._initWatchGPS(function (position) {
1397+
var localPosition = {
1398+
latitude: position.coords.latitude,
1399+
longitude: position.coords.longitude,
1400+
altitude: position.coords.altitude,
1401+
accuracy: position.coords.accuracy,
1402+
altitudeAccuracy: position.coords.altitudeAccuracy,
1403+
};
1404+
1405+
if (this.data.simulateAltitude !== 0) {
1406+
localPosition.altitude = this.data.simulateAltitude;
1407+
}
13961408

1397-
if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
1398-
localPosition.latitude = this.data.simulateLatitude;
1399-
localPosition.longitude = this.data.simulateLongitude;
1400-
this.currentCoords = localPosition;
1401-
this._updatePosition();
1402-
} else {
14031409
this.currentCoords = localPosition;
14041410
var distMoved = this._haversineDist(
14051411
this.lastPosition,
@@ -1413,8 +1419,8 @@ AFRAME.registerComponent('gps-projected-camera', {
14131419
latitude: this.currentCoords.latitude
14141420
};
14151421
}
1416-
}
1417-
}.bind(this));
1422+
}.bind(this));
1423+
}
14181424
},
14191425

14201426
tick: function() {

aframe/build/aframe-ar-nft.js

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

aframe/build/aframe-ar.js

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

aframe/examples/location-based/max-min-distance/index.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99

1010
</head>
1111

12-
<body style='margin: 0; overflow: hidden;'>
12+
<body><!-- style='margin: 0; overflow: hidden;'>-->
1313
<a-scene
1414
vr-mode-ui="enabled: false"
15-
embedded
16-
arjs='sourceType: webcam; debugUIEnabled: false;'>
15+
arjs='sourceType: webcam; videoTexture: true; debugUIEnabled: false;'>
1716

1817
<!-- too near, is like 2m far -->
19-
<a-box material="color: red;" scale="15 15 15" gps-entity-place="latitude: 44.504493; longitude: 11.301134;"></a-box>
18+
<a-box material="color: red;" scale="25 25 25" gps-entity-place="latitude: 44.504493; longitude: 11.301134;"></a-box>
2019

2120
<!-- visible, is like 400m far -->
22-
<a-box material="color: yellow;" scale="15 15 15" gps-entity-place="latitude: 44.506477; longitude: 11.301524;"></a-box>
21+
<a-box material="color: yellow;" scale="25 25 25" gps-entity-place="latitude: 44.506477; longitude: 11.301524;"></a-box>
2322

2423
<!-- too far, is like 2.5km far -->
25-
<a-box material="color: green;" scale="15 15 15" gps-entity-place="latitude: 44.500013; longitude: 11.277351;"></a-box>
24+
<a-box material="color: green;" scale="25 25 25" gps-entity-place="latitude: 44.500013; longitude: 11.277351;"></a-box>
2625

2726
<a-camera
2827
rotation-reader

0 commit comments

Comments
 (0)