面圖層疊加
點擊以疊加一個面圖層至地圖。
範例展示
原始碼
copy
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>面圖層疊加 - 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: [121.55097, 25.05488], // 初始中心座標,格式為 [lng, lat]
zoom: 15, // 初始 ZOOM LEVEL; [0-20, 0 為最小 (遠), 20 ;最大 (近)]
minZoom: 6, // 限制地圖可縮放之最小等級, 可省略, [0-19.99]
maxZoom: 19.99, // 限制地圖可縮放之最大等級, 可省略 [0-19.99]
speedLoad: false,
attributionControl: false
}).addControl(new gomp.AttributionControl({
compact: false
}));
map.on('load', function () {
map.addSource("flat1", {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[121.544111, 25.051779],
[121.548695, 25.057678],
[121.555254, 25.058218],
[121.556052, 25.054389],
[121.556656, 25.053385],
[121.557468, 25.051451],
[121.544111, 25.051779]
]
]
}
}]
}
});
map.addLayer({
"id": "flat-region",
"type": "fill",
"source": "flat1",
"paint": {
"fill-color": "#888888",
"fill-opacity": 0.4
},
"filter": ["==", "$type", "Polygon"]
});
});
</script>
</body>
</html>