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,
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Polygon layer (polygon helper) | NPM example</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="map"></div>
<script type="module" src="./main.js"></script>
</body>
</html>
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}