• 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>

  • 相关阅读:
    新风机小助手-风压变速器
    进程的概念
    SQL查询优化---子查询优化、排序分组优化、覆盖索引优化
    Chapter 5 决策树和随机森林实践
    多线程编程(1) - 先入门
    Kotlin高仿微信-第27篇-朋友圈-相册选择图片或小视频
    Vue2 01 前端核心分析、HelloVue
    (六)Mybatis中接口代理机制及使用
    NVIDIA Jetson TX2 解决奥比中光 Astra pro相机的ros 打不开深度信息/camera/depth/image
    生成二维码并支持下载
  • 原文地址:https://blog.csdn.net/u013141712/article/details/134286043