Add an icon to the map

Add an icon onto the map by utilizing an external URL and incorporate it into a symbol layer as specified in the style specification for layers.

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.STREETS,
  center: [0, 0],
  zoom: 2,
});

map.on("load", async function () {
  const image = await map.loadImage(
    "https://upload.wikimedia.org/wikipedia/commons/7/7c/201408_cat.png",
  );

  map.addImage("cat", image.data);
  map.addSource("point", {
    type: "geojson",
    data: {
      type: "FeatureCollection",
      features: [
        {
          type: "Feature",
          geometry: {
            type: "Point",
            coordinates: [0, 0],
          },
        },
      ],
    },
  });
  map.addLayer({
    id: "points",
    type: "symbol",
    source: "point",
    layout: {
      "icon-image": "cat",
      "icon-size": 0.25,
    },
  });
});
Add custom icons with markers

Add custom icons with markers

Examples

Add custom marker icons to your map.

How to add a custom icon (PNG) to a point layer

Add custom icon (PNG) to a point layer

Examples

Display a point layer using custom PNG icons.

How to add a custom icon (SVG) to a point layer

Add custom icon (SVG) to a point layer

Examples

Display a point layer using custom SVG icons.

Add an animated icon to the map

Add an animated icon to the map

Examples

Add animated icons generated at runtime using Canvas API.

Was this helpful?