概要
leafletを鍛えてみた。
kml、表示してみた。
写真
参考にしたページ
サンプルコード
var map = L.map('map').setView([36.850918, 138.284091], 10);
var tileLayer = L.tileLayer('https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
});
tileLayer.addTo(map);
fetch('example2.kml').then(res => res.text()).then(kmltext => {
const parser = new DOMParser();
const kml = parser.parseFromString(kmltext, 'text/xml');
const track = new L.KML(kml);
map.addLayer(track);
const bounds = track.getBounds();
map.fitBounds(bounds);
});
成果物
以上。
