baidumap.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <script type="text/javascript"
  5. src="https://api.map.baidu.com/api?v=2.0&ak=B74ya3RGhwWIdc8dwN2SfZOYD9G8kXiu"></script>
  6. <script src="https://mapv.baidu.com/build/mapv.min.js"></script>
  7. <meta charset="UTF-8">
  8. <title>你好</title>
  9. </head>
  10. <style>
  11. html, body {
  12. height: 100%;
  13. width: 100%;
  14. margin: 0;
  15. padding: 0;
  16. box-sizing: border-box;
  17. }
  18. </style>
  19. <body>
  20. <div id="allmap" style="height: 100%;width: 100%"></div>
  21. </body>
  22. <script>
  23. const thyyLocation = new BMap.Point(112.96716239793697, 28.309655062968343)
  24. let thyy = null
  25. let event = null
  26. let patientInfo = null
  27. function setIcon(val) {
  28. thyy = val
  29. }
  30. function eventFunc(data) {
  31. event = data
  32. }
  33. function createADrawing(data) {
  34. map.clearOverlays()
  35. createAHospitalLogo()
  36. let points = []
  37. for (let i = 0, len = data.length; i < len; i++) {
  38. let item = data[i];
  39. points.push({
  40. geometry: {
  41. type: 'Point',
  42. patientData: item,
  43. coordinates: [item.longitude, item.latitude]
  44. },
  45. })
  46. }
  47. const dataSet = new mapv.DataSet(points);
  48. const options = {
  49. shadowColor: 'rgba(255, 250, 50, 1)',
  50. shadowBlur: 10,
  51. // 非聚合点的颜色和大小,未设置icon或icon获取失败时使用
  52. fillStyle: 'rgba(255, 50, 0, 1.0)',
  53. size: 50 / 3 / 2, // 非聚合点的半径
  54. minSize: 8, // 聚合点最小半径
  55. maxSize: 31, // 聚合点最大半径
  56. globalAlpha: 0.8, // 透明度
  57. clusterRadius: 150, // 聚合像素半径
  58. maxClusterZoom: 18, // 最大聚合的级别
  59. maxZoom: 19, // 最大显示级别
  60. minPoints: 5, // 最少聚合点数,点数多于此值才会被聚合
  61. extent: 400, // 聚合的细腻程度,越高聚合后点越密集
  62. label: { // 聚合文本样式
  63. show: true, // 是否显示
  64. fillStyle: 'white',
  65. },
  66. gradient: {0: "blue", 0.5: "#28f51a", 1.0: "rgb(255,0,0)"}, // 聚合图标渐变色
  67. draw: 'cluster',
  68. methods: {
  69. click(point) {
  70. if (point?.geometry?.patientData) {
  71. deletePreviousPunctuation()
  72. // 清空上一次的患者信息
  73. if (patientInfo !== null) {
  74. map.removeOverlay(new BMap.Point(patientInfo.longitude, patientInfo.latitude))
  75. }
  76. // 复制下一次患者信息
  77. patientInfo = point?.geometry?.patientData
  78. patientInfo.mapPoint = new BMap.Point(patientInfo.longitude, patientInfo.latitude)
  79. event['pointClick'](patientInfo)
  80. locateThePatient()
  81. marker()
  82. }
  83. }
  84. }
  85. }
  86. new mapv.baiduMapLayer(map, dataSet, options);
  87. }
  88. function deletePreviousPunctuation() {
  89. let data = map.getOverlays()
  90. for (let i = 0; i < data.length; i++) {
  91. let item = data[i]
  92. if (data[i].id) {
  93. if (data[i].id === patientInfo.patNo) {
  94. map.removeOverlay(item)
  95. }
  96. }
  97. }
  98. }
  99. function locateThePatient() {
  100. map.panTo(patientInfo.mapPoint)
  101. }
  102. const marker = () => {
  103. const marker = new BMap.Marker(patientInfo.mapPoint);
  104. marker.id = patientInfo.patNo
  105. map.addOverlay(marker)
  106. }
  107. function createAHospitalLogo() {
  108. map.clearOverlays()
  109. const myIcon = new BMap.Icon(thyy, new BMap.Size(40, 40));
  110. myIcon.setImageSize(new BMap.Size(40, 40))
  111. const marker = new BMap.Marker(thyyLocation, {
  112. icon: myIcon
  113. });
  114. map.addOverlay(marker);
  115. }
  116. window.onload = () => {
  117. // 创建Map实例
  118. window.map = new BMap.Map("allmap", {
  119. enableMapClick: false
  120. });
  121. // 初始化地图,设置中心点坐标和地图级别
  122. map.centerAndZoom(thyyLocation, 15);
  123. // 开启鼠标滚轮缩放
  124. map.enableScrollWheelZoom(true);
  125. }
  126. </script>
  127. </html>