Options
All
  • Public
  • Public/Protected
  • All
Menu

Introduction to the Pointerra 3D Viewer JavaScript API

The Pointerra 3D Viewer JavaScript API is a JavaScript library that enables viewing of point clouds (and other reality capture data) hosted within the Pointerra service on any HTML5 web page. Although there is no licensing required to use the library, access control is maintained via API tokens - so you will require a valid Pointerra account (with a corresponding API token) to load data or utilise the functionality of the viewer.

Quick Start Example

To load the viewer, you simply need to include the loader script from:

https://static.pointerra.io/viewer/js/pointerra-client.js

The loader script will allow you to create an instance of the viewer. By default, it will query the Pointerra service and determine the current production viewer viewer to instantiate (you can override this with a specific version number if desired)

This example shows how to create (an empty) Pointerra viewer component on a web page hosted by your own web server (assumed to be localhost running on port 8080 in this example)

Get a web server (IIS, nodejs, etc) running on localhost, port 8080.

Create minimal.html as

<html lang="en">
<head>
    <meta charset="utf-8" />
    <script type="text/javascript" src="https://static.pointerra.io/viewer/js/pointerra-client.js"></script>

    <style>
        body {
            font-family: 'Open Sans', sans-serif;
            background: #eee;
            color: #333;
            padding: 0;
            margin: 0;
            font-size: 14px;
        }

        .pointerra-viewer {
            position: relative;
            margin: 10vh 20vw;
            width: 60vw;
            height: 60vh;
        }
    </style>
</head>

<body>
    <div id="pointerra-viewer" tabindex="0" class="pointerra-viewer"> </div>

    <script>
        pointerra.loadClient({
            targetElement: "#pointerra-viewer",
            pointerraAccessToken: "<YOUR_API_KEY>",
        })
    </script>
</body>
</html>

Run your web server and navigate to http://localhost:8080/minimal.html. This should create an empty 3D viewer inside the specified target element (#pointerra-viewer).

Viewer Creation

To create a viewer instance (and the corresponding API instance), you need to specify an element (normally a div) to host the viewer, and then call pointerraClient.create(options)

On success, the creation method returns a promise to the core API object. If there is an error in creating the viewer, then a null object will be returned.

let api = null
pointerra.loadClient({
    targetElement: "#pointerra-viewer",
    pointerraAccessToken: "<YOUR_API_KEY>"
}).then(pointerraApi => {
    api = pointerraApi
})

Required Creation Options

A full list of the options that can be passed into the creation function can be found in the IClientOptions interface documentation

As per the sample code above, the following properties are mandatory when using the API:

Using JSON Web Token Authentication

Authentication to the Pointerra service can be through the use of an API Key, or by providing an instance of the Pointerra JWT helper. Using JWT for authentication means that you do not need to risk exposing your API key - instead requiring users to provide credentials by logging in with their Pointerra username and password.

Using JWT also allows your session to operate in the context of the logged in user (i.e. with their access permissions) and is the recommended way to authenticate. The helper has a built in login UI, or you can handle this yourself. Below is a minimal viewer example that uses the JWT authentication. There is also an NPM module available for the JWT helper.

<html lang="en">
<head>
    <meta charset="utf-8" />
    <script type="text/javascript" src="https://static.pointerra.io/viewer/js/pointerra-client.js"></script>
    <script type="text/javascript" src="https://static.pointerra.io/viewer/js/jwt.js"></script>

    <style>
        body {
            font-family: 'Open Sans', sans-serif;
            background: #eee;
            color: #333;
            padding: 0;
            margin: 0;
            font-size: 14px;
        }

        .pointerra-viewer {
            position: relative;
            margin: 10vh 20vw;
            width: 60vw;
            height: 60vh;
        }
    </style>
</head>

<body>
    <div id="pointerra-viewer" tabindex="0" class="pointerra-viewer"> </div>

    <script>
        pointerra.loadClient({
            targetElement: "#pointerra-viewer",
            jwt: PointerraJWT,
        })
    </script>
</body>
</html>

Loading Plugins (Full Initialisation Example)

This example shows how to initialise the viewer with full plugin support. Plugins will be required if you need to view more than just a basic point cloud. This includes any of the following:

  • Overview map
  • Datasets (vectors, images, CAD, ewc)
  • Scanview
  • 360 Imagery

In the code below, take note of the additional plugin property passed into the loadClient options. If you know that you won't be using the functionality from any particular plugin (e.g. you don't require the overview map window because you are providing your own 2D map), then you could omit it from your code.

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8" />
    <script type="text/javascript" src="https://static.pointerra.io/viewer/js/pointerra-client.js"></script>
    <script type="text/javascript" src="https://static.pointerra.io/viewer/js/jwt.js"></script>

    <style>
        body {
            font-family: 'Open Sans', sans-serif;
            background: #eee;
            color: #333;
            padding: 0;
            margin: 0;
            font-size: 14px;
        }

        .pointerra-viewer-container {
            position: relative;
            margin: 20vh 20vw;
            width: 60vw;
            height: 60vh;
        }
    </style>
</head>

<body>
    <div id="pointerra-viewer" class="pointerra-viewer-container" tabindex="0"> </div>

    <script>
        let api = null
        pointerra.loadClient({
            targetElement: "#pointerra-viewer",
            jwt: PointerraJWT,
            plugins: [
                pointerra.Plugins.LeafletMap('https://tileserver.pointerra.io'),
                pointerra.Plugins.Datasets(),
                pointerra.Plugins.PanoViewer(),
                pointerra.Plugins.PhotosViewer(),
                pointerra.Plugins.SphericalImages()
            ],
            pointcloudId: <your_pointcloud_id>,
            viewer: {
                enableTools: true
            }
        }).then((pointerraApi) => {
            api = pointerraApi
        })
    </script>
</body>
</html>

API Namespaces

Methods and events within the API are organised into namespaces, based on key areas of functionality. Example namespaces within the API include; bookmark, poi, scene, etc. Each namespace is attached as a property to the api, and has its own section within this documentation.

For example, to get the set the background color for the viewer, you would use the setBackgroundColor() method from the viewer API:

api.viewer.setBackgroundColor('#ff0000')

There are a small number of utility methods and properties that are not in a namespace. These are documented in the ApiBase section. For example, to obtain all of the options that were passed in during viewer creation:

const creationoptions = api.options

Subscribing to Events

The viewer component makes extensive use of events to communicate changes in state to the host JavaScript environment. To listen for a specific event, you should add an event listener as follows:

api.[namespace].[event_name].addEventListener((event_data) => {
  // Do work here.
})

For example, to listen for changes to the camera location and pose, you would subscribe to the cameraChanged event in the scene namespace:

api.scene.events.cameraChanged.addEventListener((cameraData) => {
    // Do something with new camera location...
})

The available events and the data supplied to the handler functions are listed in the relevant namespace API documentation sections.

Index

Type aliases

ColourByType

ColourByType: "RGB" | "INTENSITY" | "COLOURED_INTENSITY" | "CLASSIFICATION" | "CLASSIFICATION_INTENSITY" | "HEIGHT" | "HEIGHT_INTENSITY" | "LAYER"

DatasetInfo

DatasetInfo: { dataset_id: string; name: string; type: string }

Type declaration

  • dataset_id: string
  • name: string
  • type: string

ScanViewScanMarkerOptions

ScanViewScanMarkerOptions: { cullByDistance?: boolean; distanceMeters?: number; maxVisible?: number; scaleByDistance?: boolean }

Type declaration

  • Optional cullByDistance?: boolean
  • Optional distanceMeters?: number
  • Optional maxVisible?: number
  • Optional scaleByDistance?: boolean

Variables

PointSizing

PointSizing: PointSizing

Object literals

Const DEFAULT_EXPORT_OPTIONS

DEFAULT_EXPORT_OPTIONS: object

heights

heights: "default" = "default"

Const DisplayUnitsData

DisplayUnitsData: object

Centimeters

Centimeters: DisplayUnitsInfo = new DisplayUnitsInfo( 'cm', 0.01, 1 )

Feet

Feet: DisplayUnitsInfo = new DisplayUnitsInfo( 'ft', 0.3048, 2)

Feet_US

Feet_US: DisplayUnitsInfo = new DisplayUnitsInfo( 'ftUS', 1200 / 3937, 2)

Inches

Inches: DisplayUnitsInfo = new DisplayUnitsInfo( 'in', 0.0254, 1)

Meters

Meters: DisplayUnitsInfo = new DisplayUnitsInfo( 'm', 1.0, 3 )

Millimeters

Millimeters: DisplayUnitsInfo = new DisplayUnitsInfo( 'mm', 0.001, 0 )

Yards

Yards: DisplayUnitsInfo = new DisplayUnitsInfo( 'yd', 0.9144, 3)

Yards_US

Yards_US: DisplayUnitsInfo = new DisplayUnitsInfo( 'ydUS', 3600 / 3937, 3)

Let defaultClientOptions

defaultClientOptions: object

apiAddress

apiAddress: string = "https://app.pointerra.io/api"

bootstrapped

bootstrapped: true = true

enableEdgeEnhancement

enableEdgeEnhancement: true = true

enableSSAO

enableSSAO: false = isMobileDevice() ? false : false

enableScreenshots

enableScreenshots: false = false

jwt

jwt: null = null

plugins

plugins: null = null

pointerraAccessToken

pointerraAccessToken: null = null

renderQuality

renderQuality: string = "NORMAL"

scanId

scanId: null = null

sceneProperties

sceneProperties: {}

Type declaration

showBasemap

showBasemap: false = false

staticFilesPrefix

staticFilesPrefix: string = ""

targetElement

targetElement: string = "#pointerra-viewer"

viewerProperties

viewerProperties: {}

Type declaration

wasmPrefix

wasmPrefix: null = null

workerPrefix

workerPrefix: null = null

bookmarks

bookmarks: object

allowEdit

allowEdit: true = true

drawings

drawings: object

allowEdit

allowEdit: true = true

allowExport

allowExport: true = true

features

features: object

streetView

streetView: true = true

initialViewRect

initialViewRect: object

east

east: number = 155

north

north: number = -7.0

south

south: number = -45.0

west

west: number = 110

measurements

measurements: object

allowEdit

allowEdit: true = true

allowExport

allowExport: true = true

poi

poi: object

allowEdit

allowEdit: true = true

allowExport

allowExport: true = true

showPropertiesWhenClicked

showPropertiesWhenClicked: true = true

viewer

viewer: object

allowedTools

allowedTools: null = null

disableContextMenus

disableContextMenus: false = false

disableKeyboardCommands

disableKeyboardCommands: false = false

disallowedTools

disallowedTools: null = null

displayUnits

displayUnits: METERS = DisplayUnits.METERS

enableFullscreen

enableFullscreen: true = true

enableTools

enableTools: true = true

minimiseLeftPanel

minimiseLeftPanel: false = false

reverseMouseWheelScroll

reverseMouseWheelScroll: false = false

showBookmarksPanel

showBookmarksPanel: true = true

showClassificationsPanel

showClassificationsPanel: true = true

showCloseButton

showCloseButton: false = false

showDrawingLayersPanel

showDrawingLayersPanel: true = true

showFullscreenButton

showFullscreenButton: true = true

showHomeButton

showHomeButton: true = true

showLayersPanel

showLayersPanel: true = true

showLeftPanel

showLeftPanel: true = true

showMessages

showMessages: true = true

showMousePosition

showMousePosition: true = true

showOptionsButton

showOptionsButton: true = true

showPointsOfInterestPanel

showPointsOfInterestPanel: true = true

showSearchButton

showSearchButton: true = true

showVisibilityButton

showVisibilityButton: true = true

startFullscreen

startFullscreen: false = false

theme

theme: string = "Dark"

useAnimatedZooming

useAnimatedZooming: false = false