dayjournal memo

Total 975 articles!!

MapLibre GL JS #007 - MapTilerのラスタタイル表示

Yasunori Kirimoto's avatar


画像



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



画像



script.js

// MapTiler読み込み
const map = new maplibregl.Map({
    container: 'map',
    style: {
        version: 8,
        sources: {
            m_streets: {
                type: 'raster',
                tiles: [
                    'https://api.maptiler.com/maps/jp-mierune-streets/256/{z}/{x}/{y}.png?key=[APIキー]',
                ],
                tileSize: 256,
                attribution:
                    '<a href="https://maptiler.jp/" target="_blank">© MIERUNE</a> <a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>',
            },
        },
        layers: [
            {
                id: 'mierunemap',
                type: 'raster',
                source: 'm_streets',
                minzoom: 0,
                maxzoom: 18,
            },
        ],
    },
    center: [139.767, 35.681],
    zoom: 11,
});

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



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



book

Q&A