腾讯地图添加多marker标注样式

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>腾讯地图添加多marker样式</title>
</head>
<!-- <script charset="utf-8"
    src="https://map.qq.com/api/gljs?v=1.exp&key=XTNBZ-3R7C4-IQJUI-DK7EZ-5ECLV-YDBFF"></script>
     -->
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=xxxxxxxxxxxxxxxxxxxxxx"></script>
<style type="text/css">
    html,
    body {
        height: 100%;
        margin: 0px;
        padding: 0px;
    }
    #container {
         800px;
        height: 800px;
    }
</style>
<body>
<div id="container"></div>
<script>
    function init) {
        var center = new qq.maps.LatLng39.916527, 116.397128);
        var map = new qq.maps.Mapdocument.getElementById"container"), {
            center: center,
            zoom: 13
        });
        var infoWin = new qq.maps.InfoWindow{
            map: map
        });
        var latlngs = [
            new qq.maps.LatLng39.91374, 116.37333),
            new qq.maps.LatLng39.91347, 116.39336),
            new qq.maps.LatLng39.90184, 116.41306)
        ];

        //根据图片大小调整 界点
        var anchor = new qq.maps.Point0, 39),
            size = new qq.maps.Size42, 68),
            origin = new qq.maps.Point0, 0),
            markerIcon = new qq.maps.MarkerImage
                "http://xxx.xxxxxxxxxx.com/style/image/img31.png",
                // size,
                // origin,
                // anchor
            );

        for var i = 0; i < latlngs.length; i++) {
            function n) {
                //实例标注
                var marker = new qq.maps.Marker{
                    position: latlngs[n],
                    map: map
                });

                //设置每个标注的样式
                marker.setIconmarkerIcon);

                //标注点击事件
                qq.maps.event.addListenermarker, 'click', function ) {
                    infoWin.open);
                    infoWin.setContent'<div style="text-align:center;white-space:' +
                        'nowrap;margin:10px;">这是第 ' +
                        n + ' 个标注</div>');
                    infoWin.setPositionlatlngs[n]);
                });
            })i);
        }
    }
    init);
</script>
</body>
</html>

  

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注