0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Leafletの独自マップでの範囲外の404エラーを防止する

Posted at

自分で用意した画像を表示させると、画像外のエリアを表示した場合404エラーが出るのを防止する。

土台はいつぞやの記事。

特に難しいことは無く、tileLayerboundsnoWrapを設定するだけ。

LatLngBoundsに設定する値は、元の画像のサイズ。
(今回使ってる画像は元々6720x4480)

    // 404エラー防止
    const mapBounds = new L.LatLngBounds(
      map.unproject([0, 4480], map.getMaxZoom()),
      map.unproject([6720, 0], map.getMaxZoom())
    );

    L.tileLayer('map/{z}/{x}/{y}.jpg', {
      attribution: '© <a href="https://www.pakutaso.com/20200556146post-25030.html">ぱくたそ</a>',
      bounds: mapBounds,
      noWrap: true,
    }).addTo(map);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?