index.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  5. <style type="text/css">
  6. body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
  7. #allmap {height: 100%;width:100%;overflow: hidden;}
  8. #r-searchresult {width:100%;font-size:12px;}
  9. dl,dt,dd,ul,li{
  10. margin:0;
  11. padding:0;
  12. list-style:none;
  13. }
  14. dt{
  15. font-size:14px;
  16. font-family:"微软雅黑";
  17. font-weight:bold;
  18. border-bottom:1px dotted #000;
  19. padding:5px 0 5px 5px;
  20. margin:5px 0;
  21. }
  22. dd{
  23. padding:5px 0 0 5px;
  24. }
  25. li{
  26. line-height:28px;
  27. }
  28. .sel_city_sf a {
  29. font-size:12px;
  30. }
  31. .sel_city_name {
  32. font-size:12px;
  33. }
  34. .optionpanel{margin: 10px;position:fixed;right:10px;bottom:10px;font-size:12px;}
  35. </style>
  36. <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak={$config.baiduak}"></script>
  37. <!--信息窗口库-->
  38. <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
  39. <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />
  40. <title>{$site.name}</title>
  41. </head>
  42. <body>
  43. <div id="allmap"></div>
  44. <div id="r-result">
  45. <div class="optionpanel">
  46. <label>选择主题</label>
  47. <select id="stylelist" onchange="changeMapStyle(this.value)"></select>
  48. </div>
  49. </div>
  50. <div id="r-position"></div>
  51. </body>
  52. </html>
  53. <script type="text/javascript" src="http://lbsyun.baidu.com/custom/stylelist.js">
  54. </script>
  55. <script type="text/javascript">
  56. function G(id) {
  57. return document.getElementById(id);
  58. }
  59. //初始化模板选择的下拉框
  60. var sel = document.getElementById('stylelist');
  61. for (var key in mapstyles) {
  62. var style = mapstyles[key];
  63. var item = new Option(style.title, key);
  64. sel.options.add(item);
  65. }
  66. // 百度地图API功能
  67. var map = new BMap.Map("allmap");
  68. var point = new BMap.Point(116.404, 39.915);
  69. map.centerAndZoom(point, 10);
  70. map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用
  71. map.enableContinuousZoom(); //启用地图惯性拖拽,默认禁用
  72. //添加标尺工具
  73. var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角,添加比例尺
  74. var top_left_navigation = new BMap.NavigationControl(); //左上角,添加默认缩放平移控件
  75. var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //右上角,仅包含平移和缩放按钮
  76. /*缩放控件type有四种类型:
  77. BMAP_NAVIGATION_CONTROL_SMALL:仅包含平移和缩放按钮;BMAP_NAVIGATION_CONTROL_PAN:仅包含平移按钮;BMAP_NAVIGATION_CONTROL_ZOOM:仅包含缩放按钮*/
  78. map.addControl(top_left_control);
  79. map.addControl(top_left_navigation);
  80. // map.addControl(top_right_navigation);
  81. //添加地图类型控件
  82. var stCtrl = new BMap.MapTypeControl();
  83. stCtrl.setOffset(new BMap.Size(20, 30));
  84. map.addControl(stCtrl);
  85. function changeMapStyle(style) {
  86. map.setMapStyle({style: style});
  87. $('#desc').html(mapstyles[style].desc);
  88. }
  89. //添加全景,需要flash支持
  90. // map.addTileLayer(new BMap.PanoramaCoverageLayer());
  91. // var stCtrl = new BMap.PanoramaControl(); //构造全景控件
  92. // stCtrl.setOffset(new BMap.Size(20, 20));
  93. // map.addControl(stCtrl);//添加全景控件
  94. //添加版权
  95. var cr = new BMap.CopyrightControl({anchor: BMAP_ANCHOR_TOP_RIGHT}); //设置版权控件位置
  96. map.addControl(cr); //添加版权控件
  97. var bs = map.getBounds(); //返回地图可视区域
  98. cr.addCopyright({id: 1, content: "<a href='https://www.fastadmin.net/store/cwmap.html' target='_blank' style='font-size:14px;background:yellow'>" + "{$site.name}" + "</a>", bounds: bs});
  99. //Copyright(id,content,bounds)类作为CopyrightControl.addCopyright()方法的参数
  100. //城市列表控件
  101. var size = new BMap.Size(80, 60);
  102. map.addControl(new BMap.CityListControl({
  103. anchor: BMAP_ANCHOR_TOP_LEFT,
  104. // anchor: BMAP_ANCHOR_BOTTOM_LEFT,
  105. offset: size,
  106. // 切换城市之间事件
  107. // onChangeBefore: function(){
  108. // alert('before');
  109. // },
  110. // 切换城市之后事件
  111. onChangeAfter: function () {
  112. map.setZoom(13);
  113. }
  114. }));
  115. var data = {$data};
  116. var pointArray = new Array();
  117. for (var i = 0; i < data.length; i++) {
  118. pointArray[i] = new BMap.Point(data[i]['longitude'], data[i]['latitude']);
  119. var marker = new BMap.Marker(new BMap.Point(data[i]['longitude'], data[i]['latitude'])); // 创建点
  120. map.addOverlay(marker); //增加点
  121. var title = data[i]['locationname'];
  122. marker.setLabel(new BMap.Label((i + 1) + ":" + title, {offset: new BMap.Size(20, -10)}));
  123. var content = '<div style="margin:0;line-height:20px;padding:2px;">';
  124. //check picture is null
  125. if (data[i]['picture'] != null && data[i]['picture'] != '') {
  126. content += '<img src="__CDN__' + data[i]['picture'] + '" id="img' + data[i]['id'] + '" alt="" style="float:right;zoom:1;overflow:hidden;width:100px;height:100px;margin-left:3px;"/>';
  127. }
  128. //check address
  129. if (data[i]['detailaddress'] != null && data[i]['detailaddress'] != '') {
  130. content += '地址: ' + data[i]['detailaddress'] + '<br/>';
  131. }
  132. //check phone
  133. if (data[i]['phone'] != null && data[i]['phone'] != '') {
  134. content += '电话: ' + data[i]['phone'] + '<br/>';
  135. }
  136. //check email
  137. if (data[i]['email'] != null && data[i]['email'] != '') {
  138. content += '邮箱: ' + data[i]['email'] + '<br/>';
  139. }
  140. //check fax
  141. if (data[i]['fax'] != null && data[i]['fax'] != '') {
  142. content += '传真: ' + data[i]['fax'] + '<br/>';
  143. }
  144. //check qq
  145. if (data[i]['qq'] != null && data[i]['qq'] != '') {
  146. content += 'QQ: ' + data[i]['qq'] + '<br/>';
  147. }
  148. //check website
  149. if (data[i]['website'] != null && data[i]['website'] != '') {
  150. content += '网址: ' + data[i]['website'] + '<br/>';
  151. }
  152. content += '</div>';
  153. addClickHandler(title, content, marker, "img" + data[i]['id']);
  154. }
  155. //让所有点在视野范围内
  156. map.setViewport(pointArray);
  157. var searchInfoWindow;
  158. function addClickHandler(title, content, marker, id) {
  159. marker.addEventListener("click", function (e) {
  160. openInfo(title, content, e);
  161. });
  162. }
  163. function openInfo(title, content, e) {
  164. var p = e.target;
  165. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  166. map.centerAndZoom(point, 14);
  167. // changeMapStyle('default')
  168. // sel.value = 'default';
  169. // var opts = {
  170. // width: 300, // 信息窗口宽度
  171. // height: 105, // 信息窗口高度
  172. // title: title, // 信息窗口标题
  173. // enableMessage: true//设置允许信息窗发送短息
  174. // };
  175. // var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象
  176. // map.openInfoWindow(infoWindow, point); //开启信息窗口
  177. searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
  178. title: title, //标题
  179. width: 320, //宽度
  180. height: 120, //高度
  181. panel: "panel", //检索结果面板
  182. enableAutoPan: true, //自动平移
  183. searchTypes: [
  184. BMAPLIB_TAB_SEARCH, //周边检索
  185. BMAPLIB_TAB_TO_HERE, //到这里去
  186. BMAPLIB_TAB_FROM_HERE //从这里出发
  187. ]
  188. });
  189. searchInfoWindow.open(point);
  190. }
  191. </script>