locar
    Preparing search index...

    Class LocAR

    The main engine class for the LocAR.js system. Can be obtained either via App.start() - which resolves with a LocAR object - or on its own. If you use this class without App, you must set up the three.js scene yourself, as you did with locar.js 0.1.x.

    Hierarchy (View Summary)

    Index
    • Parameters

      • scene: Scene

        The Three.js scene to use.

      • camera: Camera

        The Three.js camera to use. Should usually be a THREE.PerspectiveCamera.

      • options: GpsOptions = {}

        Initialisation options for the GPS; see setGpsOptions() below.

      • serverLogger: ServerLogger | null = 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.

      • projection: Projection = ...

      Returns LocAR

    camera: Camera
    eventHandlers: Record<string, ((...args: any[]) => void)[]>
    scene: Scene
    • Add a new AR object at a given latitude, longitude and elevation.

      Parameters

      • object: Object3D

        the object

      • lon: number

        the longitude.

      • lat: number

        the latitude.

      • Optionalelev: number

        the elevation in metres (if not specified, 0 is assigned)

      • properties: Record<string, any> = {}

        properties describing the object (for example, the contents of the GeoJSON properties field).

      Returns void

    • Add a new triangle-strip based polyline to LocAR, defined by an array of points. Each point is a three-member array contaning longitude, latitude and optional altitude.

      Parameters

      • points: [number, number, number?][]

        the array of points

      • material: Material

        the material to use

      • lineWidth: number = 1

        line width in world units (default 1)

      Returns Mesh

      • mesh containing the polyline
    • Create a new triangle-strip based polyline geometry, defined by an array of points. Each point is a three-member array contaning longitude, latitude and optional altitude. This method simply projects the coordinates and creates the geometry, it does not create a mesh.

      Parameters

      • points: [number, number, number?][]

        the array of points

      • lineWidth: number = 1

        line width in world units (default 1)

      Returns BufferGeometry

      • the created geometry
    • Convert projected east/north coordinates to three.js/WebGL world coordinates. 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. It is assumed that the projected position is in the correct projection - no check for this is made.

      Parameters

      • projectedPos: [number, number]

        the projected position.

      Returns [number, number]

      a two member array containing the WebGL x and z coordinates

    • Send a fake GPS signal. Useful for testing on a desktop or laptop.

      Parameters

      • lon: number

        The longitude.

      • lat: number

        The latitude.

      • elev: number | null = 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.

      Returns void

    • Obtain the last known GPS location.

      Returns LonLat | null

      object containing latitude and longitude fields, or null if no previous GPS location.

    • 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

      • lon: number

        The longitude.

      • lat: number

        The latitude.

      Returns [number, number]

      a two member array containing the WebGL x and z coordinates

    • Remove an event handler.

      Parameters

      • eventName: string

        the event to remove a handler from.

      • eventHandler: (...args: any[]) => void

        the event handler function to remove.

      Returns void

    • Add an event handler.

      Parameters

      • eventName: string

        the event to handle.

      • eventHandler: (...args: any[]) => void

        the event handler function.

      Returns void

    • Set the elevation (y coordinate) of the camera.

      Parameters

      • elev: number

        the elevation in metres.

      Returns void

    • Start the GPS on a real device

      Returns Promise<boolean>

      code indicating whether the GPS was started successfully. GPS errors can be handled by handling the gpserror event.

    • Stop the GPS on a real device

      Returns boolean

      true if the GPS was stopped, false if it could not be stopped (i.e. it was never started).

    • Calculate haversine distance between two lat/lon pairs.

      Taken from original A-Frame AR.js location-based components

      Parameters

      Returns number