Leafletでラインを表示するには「L.polyline」を利用します。
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>Leaflet Sample</title> <script src="./library/leaflet-0.7.3/leaflet.js"></script> <link href="./library/leaflet-0.7.3/leaflet.css" rel="stylesheet" /> <link href="./css/stylesheet.css" rel="stylesheet" /> </head> <body> <div id="map"></div> <script src="./js/script.js"></script> </body> </html> |
stylesheet.css
1 2 3 4 5 6 7 8 9 10 |
html, body { height: 100%; padding: 0; margin: 0; } #map { z-index: 0; height: 100%; } |
script.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
var m_mono = new L.tileLayer('https://tile.mierune.co.jp/mierune_mono/{z}/{x}/{y}.png', { attribution: "Maptiles by <a href='http://mierune.co.jp/' target='_blank'>MIERUNE</a>, under CC BY. Data by <a href='http://osm.org/copyright' target='_blank'>OpenStreetMap</a> contributors, under ODbL." }); var m_color = new L.tileLayer('https://tile.mierune.co.jp/mierune/{z}/{x}/{y}.png', { attribution: "Maptiles by <a href='http://mierune.co.jp/' target='_blank'>MIERUNE</a>, under CC BY. Data by <a href='http://osm.org/copyright' target='_blank'>OpenStreetMap</a> contributors, under ODbL." }); var t_pale = new L.tileLayer('http://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png', { attribution: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院</a>" }); var t_ort = new L.tileLayer('http://cyberjapandata.gsi.go.jp/xyz/ort/{z}/{x}/{y}.jpg', { attribution: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院</a>" }); var o_std = new L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }); var map = L.map('map', { center: [35.681,139.763], zoom: 14, zoomControl: true, layers: [m_mono] }); var Map_BaseLayer = { "MIERUNE地図 color": m_color, "MIERUNE地図 mono": m_mono, "地理院地図 淡色": t_pale, "地理院地図 オルソ": t_ort, "OpenStreetMap 標準": o_std }; var Line = L.polyline([ [35.66413037753069,139.75278854370114], [35.67214927327908,139.76523399353027], [35.68888176518044,139.77107048034668], [35.69703758268826,139.76660728454587] ],{ "color": "#FF0000", "weight": 5, "opacity": 0.6 }).addTo(map); L.control.scale({ imperial: false, maxWidth: 300 }).addTo(map); L.control.layers(Map_BaseLayer, null, { collapsed: true }).addTo(map); |
index.htmlを実行すると下記のようにブラウザで表示されます。
example
スタイルを変更:
1 2 3 4 5 6 7 8 9 10 |
var Line = L.polyline([ [35.66413037753069,139.75278854370114], [35.67214927327908,139.76523399353027], [35.68888176518044,139.77107048034668], [35.69703758268826,139.76660728454587] ],{ "color": "#2FFF00", "weight": 10, "opacity": 0.2 }).addTo(map); |
L.polylineを利用すると地図上にラインを表示することができます。
- 参考文献
leaflet