map.js 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. (function () {
  2. 'use strict';
  3. var map = new BMap.Map("allmap"); // 创建Map实例
  4. map.centerAndZoom(new BMap.Point(123.432790922, 41.8086447835), 10); // 初始化地图,设置中心点坐标和地图级别
  5. map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  6. map.setMapStyle(
  7. {
  8. style:"light"
  9. }
  10. );
  11. getInfo();
  12. function getInfo() {
  13. var imgname='farm';
  14. $.ajax({
  15. url:"./json/package.json",
  16. type:'get',
  17. dataType:'json',
  18. async:true,
  19. success:function(data)
  20. {
  21. var online = 0;
  22. for (var i = 0; i < data.length; i++) {
  23. (function (x) {
  24. var point = new BMap.Point(data[i].lng,data[i].lat); // 创建点坐标
  25. var myIcon = new BMap.Icon("img/0.png", new BMap.Size(32, 32), {
  26. offset: new BMap.Size(10, 25), // 指定定位位置
  27. imageOffset: new BMap.Size(0,0) // 设置图片偏移
  28. });
  29. var marker = new BMap.Marker(point,{icon:myIcon});
  30. var info = '<div style="width: 200px;height: 160px;background-color: rgba(13, 33, 70, 0.8);border: 1px solid #155596; padding: 12px 0 20px 35px;box-sizing: border-box; position: relative; border-bottom: none;">\n' +
  31. ' <div style="text-align:left; margin-bottom: 2px;">\n' +
  32. ' <span style="font-size: 16px; color: #52d2ff;margin-right: 6px;" >行政区:</span>\n' +
  33. ' <span style="font-size: 14px; color: #fff;">黑三县</span>\n' +
  34. ' </div>' +
  35. ' <div style="text-align: left;margin-bottom: 2px;">\n' +
  36. ' <span style="font-size: 16px; color: #52d2ff;margin-right: 6px;" >观测作物:</span>\n' +
  37. ' <span style="font-size: 14px; color: #fff;">西红柿</span>\n' +
  38. ' </div>' +
  39. ' <div style="text-align: left;margin-bottom: 2px;">\n' +
  40. ' <span style="font-size: 16px; color: #52d2ff;margin-right: 6px;" >站号:</span>\n' +
  41. ' <span style="font-size: 14px; color: #fff;">LOO33</span>\n' +
  42. ' </div>' +
  43. ' <div style="text-align: left;margin-bottom: 2px;">\n' +
  44. ' <span style="font-size: 16px; color: #52d2ff;margin-right: 6px;" >站名:</span>\n' +
  45. ' <span style="font-size: 14px; color: #fff;">西红柿观测站</span>\n' +
  46. ' </div>' +
  47. ' <div style="text-align: left;margin-bottom: 2px;">\n' +
  48. ' <span style="font-size: 16px; color: #52d2ff;margin-right: 6px;" >主板电压:</span>\n' +
  49. ' <span style="font-size: 14px; color: #fff;">21.0V</span>\n' +
  50. ' </div>' +
  51. ' <div style="text-align: left;margin-bottom: 2px;">\n' +
  52. ' <span style="font-size: 16px; color: #52d2ff;margin-right: 6px;" >主板温度:</span>\n' +
  53. ' <span style="font-size: 14px; color: #fff;">12.2℃</span>\n' +
  54. ' </div>\n' +
  55. ' <img src="./img/jiantou.png" alt="" style="display: blolk;position: absolute;bottom: -13px ;right: 0;">\n' +
  56. ' </div>';
  57. var infoBox = new BMapLib.InfoBox(map, info, {
  58. closeIconMargin: "10 10 0 0",
  59. closeIconUrl: "./img/jiantou.png",
  60. enableAutoPan: true,
  61. align: INFOBOX_AT_TOP,
  62. position :1,
  63. offset : new BMap.Size(-5, 30)
  64. });
  65. infoBox.open(marker);
  66. infoBox.hide();
  67. marker.addEventListener("mouseover", function () {
  68. infoBox.show(marker);
  69. });
  70. marker.addEventListener("mouseout", function () {
  71. infoBox.hide(marker);
  72. });
  73. map.addOverlay(marker);
  74. })(i);
  75. }
  76. },
  77. error:function()
  78. {
  79. alert('网络故障,请联系管理员!');
  80. }
  81. });
  82. }
  83. })()