Leafletで矩形を表示するには「L.rectangle」を利用します。


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: '&amp;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 Rectangle = L.rectangle([
[35.671,139.753],
[35.691,139.773]
],{
color: '#FF0000',
weight: 3,
opacity: 0.8,
fillColor: '#FF0000',
fillOpacity: 0.3
}).addTo(map);

L.control.scale({
imperial: false,
maxWidth: 300
}).addTo(map);

L.control.layers(Map_BaseLayer, null, {
collapsed: true
}).addTo(map)


index.htmlを実行すると下記のようにブラウザで表示されます。
leaflet_035_01

example


スタイルを変更:


var Rectangle = L.rectangle([
[35.671,139.753],
[35.691,139.773]
],{
color: '#FF0000',
weight: 10,
opacity: 0.8,
fillColor: '#FF0000',
fillOpacity: 0.1
}).addTo(map)


L.rectangleを利用すると地図上に矩形を表示することができます。





book


Q&A