Ready event

The ready event happens just after the load event but waits until all the controls managed by the Map constructor are dealt with, some having an asynchronous logic to set up.

Since the ready event waits until all the basic controls are nicely positioned, it is safer to use ready than load if you plan to add other custom controls with the .addControl() method.

In this example, we will wait for the ready event to add the terrain control to the map.

NPM module setup


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

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.OUTDOOR,
    center: [-77.60308, -9.1135],
    zoom: 12.32,
});
// Set an event listener that fires
// when the map has finished loading.
map.on('ready', function () {
  console.log('A ready event occurred.');
  const terrainControl = new maptilersdk.MaptilerTerrainControl();
  map.addControl(terrainControl);
});
Display a 3D terrain map

3D terrain map

Tutorials

Create and display 3D terrain maps on web pages.

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.

View a fullscreen map

View a fullscreen map

Examples

Toggle between the current map view and fullscreen mode.

Hide map navigation controls

Hide map navigation controls

Tutorials

Hide the map navigation and zoom controls.

Was this helpful?