Line layer (polyline helper)
Learn how to incorporate a line layer into your map by utilizing the polyline layer helper. This example shows how to add a line layer to the map using the polyline layer helper with the default values. To replicate this example, download the Amphitheater Lake trail sample data.
In this instance, the color is randomly selected from a predefined list of colors. This is the default action when no specific color is specified.
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: 14,
center: [-110.75926, 43.72683],
style: MapStyle.OUTDOOR
});
map.on('load', async function () {
await helpers.addPolyline(map, {
data: 'YOUR_MAPTILER_DATASET_ID_HERE',
outline: true,
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Line layer (polyline 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%;}
Related examples
Style a GeoJSON Line layer (polyline helper)
ExamplesStyle GeoJSON line layer using MapTiler polyline helper.
Line outline glow blur symbol (polyline helper)
ExamplesAdd glowing outline to line layer using helper.