Skip to content

Commit fa2c8ee

Browse files
fixed hide objects when minDistance is set
1 parent f78d99a commit fa2c8ee

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

aframe/build/aframe-ar.js

Lines changed: 28 additions & 7 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ AFRAME.registerComponent('gps-camera', {
9393
else {
9494
this.currentCoords = position.coords;
9595
}
96-
97-
96+
97+
9898
this._updatePosition();
9999
}.bind(this));
100100
},
@@ -245,7 +245,7 @@ AFRAME.registerComponent('gps-camera', {
245245
* @param {Position} dest
246246
* @param {Boolean} isPlace
247247
*
248-
* @returns {number} distance
248+
* @returns {number} distance | Number.MAX_SAFE_INTEGER
249249
*/
250250
computeDistanceMeters: function (src, dest, isPlace) {
251251
var dlongitude = THREE.Math.degToRad(dest.longitude - src.longitude);
@@ -256,7 +256,7 @@ AFRAME.registerComponent('gps-camera', {
256256
var distance = angle * 6378160;
257257

258258
// if function has been called for a place, and if it's too near and a min distance has been set,
259-
// set a very high distance to hide the object
259+
// return max distance possible - to be handled by the method caller
260260
if (isPlace && this.data.minDistance && this.data.minDistance > 0 && distance < this.data.minDistance) {
261261
return Number.MAX_SAFE_INTEGER;
262262
}

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ AFRAME.registerComponent('gps-entity-place', {
3434
latitude: this.data.latitude,
3535
};
3636

37-
var distance = this._cameraGps.computeDistanceMeters(ev.detail.position, dstCoords, true);
37+
// it's actually a 'distance place', but we don't call it with last param, because we want to retrieve distance even if it's < minDistance property
38+
var distance = this._cameraGps.computeDistanceMeters(ev.detail.position, dstCoords);
3839

3940
this.el.setAttribute('distance', distance);
4041
this.el.setAttribute('distanceMsg', formatDistance(distance));
@@ -60,6 +61,7 @@ AFRAME.registerComponent('gps-entity-place', {
6061
*/
6162
_updatePosition: function () {
6263
var position = { x: 0, y: this.el.getAttribute('position').y || 0, z: 0 }
64+
var hideEntity = false;
6365

6466
// update position.x
6567
var dstCoords = {
@@ -68,6 +70,12 @@ AFRAME.registerComponent('gps-entity-place', {
6870
};
6971

7072
position.x = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
73+
74+
// place has to be hide
75+
if (position.x === Number.MAX_SAFE_INTEGER) {
76+
hideEntity = true;
77+
}
78+
7179
this._positionXDebug = position.x;
7280

7381
position.x *= this.data.longitude > this._cameraGps.originCoords.longitude ? 1 : -1;
@@ -79,11 +87,24 @@ AFRAME.registerComponent('gps-entity-place', {
7987
};
8088

8189
position.z = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
90+
91+
// place has to be hide
92+
if (position.z === Number.MAX_SAFE_INTEGER) {
93+
hideEntity = true;
94+
}
95+
8296
position.z *= this.data.latitude > this._cameraGps.originCoords.latitude ? -1 : 1;
83-
if(position.y !== 0) {
97+
98+
if (position.y !== 0) {
8499
position.y = position.y - this._cameraGps.originCoords.altitude;
85100
}
86-
101+
102+
if (hideEntity) {
103+
this.el.setAttribute('visible', false);
104+
} else {
105+
this.el.setAttribute('visible', true);
106+
}
107+
87108
// update element's position in 3D world
88109
this.el.setAttribute('position', position);
89110
},

0 commit comments

Comments
 (0)