Leafletでヒートマップを作成するには、「Leaflet.heat」と言うプラグインを利用します。
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Leaflet Sample</title>
<script src="./library/leaflet-1.0.1/leaflet.js"></script>
<link href="./library/leaflet-1.0.1/leaflet.css" rel="stylesheet" />
<script src="./plugin/Leaflet.heat/dist/leaflet-heat.js"></script>
<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 mierune_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 mierune_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 map = L.map('map', {
center: [35.6831925, 139.7511307],
zoom: 12,
zoomControl: true,
layers: [mierune_mono]
});
var heat = L.heatLayer([
[35.6831, 139.7500, 50],
[35.6831, 139.7550, 10],
[35.6831, 139.7600, 50],
[35.6831, 139.7650, 10],
[35.6831, 139.7700, 50],
[35.6881, 139.7500, 10],
[35.6931, 139.7500, 50],
[35.6981, 139.7500, 10],
[35.6781, 139.7500, 50],
[35.6731, 139.7500, 10]
], {
radius: 30
}).addTo(map);
var Map_BaseLayer = {
"MIERUNE MONO": mierune_mono,
"MIERUNE Color": mierune_color
};
L.control.scale({
imperial: false,
maxWidth: 300
}).addTo(map);
L.control.layers(Map_BaseLayer, null, {
collapsed: true
}).addTo(map)
index.htmlを実行すると下記のようにブラウザで表示されます。
example
サークル半径変更:
var heat = L.heatLayer([
[35.6831, 139.7500, 50],
[35.6831, 139.7550, 10],
[35.6831, 139.7600, 50],
[35.6831, 139.7650, 10],
[35.6831, 139.7700, 50],
[35.6881, 139.7500, 10],
[35.6931, 139.7500, 50],
[35.6981, 139.7500, 10],
[35.6781, 139.7500, 50],
[35.6731, 139.7500, 10]
], {
radius: 50
}).addTo(map)
ぼかし変更:
var heat = L.heatLayer([
[35.6831, 139.7500, 50],
[35.6831, 139.7550, 10],
[35.6831, 139.7600, 50],
[35.6831, 139.7650, 10],
[35.6831, 139.7700, 50],
[35.6881, 139.7500, 10],
[35.6931, 139.7500, 50],
[35.6981, 139.7500, 10],
[35.6781, 139.7500, 50],
[35.6731, 139.7500, 10]
], {
radius: 30,
blur: 1
}).addTo(map)
ヒートマップ機能を実装したい時に便利なプラグインです。
- 参考文献
Leaflet
Leaflet.heat