diff --git a/csvmap.js b/csvmap.js new file mode 100644 index 0000000..9f3a024 --- /dev/null +++ b/csvmap.js @@ -0,0 +1,21 @@ +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: + '© OpenStreetMap contributors' + }).addTo(mymap); + L.control.scale().addTo(mymap); + fetch("locations.csv").then((resp) => { + return resp.text(); // HTTPレスポンスから文字列を抜き出して返す + }).then((csvlines) => { // それを csvlines として受け取る + /* ここに csvlines を複数のCSV行として処理するものを書く */ + var line, x, lon, lat, desc; +for (line of csvline.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);