Newer
Older
2021-Rino / csvmap.js
@ItoRino ItoRino on 6 Sep 2021 881 bytes plus
function myInit() {
    /* 北緯38.891度, 東経139.824度, ズームレベル16 で地図表示 */
    var mymap = L.map("csvmap").setView([38.891, 139.824], 16);
    L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
	attribution:
	'&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(mymap);
    L.control.scale().addTo(mymap);
    fetch("locations.csv").then((resp) => {
	return resp.text();	// HTTPレスポンスから文字列を抜き出して返す
    }).then((csvlines) => {	// それを csvlines として受け取る
        var line, x, lon, lat, desc;
        for (line of csvlines.split("\n")) {
          x = line.split(",");
          lon = x[0], lat = x[1], desc = x[2];
          L.marker([lon, lat]).bindPopup(desc).addTo(mymap);
        }
    });
}
document.addEventListener("DOMContentLoaded", myInit, false);