自訂地圖標記點圖示

自訂地圖標記點圖示。可使用 HTML 元素。一個元素只能指定給一個 Marker,若有多個 Marker 則需指定多個不同的元素。

您也能使用以 Base64 編碼的圖片,例如:

img.src = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNi4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IuWcluWxpF8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCINCgkgd2lkdGg9IjkwcHgiIGhlaWdodD0iMTA2cHgiIHZpZXdCb3g9IjAgMCA5MCAxMDYiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDkwIDEwNiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8cGF0aCBmaWxsPSIjMDA1M0NDIiBkPSJNNDQuOTkzLDBDMTcuMTczLDAsMCwyMS4zNzcsMCw0Mi40OTFjMCwwLDAsMC4xNjgsMCwwLjQ0OWMwLjA4MSw3LjI1OCwyLjU0NCwxNS4xMjEsNi43NDUsMjAuODczDQoJYzEuNDA0LDIuMDM1LDMuMTQxLDMuOTkzLDUuMjAxLDUuODQ5aDAuMDRjMC40MjksMC4zOTQsMC44NDYsMC43NTksMS4yODEsMS4xMDRjMC4yMiwwLjE5NSwwLjQ0MywwLjM3OSwwLjY2OSw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jM3OCwwLjI2NS0yLjUxOCwwLjgwOHY1LjA4aC0xLjR2LTcuMDJoMS4wODlsMC4xNDcsMS4wNjENCgljMS4wMjQtMC44MzYsMi4wMTItMS4yNTEsMi45MzQtMS4yNTFMNjEuMzE0LDU5LjAwOUw2MS4zMTQsNTkuMDA5eiIvPg0KPHBhdGggZmlsbD0iI0ZGRkZGRiIgZD0iTTYzLjc3NCw1OS4xODhsMC4wNjcsMS4wNzljMC45NzktMC44NCwxLjkzNS0xLjI2OSwyLjgxOC0xLjI2OWMwLjk3NCwwLDEuNTY3LDAuNDE1LDEuNzgxLDEuMjI1DQoJYzAuOTM4LTAuODEsMS44NDYtMS4yMjUsMi43NjgtMS4yMjVjMC42MTQsMCwxLjA3NiwwLjE2NSwxLjQwNCwwLjQ5M2MwLjMxNSwwLjMzNCwwLjQ2OCwwLjgxNCwwLjQ2OCwxLjQ1NHY1LjI1OGgtMS4zNjZ2LTQuODUxDQoJYzAtMC40MDctMC4wNzktMC43MTMtMC4yMjctMC45Yy0wLjE1Mi0wLjE3My0wLjQxNi0wLjI2Ny0wLjc4NC0wLjI2N2MtMC4zMTUsMC0wLjYxOCwwLjA3NS0wLjkxLDAuMjE2DQoJYy0wLjI3OCwwLjEzMS0wLjcwNiwwLjQxMS0xLjI2NCwwLjgwOXY0Ljk5M2gtMS4zMjV2LTQuODU0YzAtMC40MjktMC4xMDQtMC43MjctMC4yNTYtMC45MTFjLTAuMTY1LTAuMTY1LTAuNDMtMC4yNjYtMC43NzUtMC4yNjYNCgljLTAuMzExLDAtMC42MTMsMC4wODItMC45MDQsMC4yMTZjLTAuMjg5LDAuMTUxLTAuNywwLjQxNy0xLjI3LDAuODA4djQuOTk5aC0xLjM4M3YtNy4wMDdINjMuNzc0TDYzLjc3NCw1OS4xODh6Ii8+DQo8L3N2Zz4NCg==';

範例展示

原始碼

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.54885, 25.03625], // 初始中心座標,格式為 [lng, lat]
            zoom: 16, // 初始 ZOOM LEVEL; [0-20, 0 為最小 (遠), 20 ;最大 (近)]
            minZoom: 6, // 限制地圖可縮放之最小等級, 可省略, [0-19.99]
            maxZoom: 19.99, // 限制地圖可縮放之最大等級, 可省略 [0-19.99]
            pitch: 50, // 攝影機仰角, 可省略, [0-60]
            bearing: 0, // 地圖角度, 可省略, [-180 ~ 180; 0 為正北朝上, 180 為正南朝上]
            attributionControl: false
        }).addControl(new gomp.AttributionControl({
            compact: false
        }));

        map.on('load', function () {
            var nowMapCenterPoint = map.getCenter();

            var img = document.createElement('img');
            img.src = '[YOUR_IMAGE_HERE]'; // 請代換為您的圖檔之 URL (例如 "https://example.com/image.png")
            var markerImg = new gomp.Marker(img, {offset: [0, -21]})
                .setLngLat(nowMapCenterPoint)
                .addTo(map);

            var div = document.createElement('div');
            div.style.height = '42px';
            div.style.width = '28px';
            div.style.backgroundImage = 'url("[YOUR_IMAGE_HERE]")'; // 請代換為您的圖檔之 URL (例如 "https://example.com/image.png")
            var markerDiv = new gomp.Marker(div, {offset: [0, -21]})
                .setLngLat({lng: nowMapCenterPoint.lng, lat: nowMapCenterPoint.lat - 0.001})
                .addTo(map);
        });
    </script>
</body>
</html>