Attach a popup to a marker instance

Attach a Popup to a Marker and display it when the user clicks on the Marker.

NPM module setup


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

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const monument = [-77.0353, 38.8895];
const map = new Map({
    container: 'map',
    style: MapStyle.STREETS, 
    center: monument,
    zoom: 15
});

// create the popup
const popup = new Popup({ offset: 25 }).setText(
    'Construction on the Washington Monument began in 1848.'
);

// create DOM element for the marker
const el = document.createElement('div');
el.id = 'marker';

// create the marker
new maptilersdk.Marker({element: el})
    .setLngLat(monument)
    .setPopup(popup) // sets a popup on this marker
    .addTo(map);
Display a popup on hover

Display a popup on hover

Examples

Show a popup when hovering over a custom marker.

Show polygon information on click

Show polygon information on click

Examples

Display a popup when a user clicks a polygon.

Weather custom popup

Weather custom popup

Examples

Create highly customizable popups for weather maps using MarkerLayout.

Display a popup

Display a popup

Examples

Add an information popup to the map.

Was this helpful?