高德地图 JS API示例-事件系统-覆盖物事件- › 信息窗体打开关闭事件

高德地图 JS API示例-事件系统-覆盖物事件- › 信息窗体打开关闭事件

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>默认样式信息窗体</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html,body,#container{
            height:100%;
            width:100%;
        }
    </style>    
</head>
<body>
<div id="container"></div>
<div class="info" id="text">
    请打开或关闭信息窗体试试
</div>
<div class="input-card" style="width:18rem">
    <h4>信息窗体的打开与关闭</h4>
    <div>
      <div class="input-item">
        <button id="clickOn" class="btn" style="margin-right:1rem;">打开信息窗体</button>
        <button id="clickOff" class="btn">关闭信息窗体</button>
      </div>
    </div>
</div>
<script type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script type="text/javascript">
    var infoWindow;
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [116.473188,39.993253],
        zoom: 13
    });
    function showInfoOpen(){
        var text = '您打开了信息窗体!'
        document.querySelector("#text").innerText = text;
    }
    function showInfoClose(){
        var text = '您关闭了信息窗体!'
        document.querySelector("#text").innerText = text;
    }
    //在指定位置打开信息窗体
    function openInfo() {
        //构建信息窗体中显示的内容
        var info = [];
        info.push("<div><div><img style=\"float:left;\" src=\" https://webapi.amap.com/images/autonavi.png \"/></div> ");
        info.push("<div style=\"padding:0px 0px 0px 4px;\"><b>高德软件</b>");
        info.push("电话 : 010-84107000   邮编 : 100102");
        info.push("地址 :北京市朝阳区望京阜荣街10号首开广场4层</div></div>");
        infoWindow = new AMap.InfoWindow({
            content: info.join("<br/>")  //使用默认信息窗体框样式,显示信息内容
        });
        infoWindow.on('open',showInfoOpen)
        infoWindow.on('close',showInfoClose)
        infoWindow.open(map, map.getCenter());

    }
    function closeInfo() {
        infoWindow.close();
    }

    // 给按钮绑定事件
    document.getElementById("clickOn").onclick = openInfo;
    document.getElementById("clickOff").onclick = closeInfo;
</script>
</body>
</html>
0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x