How to trigger actions in the AR control

Learn how to activate functions in the Augmented reality (AR) control by utilizing the keyboard. This method will enable you to generate a three-dimensional viewport model through augmented reality (AR), which includes not only a 3D terrain but also any additional layers you have incorporated. This feature is compatible with both WebXR and Apple Quick Look platforms.

NPM module setup


npm install --save @maptiler/sdk @maptiler/ar-control
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';
import { MaptilerARControl } from '@maptiler/ar-control';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';

// Creating a map
const map = new Map({
  container: 'map',
  style: MapStyle.SATELLITE,
  zoom: 12,
  center: [-116.22335, 51.4117],
});

// Waiting for the map to be ready
map.on("load", (e) => {
  const arControl = new MaptilerARControl({
    showButton: false,
  });

  document.addEventListener('keypress', async (event) => {
    console.log(event.key);

    if (event.key === "a") {
      await arControl.run()
    }

    if (event.key === "q") {
      try{
        await arControl.close();
      } catch(e) {}
    }

  }, false);

  arControl.on("computeStart", (e) => {
    overlay.style.display = "inherit";
  })

  arControl.on("computeEnd", (e) => {
    overlay.style.display = "none";
  })

  map.addControl(arControl, "top-left");
})
Customize the AR experience.

Custom AR experience

Examples

Customize the appearance of the augmented reality map control.

Add GeoJSON to AR maps

Add GeoJSON to AR maps

Examples

Display GeoJSON biking or hiking routes in AR maps.

Getting started with AR maps: Display an AR control on your maps

Start with AR maps

Examples

Add an AR control button to map 3D viewports.

Include a QR code to access your augmented reality (AR) maps on a mobile device

QR code to access AR maps

Examples

Provide a QR code to access mobile AR maps.

Was this helpful?