---
title: "Ready event | JavaScript maps SDK"
description: "Use the ready event to safely add custom controls."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# 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

```bash
npm install --save @maptiler/sdk
```

#### main.js

```js
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);
});
```

#### index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="robots" content="noindex">
  <title>Ready event | NPM example | MapTiler SDK JS</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
  <div id="map"></div>
  <script type="module" src="./main.js"></script>
</body>
</html>
```

#### style.css

```css
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}
```

### Basic JavaScript setup

```html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ready event</title>
<script src="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.umd.min.js"></script>
<link href="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.css" rel="stylesheet" />
<style>
  body {margin: 0; padding: 0;}
  #map {position: absolute; top: 0; bottom: 0; width: 100%;}
</style>
</head>
<body>
<div id="map"></div>
<script>
    maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
    const map = new maptilersdk.Map({
        container: 'map',
        style: maptilersdk.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);
    });
</script>
</body>
</html>
```

## Related examples

### [3D terrain map](https://docs.maptiler.com/sdk-js/examples/3d-map/)

Tutorials

Create and display 3D terrain maps on web pages.

### [Start with AR maps](https://docs.maptiler.com/sdk-js/examples/ar-control/)

Examples

Add an AR control button to map 3D viewports.

### [View a fullscreen map](https://docs.maptiler.com/sdk-js/examples/fullscreen/)

Examples

Toggle between the current map view and fullscreen mode.

### [Hide map navigation controls](https://docs.maptiler.com/sdk-js/examples/navigation/)

Tutorials

Hide the map navigation and zoom controls.
