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

This example shows how to make a map with pins to display a point layer from a MapTiler Tileset using a custom PNG icon.

Download the underground sample icon, The icon is from the Maps Icons Collection.

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.BASE,
  center: [-73.9066, 40.7314], // starting position [lng, lat]
  zoom: 10.21, // starting zoom
});

map.on('load', async function() {
    const image = await map.loadImage('./underground.png');

    map.addImage('pinMetro', image.data);

    map.addSource('points', {
      type: 'vector',
      url: "https://api.maptiler.com/tiles/9537e49b-39c3-43ce-a6b9-9cf3d26b6d93/tiles.json"
    });

    map.addLayer({
      'id': 'points',
      'type': 'symbol',
      'source': 'points',
      'source-layer': 'stations',
      'layout': {
        'icon-image': 'pinMetro',
        'icon-size': ['*', ['get', 'scalerank'] ,0.01]
      },
      'paint': {}
    });

  });

Replace YOUR_MAPTILER_API_KEY_HERE with your own API key. Make sure to secure the key before you publish it.

Replace YOUR_MAPTILER_TILESET_ID_HERE with your actual MapTiler Tileset ID.

Replace YOUR_TILESET_LAYER_HERE with your actual Layer ID. How to get the Layer ID.

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 custom icons with markers

Add custom icons with markers

Examples

Add custom marker icons to your map.

Show point data from GeoJSON on the map

GeoJSON point layer

Tutorials

Add a GeoJSON point overlay to your map application.

Add an icon to the map

Add an icon to the map

Examples

Add icons from external URLs to symbol map layers.

Was this helpful?