線圖層疊加

設定所需樣式並疊加一個線圖層至地圖。

範例展示

原始碼

copy
<!DOCTYPE html>
<html>
<head>
    <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.54921, 25.05582], // 初始中心座標,格式為 [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.addLayer({
                'id': 'lines',
                'type': 'line',
                'source': {
                    'type': 'geojson',
                    'data': {
                        'type': 'FeatureCollection',
                        'features': [{
                            'type': 'Feature',
                            'properties': {
                                'color': '#42dff4'
                            },
                            'geometry': {
                                'type': 'LineString',
                                'coordinates': [
                                    [121.544541, 25.052563],
                                    [121.548695, 25.057678],
                                    [121.555054, 25.058218]
                                ]
                            }
                        }]
                    }
                },
                'paint': {
                    'line-width': 5,
                    'line-color': ['get', 'color']
                }
            });
        });
    </script>
</body>
</html>