• vue中使用高德地图的热力图方法1


    第一步:注册高德的key =》webapi的

    第二步骤:在vue.config.js中配置Amap

    1. module.exports = defineConfig({
    2. transpileDependencies: true,
    3. productionSourceMap: false,
    4. configureWebpack: {
    5. externals: {
    6. "AMap": "AMap"
    7. }
    8. },
    9. })

    第三步:引入js文件,带上key,就可以使用了,记得先重启服务,否则上面步骤配置不生效

    1. <template>
    2. <section>
    3. <div id="container" style="width:100%; height:680px; margin-top: 20px"></div>
    4. </section>
    5. </template>
    6. <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你的key"></script>
    7. <script src="https://a.amap.com/jsapi_demos/static/resource/heatmapData.js"></script>
    8. <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    9. <script>
    10. import AMap from 'AMap'
    11. export default {
    12. name: "home",
    13. data() {
    14. return {
    15. }
    16. },
    17. methods: {
    18. init() {
    19. var map = new AMap.Map("container", {
    20. resizeEnable: true,
    21. center: [116.418261, 39.921984],
    22. zoom: 11
    23. });
    24. if (!this.isSupportCanvas()) {
    25. alert('热力图仅对支持canvas的浏览器适用,您所使用的浏览器不能使用热力图功能,请换个浏览器试试~')
    26. }
    27. var heatmap;
    28. map.plugin(["AMap.Heatmap"], function () {
    29. //初始化heatmap对象
    30. heatmap = new AMap.Heatmap(map, {
    31. radius: 25, //给定半径
    32. opacity: [0, 0.8]
    33. /*,
    34. gradient:{
    35. 0.5: 'blue',
    36. 0.65: 'rgb(117,211,248)',
    37. 0.7: 'rgb(0, 255, 0)',
    38. 0.9: '#ffea00',
    39. 1.0: 'red'
    40. }
    41. */
    42. });
    43. //设置数据集:该数据为北京部分“公园”数据
    44. heatmap.setDataSet({
    45. data: heatmapData,
    46. max: 100
    47. });
    48. });
    49. },
    50. //判断浏览区是否支持canvas
    51. isSupportCanvas() {
    52. var elem = document.createElement('canvas');
    53. return !!(elem.getContext && elem.getContext('2d'));
    54. }
    55. },
    56. mounted() {
    57. this.init();
    58. },
    59. }
    60. </script>
    61. <style scoped>
    62. * {
    63. padding: 0;
    64. margin: 0;
    65. }
    66. #map {
    67. margin-top: 20px;
    68. height: 680px;
    69. }
    70. </style>

  • 相关阅读:
    Vue 项目实战——如何在页面中展示 PDF 文件以及 PDFObject 插件实战
    产业园区中工业厂房的能源综合配置
    git基本使用
    面试官:说一下MySQL事务隔离级别?
    算法竞赛入门【码蹄集进阶塔335题】(MT2281-2285)
    场馆如何进行智能改造?
    python 练习9.14
    7-3 投票统计 武汉理工大学C语言
    忽视日志吃大亏,手把手教你玩转 SpringBoot 日志
    WebSocket 协议详解
  • 原文地址:https://blog.csdn.net/u013141712/article/details/134286043