高德地圖開發

一、樣式

<style>
    .box-map{width:736px;padding-bottom:9999px;margin-bottom:-9999px}
    .gdmap{width:50%;height:400px;float:left;font-size:12px;border-radius:5px;margin:10px;}     //地圖大小 
    .button-group {position: fixed;bottom: 20px;right: 20px;font-size: 12px;padding: 10px;}
    .button-group .button {height: 28px;line-height: 28px;background-color: #0D9BF2;color: #FFF;border: 0;
        outline: none;padding-left: 5px;padding-right: 5px;border-radius: 3px;margin-bottom: 4px;cursor: pointer;}
    .button-group .inputtext {height: 26px;line-height: 26px;border: 1px;outline: none;padding-left: 5px;padding-right: 5px;border-radius: 3px;
        margin-bottom: 4px;cursor: pointer;}
    #tip {background-color: #fff;padding-left: 10px;padding-right: 10px;position: absolute;font-size: 12px;right: 10px;top: 20px;border-radius: 3px;
        border: 1px solid #ccc;line-height: 30px;}
    .amap-info-content {font-size: 12px;}
    #myPageTop {position: absolute;top: 5px;right: 10px;background: #fff none repeat scroll 0 0;border: 1px solid #ccc;margin: 10px auto;
        padding:6px;font-family: "Microsoft Yahei", "微軟雅黑", "Pinghei";font-size: 14px;}
    #myPageTop label {margin: 0 20px 0 0;color: #666666;font-weight: normal;}
    #myPageTop input {width: 170px;}
    #myPageTop .column2{padding-left: 25px;}
    .info {border: solid 1px silver;}
    div.info-top {position: relative;background: none repeat scroll 0 0 #F9F9F9;border-bottom: 1px solid #CCC;border-radius: 5px 5px 0 0;}
    div.info-top div {display: inline-block;color: #333333;font-size: 14px;font-weight: bold;line-height: 31px;padding: 0 10px;}
    div.info-top img {position: absolute;top: 10px;right: 10px;transition-duration: 0.25s;}
    div.info-top img:hover {box-shadow: 0px 0px 5px #000;}
    div.info-middle {font-size: 12px;padding: 6px;line-height: 20px;}
    div.info-bottom {height: 0px;width: 100%;clear: both;text-align: center;}
    div.info-bottom img {position: relative;z-index: 104;}
    span {margin-left: 0px;font-size: 11px;}
    .info-middle img {float: left;margin-right: 6px;}
    .cont_list{height:41px; margin-bottom:45px;}
    .cont_l{float:left; height: 41px;margin-left:45px;width:100%;}
    .cont_l p span{font-size:16px;color:#525050;font-family:微軟雅黑; }
    .cont_l p{font-size:13px;color:#000000;color:#94312B;}

</style>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=XXXXXXXXXXXXXX"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<div class="container f-fix">
    <div class="box_map f-fr" style="width:100%;">

        <div id="container" class="gdmap"></div>
    </div><!-- main -->
</div><!-- container -->

<script type="text/javascript">
    //地圖初始化時,在地圖上添加一個marker標記,鼠標點擊marker可彈出自定義的信息窗體
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [114.022706,22.536871],
        zoom: 18
    });
    addMarker();
    //添加marker標記
    function addMarker() {
        map.clearMap();
        var marker = new AMap.Marker({
            map: map,
            position: [114.022706,22.536871]
        });
        //鼠標點擊marker彈出自定義的信息窗體
        AMap.event.addListener(marker, 'click', function() {
            infoWindow.open(map, marker.getPosition());
        });
    }

    //實例化信息窗體
    var title = '<{$CONFIG.site.sitename}><span style="font-size:11px;color:#F00;"></span>',
        content = [];
    content.push("地址:<{$CONFIG.site.addr}>");
    content.push("電話:<{$CONFIG.site.tel}>");
    content.push("<a href='<{$CONFIG.site.host}>' target='_blank'>詳細信息</a>");
    var infoWindow = new AMap.InfoWindow({
        isCustom: true,  //使用自定義窗體
        content: createInfoWindow(title, content.join("<br/>")),
        offset: new AMap.Pixel(16, -45)
    });

    //構建自定義信息窗體
    function createInfoWindow(title, content) {
        var info = document.createElement("div");
        info.className = "info";

        //可以通過下面的方式修改自定義窗體的寬高
        //info.style.width = "400px";
        // 定義頂部標題
        var top = document.createElement("div");
        var titleD = document.createElement("div");
        var closeX = document.createElement("img");
        top.className = "info-top";
        titleD.innerHTML = title;
        closeX.src = "http://webapi.amap.com/images/close2.gif";
        closeX.onclick = closeInfoWindow;

        top.appendChild(titleD);
        top.appendChild(closeX);
        info.appendChild(top);

        // 定義中部內容
        var middle = document.createElement("div");
        middle.className = "info-middle";
        middle.style.backgroundColor = 'white';
        middle.innerHTML = content;
        info.appendChild(middle);

        // 定義底部內容
        var bottom = document.createElement("div");
        bottom.className = "info-bottom";
        bottom.style.position = 'relative';
        bottom.style.top = '0px';
        bottom.style.margin = '0 auto';
        var sharp = document.createElement("img");
        sharp.src = "http://webapi.amap.com/images/sharp.png";
        bottom.appendChild(sharp);
        info.appendChild(bottom);
        return info;
    }

    //關閉信息窗體
    function closeInfoWindow() {
        map.clearInfoWindow();
    }
</script>


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 一:基本地圖功能實現 1.申請密鑰流程 申請密鑰鏈接[http://lbs.amap.com/] 2.配置環境(重...
    Swift社區閱讀 5,876評論 2 10
  • 最近研究上了地圖的開發,結合自己的開發經驗以及前輩們的指導,簡要的描述一下高德地圖的基礎開發。 這里加入了一個第三...
    米拉_Recorder閱讀 4,716評論 8 15
  • 喜大普奔,終于,整理了搜索和導航。 1.依據關鍵詞進行搜索 監聽文本框編輯的變化,實現關鍵字模糊查詢。搜索是地圖的...
    米拉_Recorder閱讀 3,872評論 8 14
  • 那天李總說他家里爺爺去世了,我的思緒一下子就回到13爺爺去世的時候 。 13年2月27日,那時我還在學校,那天一大...
    Tina914閱讀 445評論 3 1
  • 一周前,我回了一趟濟南,那個三年前我迫不及待逃離的地方!2014年我畢業的時候,內心沒有絲毫對未來的向往...
    杏紙鶴閱讀 219評論 0 0