code
Snippet
language
CDN
package_2
NPM
content_copy
Copy
open_in_new
Open
const map = new maplibregl. Map ({
container: 'map' ,
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY' ,
center: [ 14.42 , 50.08 ],
zoom: 12
});
map. on ( 'load' , () => {
map. addSource ( 'route' , {
type: 'geojson' ,
data: { type: 'Feature' , geometry: { type: 'LineString' ,
coordinates: [[ 14.395 , 50.095 ], [ 14.410 , 50.088 ], [ 14.425 , 50.080 ], [ 14.445 , 50.075 ]] } }
});
map. addLayer ({
id: 'route-line' , type: 'line' , source: 'route' ,
layout: { 'line-join' : 'round' , 'line-cap' : 'round' },
paint: { 'line-color' : '#2196F3' , 'line-width' : 4 }
});
}); content_copy
Copy
open_in_new
Open
<! doctype html >
< html lang = "en" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title >Line Layers with MapLibre GL JS</ title >
< link rel = "stylesheet" href = "https://unpkg.com/maplibre-gl@6.16.0/dist/maplibre-gl.css" >
< style >
body { margin : 0 ; padding : 0 ; }
#map { width : 100 % ; height : 100 vh ; }
</ style >
</ head >
< body >
< div id = "map" ></ div >
< script type = "module" >
import * as maplibregl from 'https://unpkg.com/maplibre-gl@6.16.0/dist/maplibre-gl.mjs' ;
const map = new maplibregl. Map ({
container: 'map' ,
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY' ,
center: [ 14.42 , 50.08 ],
zoom: 12
});
map. on ( 'load' , () => {
map. addSource ( 'route' , {
type: 'geojson' ,
data: { type: 'Feature' , geometry: { type: 'LineString' ,
coordinates: [[ 14.395 , 50.095 ], [ 14.410 , 50.088 ], [ 14.425 , 50.080 ], [ 14.445 , 50.075 ]] } }
});
map. addLayer ({
id: 'route-line' , type: 'line' , source: 'route' ,
layout: { 'line-join' : 'round' , 'line-cap' : 'round' },
paint: { 'line-color' : '#2196F3' , 'line-width' : 4 }
});
});
</ script >
</ body >
</ html > content_copy
Copy
open_in_new
Open
import maplibregl from 'maplibre-gl' ;
import 'maplibre-gl/dist/maplibre-gl.css' ;
const map = new maplibregl. Map ({
container: 'map' ,
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY' ,
center: [ 14.42 , 50.08 ],
zoom: 12
});
map. on ( 'load' , () => {
map. addSource ( 'route' , {
type: 'geojson' ,
data: { type: 'Feature' , geometry: { type: 'LineString' ,
coordinates: [[ 14.395 , 50.095 ], [ 14.410 , 50.088 ], [ 14.425 , 50.080 ], [ 14.445 , 50.075 ]] } }
});
map. addLayer ({
id: 'route-line' , type: 'line' , source: 'route' ,
layout: { 'line-join' : 'round' , 'line-cap' : 'round' },
paint: { 'line-color' : '#2196F3' , 'line-width' : 4 }
});
});
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [14.42, 50.08],
zoom: 12
});
map.on('load', () => {
map.addSource('route', {
type: 'geojson',
data: { type: 'Feature', geometry: { type: 'LineString',
coordinates: [[14.395, 50.095], [14.410, 50.088], [14.425, 50.080], [14.445, 50.075]] } }
});
map.addLayer({
id: 'route-line', type: 'line', source: 'route',
layout: { 'line-join': 'round', 'line-cap': 'round' },
paint: { 'line-color': '#2196F3', 'line-width': 4 }
});
}); <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Line Layers with MapLibre GL JS</title>
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@6.16.0/dist/maplibre-gl.css">
<style>
body { margin: 0; padding: 0; }
#map { width: 100%; height: 100vh; }
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
import * as maplibregl from 'https://unpkg.com/maplibre-gl@6.16.0/dist/maplibre-gl.mjs';
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [14.42, 50.08],
zoom: 12
});
map.on('load', () => {
map.addSource('route', {
type: 'geojson',
data: { type: 'Feature', geometry: { type: 'LineString',
coordinates: [[14.395, 50.095], [14.410, 50.088], [14.425, 50.080], [14.445, 50.075]] } }
});
map.addLayer({
id: 'route-line', type: 'line', source: 'route',
layout: { 'line-join': 'round', 'line-cap': 'round' },
paint: { 'line-color': '#2196F3', 'line-width': 4 }
});
});
</script>
</body>
</html> import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [14.42, 50.08],
zoom: 12
});
map.on('load', () => {
map.addSource('route', {
type: 'geojson',
data: { type: 'Feature', geometry: { type: 'LineString',
coordinates: [[14.395, 50.095], [14.410, 50.088], [14.425, 50.080], [14.445, 50.075]] } }
});
map.addLayer({
id: 'route-line', type: 'line', source: 'route',
layout: { 'line-join': 'round', 'line-cap': 'round' },
paint: { 'line-color': '#2196F3', 'line-width': 4 }
});
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Line Layers with MapLibre GL JS</title>
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@6.16.0/dist/maplibre-gl.css">
<style>
body { margin: 0; padding: 0; }
#map { width: 100%; height: 100vh; }
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
import * as maplibregl from 'https://unpkg.com/maplibre-gl@6.16.0/dist/maplibre-gl.mjs';
window.maplibregl = maplibregl;
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=LKv9WPh4aJggV1CHU4Y8',
center: [14.42, 50.08],
zoom: 12
});
map.on('load', () => {
map.addSource('route', {
type: 'geojson',
data: { type: 'Feature', geometry: { type: 'LineString',
coordinates: [[14.395, 50.095], [14.410, 50.088], [14.425, 50.080], [14.445, 50.075]] } }
});
map.addLayer({
id: 'route-line', type: 'line', source: 'route',
layout: { 'line-join': 'round', 'line-cap': 'round' },
paint: { 'line-color': '#2196F3', 'line-width': 4 }
});
});
</script>
</body>
</html>