はじめに
Google マップのような地図を独自に構築できるleafletの基本的な使い方をご紹介します
とりあえず地図を表示する
下記の例ではOpenStreetMapを使用し、東京駅周辺を表示するサンプルです

<!DOCTYPE html>
<html lang="jp">
<head>
<meta charset="UTF-8">
<title>leaflet</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
<style>
body{
margin: 0;
}
#map{
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map("map").setView([35.6799462,139.7690628], 16);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
</script>
</body>
</html>
タイルを変更する
OpenStreetMap以外にも様々なタイルを使用することができます
タイルを変更することで地図の見た目を変えることができます
国土地理院が公開しているタイルに変更する例です

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
この部分を下記のように変更します
L.tileLayer('https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
attribution: "<a href='https://maps.gsi.go.jp/development/ichiran.html' target='_blank'>地理院タイル</a>"
}).addTo(map);
地理院地図のタイルは標準のも以外にも数種類あります
詳しくは地理院タイル一覧をご参照ください
淡色地図
