Leafletでポリゴンを表示するには「L.polygon」を利用します。
index.html
<!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
html, body {
height: 100%;
padding: 0;
margin: 0;
}
#map {
z-index: 0;
height: 100%;
}
script.js
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: '&copy; <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 Polygon = L.polygon([
[35.675949251235025,139.76617813110352],
[35.67410157813001,139.77188587188718],
[35.67455478492641,139.77227210998535],
[35.683757812281115,139.77862358093262],
[35.68431553740134,139.77343082427979],
[35.68469897115985,139.77094173431396],
[35.679923346539084,139.76871013641357],
[35.675949251235025,139.76617813110352]
],{
"color": "#E92D63",
"weight": 3,
"opacity": 0.8,
"fillColor": "#562DE9",
"fillOpacity": 0.4
}).addTo(map);
L.control.scale({
imperial: false,
maxWidth: 300
}).addTo(map);
L.control.layers(Map_BaseLayer, null, {
collapsed: true
}).addTo(map)
index.htmlを実行すると下記のようにブラウザで表示されます。
example
スタイルを変更:
var Polygon = L.polygon([
[35.675949251235025,139.76617813110352],
[35.67410157813001,139.77188587188718],
[35.67455478492641,139.77227210998535],
[35.683757812281115,139.77862358093262],
[35.68431553740134,139.77343082427979],
[35.68469897115985,139.77094173431396],
[35.679923346539084,139.76871013641357],
[35.675949251235025,139.76617813110352]
],{
"color": "#E200FF",
"weight": 1,
"opacity": 0.2,
"fillColor": "#E200FF",
"fillOpacity": 0.2
}).addTo(map)
L.polygonを利用すると地図上にポリゴンを表示することができます。
- 参考文献
Leaflet