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

  • 相关阅读:
    云原生之深入解析如何合并多个kubeconfig文件
    Greenplum数据库外部表——fileam封装
    Alkyne-Con A,炔基功能化刀豆球蛋白A,ALK-Concanavalin A
    怎么把Mesh转为SDF
    论文阅读笔记(三)——有监督解耦+信息瓶颈
    Python零基础提问,如何获取下拉菜单中的数据和文本?
    【高阶数据结构】并查集和图
    ICCV, ECCV, CVPR,IEEE的关系
    数字工厂里,看见钉钉
    SpringCloud学习笔记
  • 原文地址:https://blog.csdn.net/u013141712/article/details/134286043