• javascript高德地图实现点击marker消失marker


    javascript高德地图实现点击marker消失marker

    <pre>
    var markers = [];
    var positions = [[120.17718, 30.21772], [120.17718, 30.21872]];
    for (var i = 0, marker; i < positions.length; i++) {
    marker = new AMap.Marker({
    map: map,
    icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
    position: positions[i],
    content: '<div class="marker-route marker-marker-bus-from zhongzimark" zhongziid=1><img class="markerimg" src="http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png" /><div class="markarea"></div></div>' //自定义点标记覆盖物内容
    });
    markers.push(marker);


    markers.push(marker);

    }
    $.each(markers, function (k, v) {
    markers[k].on('click', function () {
    //获取html属性方法
    var htmlc=markers[k].getContent();
    htmlc=$(htmlc);
    console.log($(htmlc).attr('zhongziid'))
    if ( markers[k]) {
    markers[k].setMap(null);
    markers[k] = null;
    }
    /* var str2 = {"personid": <?php echo $personid ?>, "type": 1, "shuzhi": 10, "tag": 3};
    str2 = JSON.stringify(str2);
    ws.send(str2);*/

    });

    })
    <style>
    .zhongzimark {
    position: relative;
    60px;
    height: auto;
    overflow: hidden;
    }
    .markerimg{
    15%;
    }
    .markarea{
    15%;
    height:auto;
    overflow:hidden;
    line-height: 1.3;
    text-align: center;
    color: #000;
    background: #FFF;
    }
    </style>
    </pre>
    ps:原理就是 先循环遍历marker 显示并且添加到markers数组 然后循环遍历markers数组添加事件就好了 getContent可以获取到html 然后用jquery attr方法获取属性

  • 相关阅读:
    Codeforces 1196E. Connected Component on a Chessboard
    Codeforces 1196C. Robot Breakout
    Codeforces 1194E. Count The Rectangles
    Codeforces 1194D. 1-2-K Game
    Codeforces 1194C. From S To T
    Codeforces 1194B. Yet Another Crosses Problem
    Codeforces 1194A. Remove a Progression
    Codeforces 1201E2. Knightmare (hard)
    关于cookie
    关于js的addEventListener 和一些常用事件
  • 原文地址:https://www.cnblogs.com/newmiracle/p/11865587.html
Copyright © 2020-2023  润新知