zddtMap.htm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #allmap {
  7. width: 100%;
  8. height: 100%;
  9. overflow: hidden;
  10. margin: 0;
  11. font-family: "微软雅黑";
  12. }
  13. </style>
  14. <title>站点地图</title>
  15. </head>
  16. <body>
  17. <div id="allmap" style="width:980px; height:495px;"></div>
  18. </body>
  19. </html>
  20. <script type="text/javascript">
  21. var map = new BMap.Map("allmap");
  22. initMap();
  23. //创建和初始化地图函数:
  24. function initMap(){
  25. createMap(); //创建地图
  26. setMapEvent(); //设置地图事件
  27. addMapControl();//向地图添加控件
  28. addMcdaList(); //添加牧场
  29. }
  30. //创建地图
  31. function createMap(){
  32. map.clearOverlays();//清空原来的标注
  33. map.centerAndZoom("东阳市", 8);
  34. }
  35. //设置地图事件
  36. function setMapEvent(){
  37. map.enableScrollWheelZoom();
  38. map.enableKeyboard();
  39. map.enableDragging();
  40. map.enableDoubleClickZoom()
  41. }
  42. //向地图添加控件
  43. function addMapControl(){
  44. var navControl = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
  45. map.addControl(navControl);
  46. var overviewControl = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:true});
  47. map.addControl(overviewControl);
  48. }
  49. //添加牧场
  50. function addMcdaList() {
  51. #foreach ($o in $!mcdaList)
  52. searchByStationName("$o.id","$o.mcmc", "$o.mcdz", "$o.longitude", "$o.latitude");
  53. #end
  54. }
  55. //根据地址查经纬度
  56. function searchByStationName(id,mcmc,xxdz,lng,lat) {
  57. //有经纬度
  58. if (lng != null && lng != "" && lat != null && lat != "" && lng.match(/^[0-9].*$/) && lat.match(/^[0-9].*$/)) {
  59. var marker = new BMap.Marker(new BMap.Point(lng,lat));
  60. map.addOverlay(marker);
  61. // var label = new BMap.Label(mcmc);//标签
  62. // marker.setLabel(label);
  63. var opts = {
  64. width: 100,
  65. height: 50,
  66. title: "<font style='font-weight:bold'>"+ mcmc +"</font>"
  67. }
  68. var infoWindow = new BMap.InfoWindow("地址:" + xxdz, opts);
  69. // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
  70. addClickHandler(marker,id);
  71. marker.addEventListener("mouseover", function() {
  72. marker.openInfoWindow(infoWindow);
  73. });
  74. marker.addEventListener("mouseout", function() {
  75. marker.closeInfoWindow(infoWindow);
  76. });
  77. } else {
  78. var myGeo = new BMap.Geocoder();
  79. myGeo.getPoint(xxdz, function(point) {
  80. if (point) {
  81. var marker = new BMap.Marker(point);
  82. map.addOverlay(marker);
  83. // var label = new BMap.Label(mcmc);//标签
  84. // marker.setLabel(label);
  85. var opts = {
  86. width: 100,
  87. height: 10,
  88. title: "<font style='font-weight:bold'>"+ mcmc +"</font>"
  89. }
  90. var infoWindow = new BMap.InfoWindow("地址:" + xxdz, opts);
  91. // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
  92. addClickHandler(marker,id);
  93. marker.addEventListener("mouseover", function() {
  94. marker.openInfoWindow(infoWindow);
  95. });
  96. marker.addEventListener("mouseout", function() {
  97. marker.closeInfoWindow(infoWindow);
  98. });
  99. }
  100. });
  101. }
  102. }
  103. //添加点击事件
  104. function addClickHandler(target, id) {
  105. target.addEventListener("click",function(){
  106. localStorage.setItem("yzgkRight", "dttj");
  107. localStorage.setItem("mcid", id);
  108. setFocus(4, 0);
  109. loadMainBodyPanel("yzgk", "a4b4");
  110. });
  111. }
  112. </script>