도구 · T08
MapLibre GL JS: 3D와 벡터 타일
MapLibre GL JS는 WebGL로 그리는 오픈소스 웹 지도 라이브러리입니다. 부드러운 확대, 기울이기·회전, 3D 돌출, 벡터 타일 스타일을 지원합니다. 서울 행정동 인구밀도를 3D 높이로 세워 봤습니다.
실습: 인구밀도 3D
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>MapLibre GL JS 6.19로 그린 서울 인구밀도 3D</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" />
<style>html, body, #map { height: 100%; margin: 0; }</style>
</head>
<body>
<div id="map"></div>
<script type="module">
// MapLibre GL JS 6은 ES 모듈로만 배포된다(옛 dist/maplibre-gl.js 주소는 404). import로 불러온다.
import * as maplibregl from 'https://unpkg.com/[email protected]/dist/maplibre-gl.mjs';
// 배경: MapLibre 데모 스타일(키 없이 쓰는 저해상도 세계 지도). 실서비스는 자체 타일이나 약관을 확인한 타일을 쓰세요.
const map = new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [126.99, 37.55], zoom: 10.3, pitch: 55, bearing: -15
});
map.addControl(new maplibregl.NavigationControl());
map.on('load', () => {
map.addSource('dong', { type: 'geojson', data: 'seoul_dong_web.geojson' });
// 인구밀도(명/km²)를 높이로 세운다: 밀도 1만 = 1,000m
map.addLayer({
id: 'dong-3d', type: 'fill-extrusion', source: 'dong',
paint: {
'fill-extrusion-color': ['interpolate', ['linear'], ['get', 'density'], 0, '#fde8ec', 20000, '#f768a1', 45000, '#49006a'],
'fill-extrusion-height': ['*', ['get', 'density'], 0.1],
'fill-extrusion-opacity': 0.85
}
});
map.on('click', 'dong-3d', e => {
const p = e.features[0].properties;
new maplibregl.Popup().setLngLat(e.lngLat)
.setHTML(`<b>${p.name}</b><br>인구밀도 ${Number(p.density).toLocaleString()}명/km²`).addTo(map);
});
});
</script>
</body>
</html>
함정
예전 예제 주소가 404
처음에 다른 예제처럼 <script src=".../[email protected]/dist/maplibre-gl.js">로 불렀더니 파일이 없어(404) 지도가 하얗게 나왔습니다. MapLibre GL JS 6은 ES 모듈(maplibre-gl.mjs)로만 배포되어 <script type="module"> 안에서 import로 불러야 합니다. 버전을 올릴 때는 배포 파일 구성부터 확인하세요.
배경지도(스타일) 고르기
| 배경 | 키 | 메모 |
|---|---|---|
| MapLibre 데모 타일 | 없음 | 위 예제. 저해상도 세계 지도라 도시 배경으로는 부족, 학습용 |
| CARTO 베이스맵(Positron 등) | 필요(2026년부터) | 키 없이 요청하면 워터마크. 비상업 월 500만 타일 요청까지 무료(A06) |
| Mapbox 스타일 | 필요(토큰) | Mapbox 약관·요금 적용(A05) |
| 자체 타일(PMTiles 등) | 없음 | OSM 데이터로 직접 만들어 정적 호스팅. 손이 더 가지만 약관 걱정이 적음 |
MapLibre와 Mapbox, deck.gl
MapLibre GL JS는 Mapbox GL JS가 1.x 이후 오픈소스 라이선스를 바꾸자 커뮤니티가 이어 만든 갈래(fork)로 널리 알려져 있습니다. API 모양이 비슷해 예제를 옮기기 쉽습니다. 수십만 개 점·궤적처럼 더 무거운 시각화는 deck.gl(현재 9.4.2)을 MapLibre 위에 겹쳐 씁니다(kepler.gl도 deck.gl 기반).
출처(2026-11-24 확인): MapLibre GL JS 릴리스 · maplibre.org · deck.gl 릴리스 · CARTO basemap-styles
이것만 기억하세요
2D 표시는 Leaflet, 3D·벡터 타일·부드러운 지도는 MapLibre. 배경지도 약관과 키는 라이브러리와 따로 챙깁니다.