code Snippetlanguage CDNpackage_2 NPM
content_copy Copyopen_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: [ 15 , 50 ],
zoom: 6
});
map. on ( 'load' , () => {
const cities = { type: 'FeatureCollection' , features: [
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 14.42 , 50.08 ] }, properties: { name: 'Prague' , pop: 1300 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 16.61 , 49.20 ] }, properties: { name: 'Brno' , pop: 380 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 18.26 , 49.82 ] }, properties: { name: 'Ostrava' , pop: 290 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 15.05 , 50.77 ] }, properties: { name: 'Liberec' , pop: 105 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 13.38 , 49.74 ] }, properties: { name: 'Plzen' , pop: 175 } }
] };
map. addSource ( 'cities' , { type: 'geojson' , data: cities });
map. addLayer ({ id: 'city-circles' , type: 'circle' , source: 'cities' , paint: {
'circle-radius' : [ 'interpolate' , [ 'linear' ], [ 'get' , 'pop' ], 100 , 6 , 500 , 14 , 1300 , 24 ],
'circle-color' : [ 'interpolate' , [ 'linear' ], [ 'get' , 'pop' ], 100 , '#2196F3' , 700 , '#FF9800' , 1300 , '#F44336' ],
'circle-stroke-width' : 2 , 'circle-stroke-color' : '#fff'
} });
map. addLayer ({ id: 'city-labels' , type: 'symbol' , source: 'cities' ,
layout: { 'text-field' : [ 'get' , 'name' ], 'text-font' : [ 'Noto Sans Regular' ], 'text-size' : 12 , 'text-offset' : [ 0 , 1.5 ], 'text-anchor' : 'top' },
paint: { 'text-color' : '#333' , 'text-halo-color' : '#fff' , 'text-halo-width' : 1 }
});
}); content_copy Copyopen_in_new Open
<! DOCTYPE html >
< html >
< head >
< meta charset = "utf-8" />
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" />
< link rel = "stylesheet" href = "https://unpkg.com/maplibre-gl@6.11.2/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.11.2/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: [ 15 , 50 ],
zoom: 6
});
map. on ( 'load' , () => {
const cities = { type: 'FeatureCollection' , features: [
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 14.42 , 50.08 ] }, properties: { name: 'Prague' , pop: 1300 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 16.61 , 49.20 ] }, properties: { name: 'Brno' , pop: 380 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 18.26 , 49.82 ] }, properties: { name: 'Ostrava' , pop: 290 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 15.05 , 50.77 ] }, properties: { name: 'Liberec' , pop: 105 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 13.38 , 49.74 ] }, properties: { name: 'Plzen' , pop: 175 } }
] };
map. addSource ( 'cities' , { type: 'geojson' , data: cities });
map. addLayer ({ id: 'city-circles' , type: 'circle' , source: 'cities' , paint: {
'circle-radius' : [ 'interpolate' , [ 'linear' ], [ 'get' , 'pop' ], 100 , 6 , 500 , 14 , 1300 , 24 ],
'circle-color' : [ 'interpolate' , [ 'linear' ], [ 'get' , 'pop' ], 100 , '#2196F3' , 700 , '#FF9800' , 1300 , '#F44336' ],
'circle-stroke-width' : 2 , 'circle-stroke-color' : '#fff'
} });
map. addLayer ({ id: 'city-labels' , type: 'symbol' , source: 'cities' ,
layout: { 'text-field' : [ 'get' , 'name' ], 'text-font' : [ 'Noto Sans Regular' ], 'text-size' : 12 , 'text-offset' : [ 0 , 1.5 ], 'text-anchor' : 'top' },
paint: { 'text-color' : '#333' , 'text-halo-color' : '#fff' , 'text-halo-width' : 1 }
});
});
</ script >
</ body >
</ html > content_copy Copyopen_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: [ 15 , 50 ],
zoom: 6
});
map. on ( 'load' , () => {
const cities = { type: 'FeatureCollection' , features: [
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 14.42 , 50.08 ] }, properties: { name: 'Prague' , pop: 1300 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 16.61 , 49.20 ] }, properties: { name: 'Brno' , pop: 380 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 18.26 , 49.82 ] }, properties: { name: 'Ostrava' , pop: 290 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 15.05 , 50.77 ] }, properties: { name: 'Liberec' , pop: 105 } },
{ type: 'Feature' , geometry: { type: 'Point' , coordinates: [ 13.38 , 49.74 ] }, properties: { name: 'Plzen' , pop: 175 } }
] };
map. addSource ( 'cities' , { type: 'geojson' , data: cities });
map. addLayer ({ id: 'city-circles' , type: 'circle' , source: 'cities' , paint: {
'circle-radius' : [ 'interpolate' , [ 'linear' ], [ 'get' , 'pop' ], 100 , 6 , 500 , 14 , 1300 , 24 ],
'circle-color' : [ 'interpolate' , [ 'linear' ], [ 'get' , 'pop' ], 100 , '#2196F3' , 700 , '#FF9800' , 1300 , '#F44336' ],
'circle-stroke-width' : 2 , 'circle-stroke-color' : '#fff'
} });
map. addLayer ({ id: 'city-labels' , type: 'symbol' , source: 'cities' ,
layout: { 'text-field' : [ 'get' , 'name' ], 'text-font' : [ 'Noto Sans Regular' ], 'text-size' : 12 , 'text-offset' : [ 0 , 1.5 ], 'text-anchor' : 'top' },
paint: { 'text-color' : '#333' , 'text-halo-color' : '#fff' , 'text-halo-width' : 1 }
});
});
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [15, 50],
zoom: 6
});
map.on('load', () => {
const cities = { type: 'FeatureCollection', features: [
{ type: 'Feature', geometry: { type: 'Point', coordinates: [14.42, 50.08] }, properties: { name: 'Prague', pop: 1300 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [16.61, 49.20] }, properties: { name: 'Brno', pop: 380 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [18.26, 49.82] }, properties: { name: 'Ostrava', pop: 290 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [15.05, 50.77] }, properties: { name: 'Liberec', pop: 105 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [13.38, 49.74] }, properties: { name: 'Plzen', pop: 175 } }
] };
map.addSource('cities', { type: 'geojson', data: cities });
map.addLayer({ id: 'city-circles', type: 'circle', source: 'cities', paint: {
'circle-radius': ['interpolate', ['linear'], ['get', 'pop'], 100, 6, 500, 14, 1300, 24],
'circle-color': ['interpolate', ['linear'], ['get', 'pop'], 100, '#2196F3', 700, '#FF9800', 1300, '#F44336'],
'circle-stroke-width': 2, 'circle-stroke-color': '#fff'
} });
map.addLayer({ id: 'city-labels', type: 'symbol', source: 'cities',
layout: { 'text-field': ['get', 'name'], 'text-font': ['Noto Sans Regular'], 'text-size': 12, 'text-offset': [0, 1.5], 'text-anchor': 'top' },
paint: { 'text-color': '#333', 'text-halo-color': '#fff', 'text-halo-width': 1 }
});
}); <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@6.11.2/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.11.2/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: [15, 50],
zoom: 6
});
map.on('load', () => {
const cities = { type: 'FeatureCollection', features: [
{ type: 'Feature', geometry: { type: 'Point', coordinates: [14.42, 50.08] }, properties: { name: 'Prague', pop: 1300 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [16.61, 49.20] }, properties: { name: 'Brno', pop: 380 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [18.26, 49.82] }, properties: { name: 'Ostrava', pop: 290 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [15.05, 50.77] }, properties: { name: 'Liberec', pop: 105 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [13.38, 49.74] }, properties: { name: 'Plzen', pop: 175 } }
] };
map.addSource('cities', { type: 'geojson', data: cities });
map.addLayer({ id: 'city-circles', type: 'circle', source: 'cities', paint: {
'circle-radius': ['interpolate', ['linear'], ['get', 'pop'], 100, 6, 500, 14, 1300, 24],
'circle-color': ['interpolate', ['linear'], ['get', 'pop'], 100, '#2196F3', 700, '#FF9800', 1300, '#F44336'],
'circle-stroke-width': 2, 'circle-stroke-color': '#fff'
} });
map.addLayer({ id: 'city-labels', type: 'symbol', source: 'cities',
layout: { 'text-field': ['get', 'name'], 'text-font': ['Noto Sans Regular'], 'text-size': 12, 'text-offset': [0, 1.5], 'text-anchor': 'top' },
paint: { 'text-color': '#333', 'text-halo-color': '#fff', 'text-halo-width': 1 }
});
});
</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: [15, 50],
zoom: 6
});
map.on('load', () => {
const cities = { type: 'FeatureCollection', features: [
{ type: 'Feature', geometry: { type: 'Point', coordinates: [14.42, 50.08] }, properties: { name: 'Prague', pop: 1300 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [16.61, 49.20] }, properties: { name: 'Brno', pop: 380 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [18.26, 49.82] }, properties: { name: 'Ostrava', pop: 290 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [15.05, 50.77] }, properties: { name: 'Liberec', pop: 105 } },
{ type: 'Feature', geometry: { type: 'Point', coordinates: [13.38, 49.74] }, properties: { name: 'Plzen', pop: 175 } }
] };
map.addSource('cities', { type: 'geojson', data: cities });
map.addLayer({ id: 'city-circles', type: 'circle', source: 'cities', paint: {
'circle-radius': ['interpolate', ['linear'], ['get', 'pop'], 100, 6, 500, 14, 1300, 24],
'circle-color': ['interpolate', ['linear'], ['get', 'pop'], 100, '#2196F3', 700, '#FF9800', 1300, '#F44336'],
'circle-stroke-width': 2, 'circle-stroke-color': '#fff'
} });
map.addLayer({ id: 'city-labels', type: 'symbol', source: 'cities',
layout: { 'text-field': ['get', 'name'], 'text-font': ['Noto Sans Regular'], 'text-size': 12, 'text-offset': [0, 1.5], 'text-anchor': 'top' },
paint: { 'text-color': '#333', 'text-halo-color': '#fff', 'text-halo-width': 1 }
});
});