Add a GPX Line layer (polyline helper)
Learn how to incorporate a GPX line layer into your map by utilizing the polyline layer helper in this illustrative example. To replicate this example, download the GPX run 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: 14.5,
center: [-77.01801, 38.92368],
style: MapStyle.DATAVIZ.DARK
});
map.on('load', async function () {
await helpers.addPolyline(map, {
data: 'https://docs.maptiler.com/sdk-js/examples/helper-polyline-gpx/run.gpx',
outline: true
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<title>Add a GPX 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%;}