使用Echart搭配百度地图创建某一地区热点图的注意点

举报
拿我格子衫来 发表于 2022/03/18 01:10:02 2022/03/18
【摘要】 使用Echart搭配百度地图创建的热点图,为网友免费做的demo,细节没有调整.记录一下写的过程.   效果图: 代码: <!DOCTYPE html><html style="height: 100%"><head> <meta charset="utf-8"&gt...

使用Echart搭配百度地图创建的热点图,为网友免费做的demo,细节没有调整.记录一下写的过程.

 

效果图:

代码:


  
  1. <!DOCTYPE html>
  2. <html style="height: 100%">
  3. <head>
  4. <meta charset="utf-8">
  5. <style type="text/css">
  6. html, body {
  7. height: 100%;
  8. width: 100%;
  9. }
  10. </style>
  11. </head>
  12. <body style="height: 100%; margin: 0">
  13. <div id="container"
  14. style="height: 600px;width: 600px;margin: 20px auto;position: relative;top: 50%;margin-top: -300px"></div>
  15. <script type="text/javascript" src="http://echarts.baidu.com/examples/vendors/jquery/jquery.js"></script>
  16. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
  17. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
  18. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
  19. <script type="text/javascript"
  20. src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
  21. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
  22. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
  23. <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=NqENdsDTP1QxhUn047Z7C6Tfsgv5X1mj"></script>
  24. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
  25. <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>
  26. <script type="text/javascript">
  27. var dom = document.getElementById('container')
  28. var myChart = echarts.init(dom)
  29. var app = {}
  30. option = null
  31. app.title = '热力图与百度地图扩展'
  32. var points = [
  33. [114.295024, 22.632375],
  34. [114.295124, 22.632475],
  35. [114.295224, 22.632575],
  36. [114.295324, 22.632675],
  37. [114.295424, 22.632775],
  38. [114.295524, 22.632875],
  39. [114.295624, 22.632975],
  40. [114.295724, 22.633075],
  41. [114.295824, 22.633175],
  42. [114.295924, 22.633275],
  43. [114.296024, 22.633375],
  44. [114.296124, 22.633475],
  45. [114.296224, 22.633575],
  46. [114.296324, 22.633675],
  47. [114.296424, 22.633775],
  48. [114.296524, 22.633875],
  49. [114.296624, 22.633975],
  50. [114.296724, 22.634075],
  51. [114.296824, 22.634175],
  52. [114.296924, 22.634275],
  53. [114.297024, 22.634375],
  54. [114.297124, 22.634475],
  55. [114.297224, 22.634575],
  56. [114.297324, 22.634675],
  57. [114.297424, 22.634775],
  58. [114.297524, 22.634875],
  59. [114.297624, 22.634975],
  60. [114.297724, 22.635075],
  61. [114.297824, 22.635175],
  62. [114.297924, 22.635275],
  63. [114.298024, 22.635375],
  64. [114.298124, 22.635475],
  65. [114.298224, 22.635575],
  66. [114.298324, 22.635675],
  67. [114.298424, 22.635775],
  68. [114.298524, 22.635875],
  69. [114.298624, 22.635975],
  70. [114.298724, 22.636075],
  71. [114.298824, 22.636175],
  72. [114.298924, 22.636275],
  73. [114.299024, 22.636375],
  74. [114.299124, 22.636475],
  75. [114.299224, 22.636575],
  76. [114.299324, 22.636675],
  77. [114.299424, 22.636775],
  78. [114.299524, 22.636875],
  79. [114.299624, 22.636975],
  80. [114.299724, 22.637075],
  81. [114.299824, 22.637175],
  82. [114.299924, 22.637275]]
  83. myChart.setOption(option = {
  84. animation: false,
  85. bmap: {
  86. center: [114.294924, 22.632275],
  87. zoom: 15,
  88. roam: false,
  89. mapStyle: {style: 'midnight'},
  90. enableMapClick:false
  91. },
  92. visualMap: {
  93. show: false,
  94. top: 'top',
  95. min: 0,
  96. max: 5,
  97. seriesIndex: 0,
  98. calculable: false,
  99. inRange: {
  100. color: ['blue', 'blue', 'green', 'yellow', 'red']
  101. }
  102. },
  103. series: [{
  104. type: 'heatmap',
  105. coordinateSystem: 'bmap',
  106. data: points,
  107. pointSize: 5,
  108. blurSize: 6
  109. }]
  110. })
  111. var markerDataArr = [
  112. {num: 1, point: [114.294924, 22.632275], imgurl: '', text: '东部华侨城'},
  113. {num: 2, point: [114.295031, 22.624567], imgurl: '', text: '东部华侨城大峡谷'},
  114. {num: 3, point: [114.309861, 22.614975], imgurl: '', text: '茶溪谷大峡谷'},
  115. {num: 4, point: [114.30691, 22.623766], imgurl: '', text: '华侨酒店'},
  116. {num: 6, point: [114.312242, 22.610332], imgurl: '', text: '华侨城总站'},
  117. {num: 7, point: [114.30165, 22.614285], imgurl: '', text: '东部华侨城天麓'},
  118. {num: 8, point: [114.284623, 22.636045], imgurl: '', text: '茵特拉根会议中心'},
  119. {num: 9, point: [114.286962, 22.638202], imgurl: '', text: '东部华侨城茶溪谷'},
  120. {num: 10, point: [114.283761, 22.647719], imgurl: '', text: '三洲田水库'}
  121. ]
  122. if (!app.inNode) {
  123. // 添加百度地图插件
  124. var bmap = myChart.getModel().getComponent('bmap').getBMap()
  125. // bmap.setEnableMapClick('false')
  126. //MapOptions{ enableMapClick:false}
  127. var myIcon = new BMap.Icon('./0.png', new BMap.Size(42, 56))
  128. for (var i = 0; i < markerDataArr.length; i++) {
  129. var item = markerDataArr[i]
  130. var pointItem = new BMap.Point(item.point[0], item.point[1])
  131. var opts = {
  132. position: pointItem, // 指定文本标注所在的地理位置
  133. offset: new BMap.Size(-30, 30) //设置文本偏移量
  134. }
  135. var label = new BMap.Label(item.text, opts) // 创建文本标注对象
  136. label.setStyle({
  137. color: '#fff',
  138. backgroundColor: 'transform',
  139. border: 'none',
  140. fontSize: '12px',
  141. fontFamily: '微软雅黑'
  142. })
  143. var mapMaker = new BMap.Marker(pointItem, {icon: myIcon})
  144. bmap.addOverlay(mapMaker)
  145. bmap.addOverlay(label)
  146. }
  147. }
  148. </script>
  149. </body>
  150. </html>

 

代码解释及注意点:

  1. 搭配地图插件需要引入相应的库
  2. 使用
    var bmap = myChart.getModel().getComponent('bmap').getBMap()  // 获取百度地图对象 从而使用地图api
  3. 多查API,对比官方给出的例子,不是太难的功能都能做出的出来

文章来源: fizzz.blog.csdn.net,作者:拿我格子衫来,版权归原作者所有,如需转载,请联系作者。

原文链接:fizzz.blog.csdn.net/article/details/82979130

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。