MapSnippets logo MapSnippets logo

Add Markers and Popups with MapTiler SDK

MapTiler SDK

Place markers on a MapTiler SDK map with maptilersdk.Marker and attach an HTML info window to each one via setPopup() and maptilersdk.Popup.

progress_activity Loading map...
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
  container: 'map',
  style: maptilersdk.MapStyle.STREETS,
  center: [2.3522, 48.8566],
  zoom: 13
});
const places = [
  { coords: [2.2945, 48.8584], name: 'Eiffel Tower' },
  { coords: [2.3500, 48.8530], name: 'Notre-Dame' },
  { coords: [2.3376, 48.8606], name: 'Louvre Museum' }
];
places.forEach(p => {
  new maptilersdk.Marker({ color: '#9C27B0' })
    .setLngLat(p.coords)
    .setPopup(new maptilersdk.Popup({ offset: 25 }).setHTML(`<b>${p.name}</b>`))
    .addTo(map);
});

How to add a marker with a popup with MapTiler SDK

Create markers with new maptilersdk.Marker() and attach them to the map with .addTo(map). Each marker gets a position via .setLngLat([lng, lat]).

Popups are attached with .setPopup(). The popup opens when the user clicks the marker. The offset option prevents the popup from overlapping the marker pin.

Markers are DOM elements, so they support full HTML content and CSS styling.

Key APIs

API Description Docs
maptilersdk.Marker Create a DOM-based marker docs.maptiler.com/sdk-js/api/
maptilersdk.Popup Attach an information popup docs.maptiler.com/sdk-js/api/
.setLngLat() Set marker position docs.maptiler.com/sdk-js/api/

FAQ

How many DOM markers can I add before performance degrades?

Typically up to a few hundred. For thousands of points, use a GeoJSON source with symbol or circle layers instead of DOM markers.

Can I use a custom image instead of the default pin?

Yes. Pass an element option with a custom HTML element to the Marker constructor.

Common mistakes

  • Using [lat, lng] order. MapTiler SDK uses [lng, lat] like GeoJSON
  • Delaying marker creation until the map loads, although markers can be added immediately without waiting for load
  • Forgetting .addTo(map), so the marker is created but not displayed

Build maps using MapTiler SDK with AI

Generate code like this add markers and popups with maptiler sdk example using the MapTiler SDK skill in your IDE.