溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

js-百度地圖多個標注點的實現(xiàn)方法

發(fā)布時間:2020-09-14 10:35:31 來源:億速云 閱讀:999 作者:小新 欄目:web開發(fā)

小編給大家分享一下js-百度地圖多個標注點的實現(xiàn)方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

<div class = "demo_main">

        <fieldset class = "demo_content">

              <div class = "min-height:400px; width:100%;" id = "map"></div>

               <script type = "text/javascript">

                         var markerArr = [

                               {

                                 title: "名稱:錦江區(qū)門診部",
                                 point: "104.118821,30.642073",
                                 address: "成都市錦江區(qū)通源街188號",
                                 tel: "028-86712080"

                               },

                               {
                                  title: "名稱:青羊區(qū)門診部",
                                  point: "104.000092,30.672099",
                                  address: "成都市青羊區(qū)春曉路15號 ",
                                  tel: "028-81067120"
                                },
                                {
                                  title: "名稱:高新區(qū)門診部",
                                  point: "104.061895,30.556204",
                                  address: "成都市高新區(qū)益州大道中段和天府二街交叉口復城國際T3-2號",
                                  tel: "028-81067120"
                                },

                          ];

                            var map; //Map實例 
                            function map_init() {
                                       map = new BMap.Map("map");
//第1步:設置地圖中心點,成都市 
                                       var point = new BMap.Point(104.082684, 30.656319);
//第2步:初始化地圖,設置中心點坐標和地圖級別。 
                                        map.centerAndZoom(point, 13);
//第3步:啟用滾輪放大縮小 
                                        map.enableScrollWheelZoom(true);
//第4步:向地圖中添加縮放控件 
                                        var ctrlNav = new window.BMap.NavigationControl({
                                              anchor: BMAP_ANCHOR_TOP_LEFT,
                                              type: BMAP_NAVIGATION_CONTROL_LARGE
                                         });
                                         map.addControl(ctrlNav);
//第5步:向地圖中添加縮略圖控件 
                                          var ctrlOve = new window.BMap.OverviewMapControl({
                                                anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
                                                isOpen: 1
                                            });
                                          map.addControl(ctrlOve);

//第6步:向地圖中添加比例尺控件 
                                          var ctrlSca = new window.BMap.ScaleControl({
                                                anchor: BMAP_ANCHOR_BOTTOM_LEFT
                                            });
                                           map.addControl(ctrlSca);

//第7步:繪制點 
                                          for(var i = 0; i < markerArr.length; i++) {
                                                      var p0 = markerArr[i].point.split(",")[0];
                                                      var p1 = markerArr[i].point.split(",")[1];
                                                      var maker = addMarker(new window.BMap.Point(p0, p1), i);
                                                      addInfoWindow(maker, markerArr[i], i);
                                             }
                                     }

 

// 添加標注 
                                            function addMarker(point, index) {
                                                         var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png",
                                                               new BMap.Size(23, 25), {
                                                                        offset: new BMap.Size(10, 25),
                                                                         imageOffset: new BMap.Size(0, 0 - index * 25)
                                                                 });
                                                                var marker = new BMap.Marker(point, {
                                                                      icon: myIcon
                                                                   });
                                                                  map.addOverlay(marker);
                                                                    return marker;
                                                }

 

 

// 添加信息窗口 
                                      function addInfoWindow(marker, poi) {
//pop彈窗標題 
                                            var title = '<div style="font-weight:bold;color:#CE5521;font-size:14px">' + poi.title + '</div>';
//pop彈窗信息 
                                             var html = [];
                                              html.push('<table cellspacing="0" style="table-layout:fixed;width:100%;font:12px arial,simsun,sans-serif"><tbody>');
                                              html.push('<tr>');
                                              html.push('<td style="vertical-align:top;line-height:16px;width:38px;white-space:nowrap;word-break:keep-all">地址:</td>');
                                              html.push('<td style="vertical-align:top;line-height:16px">' + poi.address + ' </td>');
                                              html.push('</tr>');
                                              html.push('</tbody></table>');
                                             var infoWindow = new BMap.InfoWindow(html.join(""), {
                                                     title: title,
                                                     width: 200
                                              });

                                             var openInfoWinFun = function() {
                                                       marker.openInfoWindow(infoWindow);
                                                };
                                           marker.addEventListener("click", openInfoWinFun);
                                                    return openInfoWinFun;
                                             }

 

 

//異步調(diào)用百度js 
          function map_load() {
                     var load = document.createElement("script");
                      load.src = "http://api.map.baidu.com/api?v=1.4&callback=map_init";
                      document.body.appendChild(load);
             }
              window.onload = map_load;

                </script>

         </fieldset>

</div>

css:

body { margin: 0; font-family: "Helvetica,Arial,FreeSans"; color: #000000; font-size: 12px; } 
.demo_main { padding: 20px; padding-top: 10px; } 
.demo_title { padding: 10px; margin-bottom: 10px; background-color: #D3D8E0; } 
.demo_content { padding: 10px; margin-bottom: 10px; }

js:

<script src="http://www.w3school.com.cn/jquery/jquery.js" type="text/javascript"></script>

效果圖:

js-百度地圖多個標注點的實現(xiàn)方法

以上是js-百度地圖多個標注點的實現(xiàn)方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

js
AI