dayjournal memo

Total 975 articles!!

Mapbox GL JS #026 – 移動できる範囲指定

Yasunori Kirimoto's avatar


画像



移動できる範囲を指定するメモ。



画像



script.js

// MIERUNE MONO読み込み
var map = new mapboxgl.Map({
    container: "map",
    style: {
        "version": 8,
        "sources": {
            "MIERUNEMAP": {
                "type": "raster",
                "tiles": ["https://tile.mierune.co.jp/mierune_mono/{z}/{x}/{y}.png"],
                "tileSize": 256,
                "attribution": "Maptiles by <a href='http://mierune.co.jp/' target='_blank'>MIERUNE</a>, under CC BY. Data by <a href='http://osm.org/copyright' target='_blank'>OpenStreetMap</a> contributors, under ODbL."
            }
        },
        "layers": [{
            "id": "MIERUNEMAP",
            "type": "raster",
            "source": "MIERUNEMAP",
            "minzoom": 10,
            "maxzoom": 18
        }]
    },
    center: [139.767, 35.681],
    zoom: 11,
    // 移動できる範囲を指定 左下:右上
    maxBounds: [
        [139.7568, 35.6746],
        [139.7774, 35.6877]
    ]
});

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



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



book

Q&A