• Vue中如何实现城市3D分布图


    178775c61d0b1e487633f49f70c844b4.png

    cityfenbu.vue

    1.   
    2.   
    3.   "scss" scoped>
    4.   .seriesmap-box-card {
    5.     color:rgb(191, 203, 217);
    6.     background:#2d3a4b;
    7.     width: 100%;
    8.     height: 100%;
    9.     font-size: 14px;
    10.     .clearfix:before,
    11.     .clearfix:after {
    12.       display: table;
    13.       content: "";
    14.     }
    15.     .clearfix:after {
    16.       clear: both
    17.     }
    18.     .series-map {
    19.       cursor:move;
    20.     }
    21.   }
    22.   

    resize.js

    1. import { debounce } from "./debounce.js";
    2. export default {
    3.   data() {
    4.     return {
    5.       myChart: null,
    6.       resizeHandler: null
    7.     };
    8.   },
    9.   computed: {},
    10.   mounted() {
    11.     this.resizeHandler = debounce(() => {
    12.       if (this.myChart) {
    13.         this.myChart.resize();
    14.       }
    15.     }, 100);
    16.     this.initResizeEvent();
    17.   },
    18.   methods: {
    19.     //监听resize
    20.     initResizeEvent() {
    21.       window.addEventListener("resize", this.resizeHandler);
    22.     },
    23.     //移除resize
    24.     destroyResizeEvent() {
    25.       window.removeEventListener("resize", this.resizeHandler);
    26.     }
    27.   },
    28.   beforeDestroy() {
    29.     this.destroyResizeEvent();
    30.     if (!this.myChart) {
    31.       return;
    32.     }
    33.     this.myChart.dispose();
    34.     this.myChart.off("click");
    35.     this.myChart = null;
    36.   },
    37.   activated() {
    38.     this.initResizeEvent();
    39.     if (this.myChart) {
    40.       this.myChart.resize();
    41.     }
    42.   },
    43.   deactivated() {
    44.     this.destroyResizeEvent();
    45.   },
    46.   watch: {}
    47. };

    getGeoJson.js

    1. /**
    2.  * 获取geoJson数据 通过高德获取 递归获取区县geoJson
    3.  * @param {string} adcode 行政区code
    4.  * @param {string} childAdcode 区县级行政区code
    5.  * @return {Array}
    6.  */
    7. import remoteLoad from "./remoteLoad.js";
    8. const  {AMapCDN, AMapUiCDN} = require("./cdn.js");
    9. export function getGeoJson(adcode, childAdcode = "") {
    10.     return new Promise((resolve, reject) => {
    11.       if (window.AMap && window.AMapUI) {
    12.         insideFun(adcode, childAdcode);
    13.       } else {
    14.         remoteLoad(AMapCDN).then(() => {
    15.           if (window.AMap) {
    16.             remoteLoad(AMapUiCDN).then(() => {
    17.               if (window.AMapUI) {
    18.                 insideFun(adcode, childAdcode);
    19.               } else {
    20.                 console.error("AMapUI获取失败");
    21.               }
    22.             });
    23.           } else {
    24.             console.error("AMap获取失败");
    25.           }
    26.         });
    27.       }
    28.       function insideFun(adcode, childAdcode) {
    29.         // eslint-disable-next-line
    30.         AMapUI.loadUI(["geo/DistrictExplorer"], DistrictExplorer => {
    31.           var districtExplorer = new DistrictExplorer();
    32.           districtExplorer.loadAreaNode(adcode, function(error, areaNode) {
    33.             if (error) {
    34.               console.error(error);
    35.               reject(error);
    36.               return;
    37.             }
    38.             let Json = areaNode.getSubFeatures();
    39.             if (Json.length === 0) {
    40.               let parent = areaNode._data.geoData.parent.properties.acroutes;
    41.               insideFun(parent[parent.length - 1], adcode);
    42.               return;
    43.             }
    44.   
    45.             if (childAdcode) {
    46.               Json = Json.filter(item => {
    47.                 return item.properties.adcode == childAdcode;
    48.               });
    49.             }
    50.             let mapJson = {
    51.               features: Json
    52.             };
    53.             resolve(mapJson);
    54.           });
    55.         });
    56.       }
    57.     });
    58.   }

    getMapChartData.js

    1. import { getGeoJson } from "./getGeoJson.js";
    2. /** 地图数据
    3.  * @param {string} adcode 城市code
    4.  * @returns {Array}
    5.  */
    6. export function getMapChartData(adcode) {
    7.   return new Promise((resolve, reject) => {
    8.     getGeoJson(adcode)
    9.       .then(res => {
    10.         const data = res.features;
    11.         const mapData = data.map(item => {
    12.           return {
    13.             name: item.properties.name,
    14.             value: parseFloat((Math.random() * 3000).toFixed(2)),
    15.             adcode: item.properties.adcode,
    16.             level: item.properties.level
    17.           };
    18.         });
    19.         resolve({
    20.           code: 200,
    21.           data: mapData
    22.         });
    23.       })
    24.       .catch(error => {
    25.         reject(error);
    26.       });
    27.   });
    28. }
    29. /** 地图数据 散点
    30.  * @param {string} adcode 城市code
    31.  * @returns {Array}
    32.  */
    33. export function getPointChartData(adcode) {
    34.   return new Promise((resolve, reject) => {
    35.     getGeoJson(adcode)
    36.       .then(res => {
    37.         const data = res.features;
    38.         const mapData = data.map(item => {
    39.           return {
    40.             name: item.properties.name,
    41.             value: [
    42.               item.properties.center[0],
    43.               item.properties.center[1],
    44.               parseFloat((Math.random(0.1, 1) * 1000).toFixed(2))
    45.             ],
    46.             adcode: item.properties.adcode,
    47.             level: item.properties.level
    48.           };
    49.         });
    50.         resolve({
    51.           code: 200,
    52.           data: mapData
    53.         });
    54.       })
    55.       .catch(error => {
    56.         reject(error);
    57.       });
    58.   });
    59. }
    60. /** 地图数据 热力图
    61.  * @param {string} adcode 城市code
    62.  * @returns {Array}
    63.  */
    64. export function getHotMapChartData(adcode) {
    65.   const data = [
    66.     {
    67.       name: "地点1",
    68.       value: [114.412021, 30.481201, 1000]
    69.     },
    70.     {
    71.       name: "地点2",
    72.       value: [114.411266, 30.480921, 1000]
    73.     },
    74.     {
    75.       name: "地点3",
    76.       value: [114.411985, 30.481387, 1000]
    77.     },
    78.     {
    79.       name: "地点4",
    80.       value: [114.411159, 30.481917, 1000]
    81.     },
    82.     {
    83.       name: "地点5",
    84.       value: [114.412488, 30.481917, 1000]
    85.     },
    86.     {
    87.       name: "地点6",
    88.       value: [114.413638, 30.482726, 1000]
    89.     },
    90.     {
    91.       name: "地点7",
    92.       value: [114.412344, 30.48341, 1000]
    93.     },
    94.     {
    95.       name: "地点8",
    96.       value: [114.413494, 30.483939, parseInt(Math.random(0.6, 1) * 1000)]
    97.     },
    98.     {
    99.       name: "地点9",
    100.       value: [114.411877, 30.484469, parseInt(Math.random(0.6, 1) * 1000)]
    101.     },
    102.     {
    103.       name: "地点10",
    104.       value: [114.412308, 30.484531, parseInt(Math.random(0.6, 1) * 1000)]
    105.     },
    106.     {
    107.       name: "地点11",
    108.       value: [114.407853, 30.4845, parseInt(Math.random(0.6, 1) * 1000)]
    109.     },
    110.     {
    111.       name: "地点12",
    112.       value: [114.407242, 30.48285, parseInt(Math.random(0.1, 0.5) * 1000)]
    113.     },
    114.     {
    115.       name: "地点13",
    116.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    117.     },
    118.     {
    119.       name: "地点14",
    120.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    121.     },
    122.     {
    123.       name: "地点15",
    124.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    125.     },
    126.     {
    127.       name: "地点16",
    128.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    129.     },
    130.     {
    131.       name: "地点17",
    132.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    133.     },
    134.     {
    135.       name: "地点18",
    136.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    137.     },
    138.     {
    139.       name: "地点19",
    140.       value: [114.412021, 30.481201, parseInt(Math.random(0.1, 0.5) * 1000)]
    141.     },
    142.     {
    143.       name: "地点20",
    144.       value: [114.447306, 30.560407, parseInt(Math.random(0.1, 0.9) * 1000)]
    145.     },
    146.     {
    147.       name: "地点21",
    148.       value: [114.296104, 30.600017, parseInt(Math.random(0.1, 0.9) * 1000)]
    149.     },
    150.     {
    151.       name: "地点22",
    152.       value: [114.29402, 30.597406, parseInt(Math.random(0.1, 0.9) * 1000)]
    153.     },
    154.     {
    155.       name: "地点23",
    156.       value: [114.300487, 30.595106, parseInt(Math.random(0.1, 0.9) * 1000)]
    157.     },
    158.     {
    159.       name: "地点24",
    160.       value: [114.295026, 30.592805, parseInt(Math.random(0.1, 0.9) * 1000)]
    161.     },
    162.     {
    163.       name: "地点25",
    164.       value: [114.291648, 30.597282, 1000]
    165.     },
    166.     {
    167.       name: "地点26",
    168.       value: [114.287408, 30.599147, 1000]
    169.     },
    170.     {
    171.       name: "地点27",
    172.       value: [114.282378, 30.598649, 1000]
    173.     },
    174.     {
    175.       name: "地点28",
    176.       value: [114.286689, 30.600514, 1000]
    177.     }
    178.   ];
    179.   return new Promise((resolve, reject) => {
    180.     resolve({
    181.       code: 200,
    182.       data: data
    183.     });
    184.   });
    185. }

    remoteLoad.js

    1. const remoteLoad = url => {
    2.     return new Promise((resolve, reject) => {
    3.       const existingScript = document.getElementById(url);
    4.       //如果script不存在
    5.       if (!existingScript) {
    6.         const script = document.createElement("script");
    7.         script.id = url;
    8.         script.src = url;
    9.         script.async = true;
    10.         document.body.appendChild(script);
    11.         script.onload = function() {
    12.           setTimeout(() => {
    13.             this.onerror = this.onload = null;
    14.             resolve();
    15.           }, 500);
    16.         };
    17.         script.onerror = function() {
    18.           this.onerror = this.onload = null;
    19.           reject("加载失败" + url);
    20.         };
    21.       } else {
    22.         setTimeout(() => {
    23.           resolve();
    24.         }, 500);
    25.       }
    26.     });
    27.   };
    28.   
    29.   export default remoteLoad;

    cdn.js

    1. const AMapCDN =
    2.   "https://webapi.amap.com/maps?v=1.3&key=73cddabc2173e0166a622f4483d3592a&plugin=AMap.DistrictSearch";
    3. const AMapUiCDN = "https://webapi.amap.com/ui/1.0/main.js";
    4. const VueCDN = "https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js";
    5. const AxiosCDN = "https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js";
    6. const VueRouterCDN =
    7.   "https://cdn.bootcdn.net/ajax/libs/vue-router/3.2.0/vue-router.min.js";
    8. const VuexCDN = "https://cdn.bootcdn.net/ajax/libs/vuex/3.5.1/vuex.min.js";
    9. const TinymceCDN =
    10.   "https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js";
    11. const html2canvasCDN =
    12.   "https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.7/dist/html2canvas.min.js";
    13. module.exports = {
    14.   AMapCDN,
    15.   AMapUiCDN,
    16.   VueCDN,
    17.   AxiosCDN,
    18.   VueRouterCDN,
    19.   VuexCDN,
    20.   TinymceCDN,
    21.   html2canvasCDN
    22. };

    视频号如何做视频任务进行变现

    2023-09-05

    380aa791f41ecbf439667a54d080e02a.jpeg

    视频号如何插入带货商品链接进行变现

    2023-09-04

    18d58b43f50326bf75f5ddf723f04b24.jpeg

    36岁男子自称被裁,曾是前500强公司市场总监,最后接受做外买

    2023-09-03

    2944e1dee434498ac35ac381d15e1185.jpeg

    聊一下互联网红利并牢牢抓住

    2023-09-02

    b0b405f1be0254fb3c3ed981e3f1f698.jpeg

    关于大学考研与不考研自己一点看法

    2023-09-01

    1d31375fc500862aefaaa7729b46ed15.jpeg

    css中文本阴影特效

    2023-08-30

    f937bf70bf5017f39012ba075716e048.jpeg

    8d5b7ba2bc51eef1736bdce50d22f2f7.png

    (能绘画,能问答)

    f43e85a14eb42c562714935bde373b41.jpeg

    (拓展人脉,圈子)

  • 相关阅读:
    openarena
    如何基于先进视频技术,构建互联网视频监控安全管理平台解决方案
    net基于asp.net的二手商品的交易系统-二手网站-计算机毕业设计
    SpringBoot SpringBoot 开发实用篇 4 数据层解决方案 4.14 ES 索引操作
    <蓝桥杯软件赛>零基础备赛20周--第5周--杂题-2
    美团面试拷打:Redis 缓存穿透、缓存击穿、缓存雪崩区别和解决方案
    前端工作日常
    Linux学习——文件IO
    数字化新零售营销模式如何落地?数字化新零售营销功能推荐
    ​7.1 项目1 学生通讯录管理:文本文件增删改查(C++版本)(自顶向下设计+断点调试) (A)​
  • 原文地址:https://blog.csdn.net/wzc_coder/article/details/132749704