地震規模圖 (Heatmap)
範例展示
原始碼
copy
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>地震規模圖 (Heatmap) - Map8 Platform Documentation</title>
<link rel="stylesheet" href="https://api.map8.zone/css/gomp.css?key=[YOUR_KEY_HERE]" />
<style>
#map{
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="https://api.map8.zone/maps/js/gomp.js?key=[YOUR_KEY_HERE]"></script>
<script type="text/javascript">
gomp.accessToken = '[YOUR_KEY_HERE]';
var map = new gomp.Map({
container: 'map', // 地圖容器 ID
style: 'https://api.map8.zone/styles/go-life-maps-tw-style-std/style.json', // 地圖樣式檔案位置
maxBounds: [[105, 15], [138.45858, 33.4]], // 台灣地圖區域
center: [120.973882, 23.6], // 初始中心座標,格式為 [lng, lat]
zoom: 6, // 初始 ZOOM LEVEL; [0-20, 0 為最小 (遠), 20 ;最大 (近)]
minZoom: 6, // 限制地圖可縮放之最小等級, 可省略, [0-19.99]
maxZoom: 19.99, // 限制地圖可縮放之最大等級, 可省略 [0-19.99]
attributionControl: false
}).addControl(new gomp.AttributionControl({
compact: false
}));
map.addControl(new gomp.NavigationControl());
map.on('load', function () {
map.addSource("earthquake", {
type: "geojson",
data: "[YOUR_GEOJSON_FILE_HERE]" // 此範例所使用的檔案請見 https://www.map8.zone/js/vector/earthquakeHeatmap.json
});
map.addLayer({
id: "earthquake",
type: "heatmap",
source: "earthquake",
paint: {
'heatmap-weight': [
'interpolate',
['linear'],
['get', 'magnitude'],
0, 0,
6, 1
],
'heatmap-intensity': [
'interpolate',
['linear'],
['zoom'],
0, 1,
9, 5
],
'heatmap-color': [
'interpolate',
['linear'],
['heatmap-density'],
0, 'rgba(255,255,255,0)',
0.4, '#21cf42',
0.6, '#fed23a',
0.8, '#ff8400',
1, 'red'
],
'heatmap-radius': [
'interpolate',
['linear'],
['zoom'],
0, 2,
9, 20
]
}
});
});
map.once('idle', function(){
map.moveLayer('earthquake')
})
</script>
</body>
</html>