• vue中引入高德地图Loca数据可视化


    目录

    引言:

    关键词:

    正文:

    一、如何安装或者引入:

    二、如何引入:

    三、如何使用:

    四、完整代码:

    五、效果图

     参考:


    引言:

            前面我的文章介绍了vue中引入高德地图实例的,详情可以去参考,由于需求增加,地图要做的更加美观、数据更加符合真实的空间数据呈现,依旧选择高德地图的API,这里我们选择引入高德地图 在vue中加载 数据可视化 Loca api 2.0版本。

    关键词:

            vue、高德地图、LOCA、数据可视化

    正文:

            Loca 数据可视化 API 2.0(以下简称为LOCA API 2.0)是一个基于高德地图JS API 2.0的高性能地图数据可视化库。其中Loca 2.x版本的要比1.3版本的相比,性能提升了和渲染效果更好,这是因为它们不同的架构模式和渲染管线;而且,2.0版本还引入了自定义镜头动画、图层动效、光照和材质等能力。此处注意一下你的版本兼容性!

    一、如何安装或者引入:

    方式一:

            通过npm引入:

    npm i @amap/amap-jsapi-loader --save

    方式二:

            通过标签CDN引入:

    1. "https://webapi.amap.com/maps?v=2.0&key=您申请的key值">
    2. <script src="https://webapi.amap.com/loca?v=2.0.0&key=您申请的key值">script>

    二、如何引入:

    通过npm安装的依赖引入,如下:

    import AMapLoader from '@amap/amap-jsapi-loader';

    三、如何使用:

    注意版本号要选择 2.0!

    1. AMapLoader.load({
    2. "key": "ec5517c7d9a73dae44xxxxxxxxxxx", //申请好的Web端开发者Key,首次调用load时必填
    3. "version": "2.0", //指定要加载的JSAPI的版本,缺省时默认为1.4.15
    4. "plugins": ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
    5. "Loca":{ //是否加载 Loca,缺省不加载
    6. "version": '2.0.0' //Loca 版本,缺省1.3.2
    7. }
    8. }).then((AMap)=>{
    9. this.map = new AMap.Map('container', {
    10. zoom: 15.82,
    11. center: [81.214768,43.836157],
    12. pitch: 80,
    13. rotation: 205,
    14. showLabel: true, //不显示地名
    15. showBuildingBlock: true, //显示建筑物
    16. viewMode: '3D', //查看视野
    17. });
    18. this.loca = new Loca.Container({
    19. map: this.map
    20. });
    21. //....其他配置代码,参考下文全量代码
    22. })

    四、完整代码:

    1. <script>
    2. import AMapLoader from '@amap/amap-jsapi-loader';
    3. export default {
    4. name: "home",
    5. data() {
    6. return {
    7. mapStyle: "amap://styles/normal", //地图背景模式
    8. loca: null,
    9. map: null,
    10. featuresDataTest: [
    11. {
    12. type: 'Feature',
    13. geometry: {
    14. type: 'Point',
    15. coordinates: [81.218792, 43.841619],
    16. },
    17. properties: {
    18. name: '一号灌溉区',
    19. price: 65000,
    20. count: 92
    21. }
    22. },
    23. {
    24. type: 'Feature',
    25. geometry: {
    26. type: 'Point',
    27. coordinates: [81.20927,43.836963],
    28. },
    29. properties: {
    30. name: '2号灌溉区',
    31. price: 65000,
    32. count: 52
    33. }
    34. },
    35. {
    36. type: 'Feature',
    37. geometry: {
    38. type: 'Point',
    39. coordinates: [81.20927,43.836963],
    40. },
    41. properties: {
    42. name: '3号灌溉区',
    43. price: 49000,
    44. count: 53,
    45. },
    46. },
    47. {
    48. type: 'Feature',
    49. geometry: {
    50. type: 'Point',
    51. coordinates: [81.190621,43.838342],
    52. },
    53. properties: {
    54. name: '4号灌溉区',
    55. price: 62000,
    56. count: 639,
    57. },
    58. },
    59. {
    60. type: 'Feature',
    61. geometry: {
    62. type: 'Point',
    63. coordinates: [81.203593,43.83431],
    64. },
    65. properties: {
    66. name: '5号灌溉区',
    67. price: 48000,
    68. count: 651,
    69. },
    70. },
    71. ]
    72. }
    73. },
    74. methods: {
    75. //获取当前时间看是白天还是晚上
    76. getCurrentTime() {
    77. let currentDate = new Date(),
    78. hours = currentDate.getHours();
    79. if (hours >= 19) {
    80. this.mapStyle = "amap://styles/darkblue";
    81. } else {
    82. this.mapStyle = "amap://styles/normal";
    83. }
    84. },
    85. //初始化地图
    86. initMap(){
    87. AMapLoader.load({
    88. "key": "ec5517c7d9a73dae44xxxxxxxxxxx", //申请好的Web端开发者Key,首次调用load时必填
    89. "version": "2.0", //指定要加载的JSAPI的版本,缺省时默认为1.4.15
    90. "plugins": ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
    91. "Loca":{ //是否加载 Loca,缺省不加载
    92. "version": '2.0.0' //Loca 版本,缺省1.3.2
    93. }
    94. }).then((AMap)=>{
    95. this.map = new AMap.Map('container', {
    96. zoom: 15.82,
    97. center: [81.214768,43.836157],
    98. pitch: 80,
    99. rotation: 205,
    100. showLabel: true, //不显示地名
    101. showBuildingBlock: true, //显示建筑物
    102. viewMode: '3D', //查看视野
    103. });
    104. this.loca = new Loca.Container({
    105. map: this.map
    106. });
    107. var geo = new Loca.GeoJSONSource({
    108. data: {
    109. "type": "FeatureCollection",
    110. "features": this.featuresDataTest
    111. }
    112. });
    113. // 文字主体图层
    114. var zMarker = new Loca.ZMarkerLayer({
    115. loca: this.loca,
    116. zIndex: 120,
    117. depth: false
    118. });
    119. zMarker.setSource(geo);
    120. zMarker.setStyle({
    121. content: (i, feat) => {
    122. var props = feat.properties;
    123. var leftColor = props.price < 60000 ? 'rgba(0, 28, 52, 0.6)' : 'rgba(33,33,33,0.6)';
    124. var rightColor = props.price < 60000 ? '#038684' : 'rgba(172, 137, 51, 0.3)';
    125. var borderColor = props.price < 60000 ? '#038684' : 'rgba(172, 137, 51, 1)';
    126. return (
    127. '
      ' +
    128. '

      + leftColor + ',' + leftColor + ',' + rightColor + ',rgba(0,0,0,0.4)); border:4px solid '
    129. + borderColor + '; color:#fff; border-radius: 15px; text-align:center; margin:0; padding:5px;">' +
    130. props['name'] +
    131. ': ' +
    132. (props['price'] / 10000) + `m3` +
    133. '

      + (props['price'] < 60000 ? 'blue' : 'yellow') + '.png);">
      '
    134. );
    135. },
    136. unit: 'meter',
    137. rotation: 0,
    138. alwaysFront: true,
    139. size: [490/2, 222/2],
    140. altitude: 0
    141. });
    142. // 浮动三角
    143. var triangleZMarker = new Loca.ZMarkerLayer({
    144. loca: this.loca,
    145. zIndex: 119,
    146. depth: false
    147. });
    148. triangleZMarker.setSource(geo);
    149. triangleZMarker.setStyle({
    150. content: (i, feat) => {
    151. return (
    152. '
      + (feat.properties.price < 60000 ? 'blue' : 'yellow')
    153. + '.png);">
      '
  • );
  • },
  • unit: 'meter',
  • rotation: 0,
  • alwaysFront: true,
  • size: [60, 60],
  • altitude: 15
  • });
  • triangleZMarker.addAnimate({
  • key: 'altitude',
  • value: [0, 1],
  • random: true,
  • transform: 1000,
  • delay: 2000,
  • yoyo: true,
  • repeat: 999999
  • });
  • // 呼吸点 蓝色
  • var scatterBlue = new Loca.ScatterLayer({
  • loca: this.loca,
  • zIndex: 110,
  • opacity: 1,
  • visible: true,
  • zooms: [2, 26],
  • depth: false
  • });
  • scatterBlue.setSource(geo);
  • scatterBlue.setStyle({
  • unit: 'meter',
  • size: function (i, feat) {
  • return feat.properties.price < 60000 ? [90, 90] : [0, 0];
  • },
  • texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/scan_blue.png',
  • altitude: 20,
  • duration: 2000,
  • animate: true
  • });
  • // 呼吸点 金色
  • var scatterYellow = new Loca.ScatterLayer({
  • loca: this.loca,
  • zIndex: 110,
  • opacity: 1,
  • visible: true,
  • zooms: [2, 26],
  • depth: false
  • });
  • scatterYellow.setSource(geo);
  • scatterYellow.setStyle({
  • unit: 'meter',
  • size: function (i, feat) {
  • return feat.properties.price > 60000 ? [90, 90] : [0, 0];
  • },
  • texture: 'https://a.amap.com/Loca/static/loca-v2/demos/images/scan_yellow.png',
  • altitude: 20,
  • duration: 2000,
  • animate: true
  • });
  • // 启动帧
  • this.loca.animate.start();
  • })
  • },
  • },
  • mounted(){
  • if(!this.map){
  • this.initMap();
  • }
  • }
  • }
  • script>
  • 五、效果图

     参考:

    1.、参考手册-LOCA 数据可视化 API 2.0 | 高德地图API

    2.、某片区房价信息-标牌点-示例详情-Loca API 2.0 | 高德地图API

  • 相关阅读:
    【FusionInsight 迁移】HBase从C50迁移到6.5.1(03)6.5.1上准备Loader
    zgc各版本信息收集统计
    通关GO语言21 网络编程:Go 语言如何玩转 RESTful API 服务?
    Java学生管理系统
    Flink源码阅读笔记——StreamGraph、JobGraph、ExecutionGraph
    【web-攻击访问控制】(5.3)保障访问控制的安全:多层权限模型
    uView自定义图标和普通引入图标(iconfont-阿里巴巴图标库)
    新的node节点加入集群
    嵌入式Linux驱动开发(同步与互斥专题)(二)
    一篇图解Linux内存碎片整理
  • 原文地址:https://blog.csdn.net/XU441520/article/details/127666094