208 lines
6.7 KiB
HTML
208 lines
6.7 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
<meta
|
||
name="viewport"
|
||
content="initial-scale=1.0, user-scalable=no, width=device-width"
|
||
/>
|
||
<title>热力图</title>
|
||
|
||
<script src="./static/tailwind.min.js"></script>
|
||
<link href="./static/remixicon/remixicon.css" rel="stylesheet" />
|
||
|
||
<style>
|
||
html,
|
||
body,
|
||
#container {
|
||
margin: 0;
|
||
padding: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<div id="container"></div>
|
||
|
||
<div
|
||
class="fixed border rounded-lg shadow-xl bottom-4 left-4 right-4 bg-white"
|
||
>
|
||
<div class="flex flex-row flex-nowrap items-center p-4">
|
||
<button
|
||
class="h-7 w-7 rounded-full transition-all hover:bg-slate-200 mb-6 mx-1"
|
||
id="play-btn"
|
||
onclick="startOrPause()"
|
||
>
|
||
<i class="ri-play-line"></i>
|
||
</button>
|
||
<div class="grow relative mb-6 mx-1">
|
||
<input
|
||
type="range"
|
||
min="0"
|
||
max="11"
|
||
value="0"
|
||
id="control-bar"
|
||
class="h-2 w-full cursor-pointer appearance-none rounded-lg bg-gray-200"
|
||
oninput="updateData(this.value)"
|
||
/>
|
||
<!-- 一种让 slider 下标和对应档位对齐的奇技淫巧:
|
||
在其下方放置 flex 容器,其中放置 space-between 的若干 label。此时,由于文字宽度的影响,无法真正对齐,产生偏移。
|
||
考虑将每个 label 实际大小设为 0,这样 label 可以实际对齐;放置其 absolute 的子元素,其中放置实际要显示的文字,
|
||
该 span 通过指定 left 和 translate 可以实现文字中线和父元素对齐,从而实现文字和 slider 档位对齐,作为 slider 刻度。
|
||
此外,注意 x 轴 padding 应该设为 slider 上按钮半径大小,因为 slider 实际开始位置不是该元素最左端,而是滑块在最左端时的中心点。
|
||
-->
|
||
<div
|
||
class="-bottom-6 flex w-full flex-nowrap justify-between px-2 text-sm text-gray-500"
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">1</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">2</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">3</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">4</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">5</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">6</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">7</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">8</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">9</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">10</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">11</span></span
|
||
>
|
||
<span class="relative">
|
||
<span class="absolute left-1/2 -translate-x-1/2">12</span></span
|
||
>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script type="text/javascript">
|
||
window._AMapSecurityConfig = {
|
||
securityJsCode: "0bc2f7560c1da34a09c921a92fce4502",
|
||
};
|
||
</script>
|
||
<script src="https://webapi.amap.com/maps?v=2.0&key=13471667a960ce7a08b3dfdd9a4fb193"></script>
|
||
<script src="./heatmapData.js"></script>
|
||
|
||
<script>
|
||
var map = new AMap.Map("container", {
|
||
resizeEnable: true,
|
||
center: [116.418261, 39.921984], // 配置地图中心的经纬度
|
||
zoom: 11,
|
||
});
|
||
|
||
if (!isSupportCanvas()) {
|
||
alert("您所使用的浏览器不能使用热力图功能,请换个浏览器试试~");
|
||
}
|
||
|
||
// heatmap.js document:
|
||
// http://www.patrick-wied.at/static/heatmapjs/docs.html
|
||
/* visible 热力图是否显示, 默认为 true
|
||
* opacity 热力图的透明度, 分别对应 heatmap.js的minOpacity和maxOpacity
|
||
* radius 热力图的每个点的半径大小
|
||
* gradient {JSON} 热力图的渐变区间 . gradient如下所示
|
||
* {
|
||
.2:'rgb(0, 255, 255)',
|
||
.5:'rgb(0, 110, 255)',
|
||
.8:'rgb(100, 0, 255)'
|
||
}
|
||
其中 key 表示插值的位置, 0-1
|
||
value 为颜色值
|
||
*/
|
||
var heatmap;
|
||
var playing = false;
|
||
map.plugin(["AMap.HeatMap"], function () {
|
||
heatmap = new AMap.HeatMap(map, {
|
||
radius: 25, //给定半径
|
||
opacity: [0, 0.8],
|
||
/*,
|
||
gradient:{
|
||
0.5: 'blue',
|
||
0.65: 'rgb(117,211,248)',
|
||
0.7: 'rgb(0, 255, 0)',
|
||
0.9: '#ffea00',
|
||
1.0: 'red'
|
||
}
|
||
*/
|
||
});
|
||
heatmap.setDataSet({
|
||
max: 100,
|
||
data: heatmapData[0],
|
||
});
|
||
});
|
||
|
||
function isSupportCanvas() {
|
||
var elem = document.createElement("canvas");
|
||
return !!(elem.getContext && elem.getContext("2d"));
|
||
}
|
||
|
||
function showHeatmap() {
|
||
heatmap.show();
|
||
}
|
||
|
||
function hideHeatmap() {
|
||
heatmap.hide();
|
||
}
|
||
|
||
function updateData(value) {
|
||
heatmap.setDataSet({
|
||
data: heatmapData[value],
|
||
max: 100,
|
||
});
|
||
}
|
||
|
||
function startOrPause() {
|
||
if (playing) {
|
||
playing = false;
|
||
let btn = document.getElementById("play-btn");
|
||
btn.innerHTML = '<i class="ri-play-line"></i>';
|
||
stopPlay();
|
||
} else {
|
||
playing = true;
|
||
let btn = document.getElementById("play-btn");
|
||
btn.innerHTML = '<i class="ri-pause-line"></i>';
|
||
startPlay();
|
||
}
|
||
}
|
||
|
||
function startPlay() {
|
||
let slider = document.getElementById("control-bar");
|
||
intervalID = setInterval(function () {
|
||
if (slider.value < 11) {
|
||
slider.value++;
|
||
updateData(slider.value);
|
||
} else {
|
||
startOrPause();
|
||
}
|
||
}, 100); // Do every 100ms
|
||
}
|
||
|
||
function stopPlay() {
|
||
clearInterval(intervalID);
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|