dayjournal memo

Total 974 articles!!

MapLibre GL JS #003 - OpenStreetMapのラスタタイル表示

Yasunori Kirimoto's avatar

画像


背景にOpenStreetMapのラスタタイルを表示するメモ。



画像



script.js

// OpenStreetMap読み込み
const map = new maplibregl.Map({
    container: 'map',
    style: {
        version: 8,
        sources: {
            OSM: {
                type: 'raster',
                tiles: [
                    'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
                    'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png',
                ],
                tileSize: 256,
                attribution: "© <a href='http://osm.org/copyright'>OpenStreetMap</a> contributors",
            },
        },
        layers: [
            {
                id: 'OSM',
                type: 'raster',
                source: 'OSM',
                minzoom: 0,
                maxzoom: 18,
            },
        ],
    },
    center: [139.767, 35.681],
    zoom: 11,
});

// コントロール関係表示
map.addControl(new maplibregl.NavigationControl());



MapLibre GL JSを手軽に始めるビルド環境公開しています。
maplibregljs-starter



book

Q&A