Constructor
new LocationBased(scene, camera, options, serverLogger)
Parameters:
Name | Type | Default | Description |
---|---|---|---|
scene |
THREE.Scene | The Three.js scene to use. | |
camera |
THREE.Camera | The Three.js camera to use. Should usually be a THREE.PerspectiveCamera. | |
options |
Object | Initialisation options for the GPS; see setGpsOptions() below. | |
serverLogger |
Object | null | an object which can optionally log GPS position to a server for debugging. null by default, so no logging will be done. This object should implement a sendData() method to send data (2nd arg) to a given endpoint (1st arg). Please see source code for details. Ensure you comply with privacy laws (GDPR or equivalent) if implementing this. |
- Source:
Methods
add(object, lon, lat, elev, properties)
Add a new AR object at a given latitude, longitude and elevation.
Parameters:
Name | Type | Description |
---|---|---|
object |
THREE.Mesh | the object |
lon |
number | the longitude. |
lat |
number | the latitude. |
elev |
number | the elevation in metres (if not specified, 0 is assigned) |
properties |
Object | properties describing the object (for example, the contents of the GeoJSON properties field). |
- Source:
fakeGps(lon, lat, elev, acc)
Send a fake GPS signal. Useful for testing on a desktop or laptop.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
lon |
number | The longitude. | |
lat |
number | The latitude. | |
elev |
number | null | The elevation in metres. (optional, set to null for no elevation). |
acc |
number | 0 | The accuracy of the GPS reading in metres. May be ignored if lower than the specified minimum accuracy. |
- Source:
lonLatToWorldCoords(lon, lat) → {Array}
Convert longitude and latitude to three.js/WebGL world coordinates.
Uses the specified projection, and negates the northing (in typical
projections, northings increase northwards, but in the WebGL coordinate
system, we face negative z if the camera is at the origin with default
rotation).
Must not be called until an initial position is determined.
Parameters:
Name | Type | Description |
---|---|---|
lon |
number | The longitude. |
lat |
number | The latitude. |
- Source:
Returns:
a two member array containing the WebGL x and z coordinates
- Type
- Array
setElevation(elev)
Set the elevation (y coordinate) of the camera.
Parameters:
Name | Type | Description |
---|---|---|
elev |
number | the elevation in metres. |
- Source:
setGpsOptions(object)
Set the GPS options.
Parameters:
Name | Type | Description |
---|---|---|
object |
Object | containing gpsMinDistance and/or gpsMinAccuracy properties. The former specifies the number of metres which the device must move to process a new GPS reading, and the latter specifies the minimum accuracy, in metres, for a GPS reading to be counted. |
- Source:
setProjection(any)
Set the projection to use.
Parameters:
Name | Type | Description |
---|---|---|
any |
Object | object which includes a project() method taking longitude and latitude as arguments and returning an array containing easting and northing. |
- Source:
(async) startGps() → {boolean}
Start the GPS on a real device
- Source:
Returns:
code indicating whether the GPS was started successfully.
GPS errors can be handled by handling the gpserror event.
- Type
- boolean
stopGps() → {boolean}
Stop the GPS on a real device
- Source:
Returns:
true if the GPS was stopped, false if it could not be
stopped (i.e. it was never started).
- Type
- boolean
Events
gpserror
GPS error event.
Parameters:
Name | Type | Description |
---|---|---|
error |
Object | the Geolocation API error object. |
- Source:
gpsupdate
GPS update event.
Parameters:
Name | Type | Description |
---|---|---|
event |
object | object containing 'position' -the Geolocation API position object and 'distMoved' - the distance moved in metres since the last GPS update. |
- Source: