index.html 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="keywords" content="百度地图,百度地图API,百度地图自定义工具,百度地图所见即所得工具" />
  6. <meta name="description" content="百度地图API自定义地图,帮助用户在可视化操作下生成百度地图" />
  7. <title>百度地图API自定义地图</title>
  8. <!--引用百度地图API-->
  9. <style type="text/css">
  10. html,body{margin:0;padding:0;}
  11. .iw_poi_title {color:#CC5522;font-size:14px;font-weight:bold;overflow:hidden;padding-right:13px;white-space:nowrap}
  12. .iw_poi_content {font:12px arial,sans-serif;overflow:visible;padding-top:4px;white-space:-moz-pre-wrap;word-wrap:break-word}
  13. </style>
  14. <script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.1&services=true"></script>
  15. </head>
  16. <body onload="initMap();">
  17. <!--百度地图容器-->
  18. <div style="width:697px;height:550px;border:#ccc solid 1px;" id="dituContent"></div>
  19. </body>
  20. <script type="text/javascript">
  21. function getParam(name) {
  22. return location.href.match(new RegExp('[?&]' + name + '=([^?&]+)', 'i')) ? decodeURIComponent(RegExp.$1) : '';
  23. }
  24. var centerParam = getParam('center');
  25. var zoomParam = getParam('zoom');
  26. var widthParam = getParam('width');
  27. var heightParam = getParam('height');
  28. var markersParam = getParam('markers');
  29. var markerStylesParam = getParam('markerStyles');
  30. //创建和初始化地图函数:
  31. function initMap(){
  32. // [FF]切换模式后报错
  33. if (!window.BMap) {
  34. return;
  35. }
  36. var dituContent = document.getElementById('dituContent');
  37. dituContent.style.width = widthParam + 'px';
  38. dituContent.style.height = heightParam + 'px';
  39. createMap();//创建地图
  40. setMapEvent();//设置地图事件
  41. addMapControl();//向地图添加控件
  42. // 创建标注
  43. var markersArr = markersParam.split(',');
  44. var point = new BMap.Point(markersArr[0], markersArr[1]);
  45. var marker = new BMap.Marker(point);
  46. map.addOverlay(marker); // 将标注添加到地图中
  47. }
  48. //创建地图函数:
  49. function createMap(){
  50. var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
  51. var centerArr = centerParam.split(',');
  52. var point = new BMap.Point(centerArr[0], centerArr[1]);//定义一个中心点坐标
  53. map.centerAndZoom(point, zoomParam);//设定地图的中心点和坐标并将地图显示在地图容器中
  54. window.map = map;//将map变量存储在全局
  55. }
  56. //地图事件设置函数:
  57. function setMapEvent(){
  58. map.enableDragging();//启用地图拖拽事件,默认启用(可不写)
  59. map.enableScrollWheelZoom();//启用地图滚轮放大缩小
  60. map.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
  61. map.enableKeyboard();//启用键盘上下左右键移动地图
  62. }
  63. //地图控件添加函数:
  64. function addMapControl(){
  65. //向地图中添加缩放控件
  66. var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
  67. map.addControl(ctrl_nav);
  68. //向地图中添加缩略图控件
  69. var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
  70. map.addControl(ctrl_ove);
  71. //向地图中添加比例尺控件
  72. var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
  73. map.addControl(ctrl_sca);
  74. }
  75. </script>
  76. </html>