Polygon layer (polygon helper)

This example shows the process of incorporating a layer of polygons onto the map by utilizing the polygon layer helper and its default settings. Download the Swiss sample data.

In this particular case, the color is assigned at random from a predetermined list of colors. This is the default behavior taken when a specific color is not designated.

NPM module setup


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

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    zoom: 6.62,
    center: [8.224, 46.823],
    style: MapStyle.STREETS.LIGHT
});

map.on('load', async function () {
  await helpers.addPolygon(map, {
    data: 'YOUR_MAPTILER_DATASET_ID_HERE',
    fillOpacity: 0.5,
  });
});
Polygon fill pattern (polygon helper)

Polygon fill pattern (polygon helper)

Examples

Add fill pattern to polygon layer using helper.

Polygon color ramp symbol (polygon helper)

Polygon color ramp symbol (polygon helper)

Examples

Style polygon fill color based on zoom level.

Show polygon data from GeoJSON on the map

GeoJSON polygon layer

Tutorials

Add GeoJSON polygon overlay to your web map application.

Show polygon information on click

Show polygon information on click

Examples

Display a popup when a user clicks a polygon.

Was this helpful?