Style a GeoJSON Line layer (polyline helper)
This example demonstrates the process of incorporating and customizing a GeoJSON line layer on the map by utilizing the polyline layer helper. In this specific case, we will generate a line that is purple and has a border in gray. You can access the sample data by downloading the Blue Hills sample data.
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: 13,
center: [-110.75926, 43.72683],
style: MapStyle.DATAVIZ.DARK
});
map.on('load', async function () {
await helpers.addPolyline(map, {
data: 'https://docs.maptiler.com/sdk-js/examples/helper-polyline-simple/blue_hills.geojson',
outline: true,
lineColor: "purple",
lineWidth: 6,
outlineColor: "#D3DBEC", // mid gray
outlineWidth: 10,
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Style a GeoJSON 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
Line outline glow blur symbol (polyline helper)
ExamplesAdd glowing outline to line layer using helper.