TrackAsia GL JS

Current version: v1.0.5

  • Custom map styles
  • Fast vector maps
  • Compatible with other TrackAsia tools

TrackAsia GL JS is a TypeScript library that uses WebGL2 to render interactive maps from vector tiles in a browser.

Quickstart

Include the JavaScript and CSS files in the <head> of your HTML file.

<script src='https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.js'></script>
<link href='https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.css' rel='stylesheet' />

Include the following code in the <body> of your HTML file.

<div id='map' style='width: 400px; height: 300px;'></div>
<script>
var map = new trackasiagl.Map({
container: 'map',
style: 'https://maps.track-asia.com/styles/v1/streets.json?key=public_key', // stylesheet location
center: {"lat":10.762622,"lng":106.660172}, // starting position
zoom: 6 // starting zoom
});
</script>

Reading this documentation

This documentation is divided into several sections:

  • Map. The Map object is the map on your page. It lets you access methods and properties for interacting with the map's style and layers, respond to events, and manipulate the user's perspective with the camera.
  • Properties and options. This section describes TrackAsia GL JS's global properties and options that you might want to access while initializing your map or accessing information about its status.
  • Markers and controls. This section describes the user interface elements that you can add to your map. The items in this section exist outside of the map's canvas element.
  • Geography and geometry. This section includes general utilities and types that relate to working with and manipulating geographic information or geometries.
  • User interaction handlers. The items in this section relate to the ways in which the map responds to user input.
  • Sources. This section describes the source types TrackAsia GL JS can handle besides the ones described in the TrackAsia Style Specification.
  • Events. This section describes the different types of events that TrackAsia GL JS can raise.

Each section describes classes or objects as well as their properties, parameters, instance members, and associated events. Many sections also include inline code examples and related resources.

In the examples, we use vector tiles from MapTiler. Get your own API key if you want to use MapTiler data in your project.

CSP Directives

As a mitigation for Cross-Site Scripting and other types of web security vulnerabilities, you may use a Content Security Policy (CSP) to specify security policies for your website. If you do, TrackAsia GL JS requires the following CSP directives:

worker-src blob: ;
child-src blob: ;
img-src data: blob: ;

Requesting styles from Mapbox or other services will require additional directives. For Mapbox, you can use this connect-src directive:

connect-src https://*.tiles.mapbox.com https://api.mapbox.com https://events.mapbox.com

For strict CSP environments without worker-src blob: ; child-src blob: enabled, there's a separate TrackAsia GL JS bundle (trackasia-gl-csp.js and trackasia-gl-csp-worker.js) which requires setting the path to the worker manually:

<script src='https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl-csp.js'></script>
<script>
trackasiagl.workerUrl = "https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl-csp-worker.js";
...
</script>

TrackAsia CSS

The CSS referenced in the Quickstart is used to style DOM elements created by TrackAsia code. Without the CSS, elements like Popups and Markers won't work.

Including it with a <link> in the head of the document via the UNPKG CDN is the simplest and easiest way to provide the CSS, but it is also bundled in the TrackAsia module, meaning that if you have a bundler that can handle CSS, you can import the CSS from trackasia-gl/dist/trackasia-gl.css.

Note too that if the CSS isn't available by the first render, as soon as the CSS is provided, the DOM elements that depend on this CSS should recover.

Dependencies

The dependencies for TrackAsia GL JS (.js & .css) are distributed via UNPKG.com. UNPKG can distribute a fixed version, a semver range, a tag, or omit the version/tag entirely to use the latest tag.

You can view a listing of all the files in the TrackAsia GL JS package by appending a / at the end of the TrackAsia slug. This is useful to review other revisions or to review the files at UNPKG or the LICENSE. See https://unpkg.com/trackasia-gl/

Examples

Use Case.js.css
latest
https://unpkg.com/trackasia-gl/dist/trackasia-gl.js
https://unpkg.com/trackasia-gl/dist/trackasia-gl.css
Use a fixed version
https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.js
https://unpkg.com/trackasia-gl@1.0.5/dist/trackasia-gl.css
Use at least 1.0.xhttps://unpkg.com/trackasia-gl@^1.0/dist/trackasia-gl.jshttps://unpkg.com/trackasia-gl@^1.0/dist/trackasia-gl.css
metadata: sizehttps://unpkg.com/trackasia-gl/dist/trackasia-gl.js?metahttps://unpkg.com/trackasia-gl/dist/trackasia-gl.css?meta