Skip to content

Commit

Permalink
Merge pull request #262 from nickw1/dev
Browse files Browse the repository at this point in the history
Allow minDistance and maxDistance to work with simulated GPS position
  • Loading branch information
nicolocarpignoli authored May 7, 2021
2 parents 9f4d3c2 + cb0b755 commit c6661e2
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 150 deletions.
78 changes: 42 additions & 36 deletions aframe/build/aframe-ar-location-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,25 +816,28 @@ AFRAME.registerComponent('gps-camera', {
},

play: function() {
this._watchPositionId = this._initWatchGPS(function (position) {
var localPosition = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
altitude: position.coords.altitude,
accuracy: position.coords.accuracy,
altitudeAccuracy: position.coords.altitudeAccuracy,
};

if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
localPosition.latitude = this.data.simulateLatitude;
localPosition.longitude = this.data.simulateLongitude;
if (this.data.simulateAltitude !== 0) {
localPosition.altitude = this.data.simulateAltitude;
}
this.currentCoords = localPosition;
this._updatePosition();
} else {
this._watchPositionId = this._initWatchGPS(function (position) {
var localPosition = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
altitude: position.coords.altitude,
accuracy: position.coords.accuracy,
altitudeAccuracy: position.coords.altitudeAccuracy,
};

if (this.data.simulateAltitude !== 0) {
localPosition.altitude = this.data.simulateAltitude;
}

if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
localPosition.latitude = this.data.simulateLatitude;
localPosition.longitude = this.data.simulateLongitude;
this.currentCoords = localPosition;
this._updatePosition();
} else {
this.currentCoords = localPosition;
var distMoved = this._haversineDist(
this.lastPosition,
Expand All @@ -848,8 +851,8 @@ AFRAME.registerComponent('gps-camera', {
latitude: this.currentCoords.latitude
};
}
}
}.bind(this));
}.bind(this));
}
},

tick: function () {
Expand Down Expand Up @@ -1017,7 +1020,7 @@ AFRAME.registerComponent('gps-camera', {
if (isPlace && this.data.maxDistance && this.data.maxDistance > 0 && distance > this.data.maxDistance) {
return Number.MAX_SAFE_INTEGER;
}

return distance;
},

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

play: function() {
this._watchPositionId = this._initWatchGPS(function (position) {
var localPosition = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
altitude: position.coords.altitude,
accuracy: position.coords.accuracy,
altitudeAccuracy: position.coords.altitudeAccuracy,
};

play: function() {
if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
localPosition.latitude = this.data.simulateLatitude;
localPosition.longitude = this.data.simulateLongitude;
if (this.data.simulateAltitude !== 0) {
localPosition.altitude = this.data.simulateAltitude;
}
this.currentCoords = localPosition;
this._updatePosition();
} else {
this._watchPositionId = this._initWatchGPS(function (position) {
var localPosition = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
altitude: position.coords.altitude,
accuracy: position.coords.accuracy,
altitudeAccuracy: position.coords.altitudeAccuracy,
};

if (this.data.simulateAltitude !== 0) {
localPosition.altitude = this.data.simulateAltitude;
}

if (this.data.simulateLatitude !== 0 && this.data.simulateLongitude !== 0) {
localPosition.latitude = this.data.simulateLatitude;
localPosition.longitude = this.data.simulateLongitude;
this.currentCoords = localPosition;
this._updatePosition();
} else {
this.currentCoords = localPosition;
var distMoved = this._haversineDist(
this.lastPosition,
Expand All @@ -1413,8 +1419,8 @@ AFRAME.registerComponent('gps-projected-camera', {
latitude: this.currentCoords.latitude
};
}
}
}.bind(this));
}.bind(this));
}
},

tick: function() {
Expand Down
78 changes: 42 additions & 36 deletions aframe/build/aframe-ar-nft.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 42 additions & 36 deletions aframe/build/aframe-ar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions aframe/examples/location-based/max-min-distance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@

</head>

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

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

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

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

<a-camera
rotation-reader
Expand Down
Loading

0 comments on commit c6661e2

Please sign in to comment.