Class: LocationBased

LocationBased(scene, camera, options)

The main class for the LocAR.js system.

Constructor

new LocationBased(scene, camera, options)

Parameters:
Name Type 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.
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).
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

on(eventName, eventHandler)

Add an event handler. Currently-understood events: "gpsupdate" and "gpserror". The former fires when a GPS update is received, and is passed the standard Geolocation API position object, along with the distance moved since the last GPS update in metres. The latter fires when a GPS error is generated, and is passed the standard Geolocation API numerical error code.
Parameters:
Name Type Description
eventName string the event to handle.
eventHandler function the event handler function.
Source:
Listens to Events:

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:

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
code number the Geolocation API numerical error code.
Source:
Listeners of This Event:

gpsupdate

GPS update event.
Parameters:
Name Type Description
position object the Geolocation API position object.
distMoved number the distance moved in metres since the last GPS update.
Source:
Listeners of This Event: