vue+高德API搭建前段经济页面

news/2025/2/5 1:08:22/

 一、模板部分(<template>

html

<template><div class="content"><div><dv-border-box-8 :reverse="true"><div class="head"><div class="head_content"><h1>12344822</h1><h2>2024年收入情况(单位:元)</h2></div><div class="head_content"><h1>45620218</h1><h2>2024年总支出情况(单位:元)</h2></div></div></dv-border-box-8></div><div> <div id="container"></div></div></div>
</template>
  • 该部分使用 Vue 的模板语法,主要负责页面的布局和显示内容。
    • 整体使用一个 div 元素,类名为 content,它包含了整个页面的内容。
    • 内部有一个 dv-border-box-8 组件,使用了 :reverse="true" 属性,可能是一个自定义的边框组件,其内部有一个 div 元素类名为 head
    • head 元素内部包含两个 div 元素,类名为 head_content,分别显示了 2024 年的收入和支出信息,包含 h1 和 h2 元素,用于展示相应的数字和描述信息。
    • 还有一个 div 元素,其 id 为 container,可能是为了后续在 JavaScript 中进行操作,例如将地图渲染在这个元素内。

二、脚本部分(<script>

javascript

import AMapLoader from '@amap/amap-jsapi-loader';
export default {name: "HeatmapComponent",data() {return {map: null,heatmap: null}},methods: {initMap() {AMapLoader.load({key: "1e31659e58fa7666fe0d08f4487ec5c2",version: "2.0",plugins: ['AMap.HeatMap']}).then((AMap) => {this.map = new AMap.Map("container", {resizeEnable: true,center: [114.91934, 32.010736],zoom: 9,mapStyle: 'amap://styles/fresh'});this.map.plugin(["AMap.HeatMap"], () => {// 初始化 heatmap 对象this.heatmap = new AMap.HeatMap(this.map, {radius: 100,opacity: [0, 32]});// 设置数据集this.heatmap.setDataSet({data: [{ "lng": 114.05867, "lat": 32.116885, "count": 200 },{ "lng": 114.125595, "lat": 32.101005, "count": 220 },{ "lng": 114.512838, "lat": 32.20436, "count": 120 },{ "lng": 114.91934, "lat": 32.010736, "count": 100 },{ "lng": 114.740392, "lat": 32.34312, "count": 100 },{ "lng": 114.91934, "lat": 32.010736, "count": 90 },{ "lng": 114.879309, "lat": 31.643914, "count": 100 },{ "lng": 115.051683, "lat": 32.131426, "count": 120 },{ "lng": 1": 120 },{ "lng": 115.420101, "lat": 32.474772, "count": 180 },{ "lng": 115.406894, "lat": 31.79832, "count": 190 },{ "lng": 115.654066, "lat": 32.169239, "count": 200 },],max: 220});});}).catch(e => {console.log(e);});},showHeatmap() {this.heatmap.show();},hideHeatmap() {this.heatmap.hide();}},mounted() {this.initMap();}
}
  • 导入和组件声明
    • import AMapLoader from '@amap/amap-jsapi-loader';:导入高德地图的 JavaScript API 加载器。
    • export default {...}:定义一个 Vue 组件,名称为 HeatmapComponent
  • 数据部分(data
    • map: null:存储地图对象,初始化为 null
    • heatmap: null:存储热力图对象,初始化为 null
  • 方法部分(methods
    • initMap()
      • 使用 AMapLoader.load() 方法加载高德地图 API,传入 keyversion 和 plugins 等配置信息。
      • 在加载成功后,使用 AMap.Map 创建一个地图对象,将其绑定到 id 为 container 的元素上,并设置一些地图的属性,如 resizeEnablecenterzoom 和 mapStyle
      • 然后使用 this.map.plugin() 加载 AMap.HeatMap 插件,在回调函数中,使用 new AMap.HeatMap() 初始化热力图对象,设置 radius 和 opacity 属性。
      • 使用 this.heatmap.setDataSet() 方法设置热力图的数据集,包含多个位置的经纬度和 count 信息,同时设置 max 值。
    • showHeatmap():调用热力图对象的 show() 方法显示热力图。
    • hideHeatmap():调用热力图对象的 hide() 方法隐藏热力图。
  • 生命周期钩子(mounted
    • 调用 initMap() 方法,在组件挂载后初始化地图和热力图。

三、样式部分(<style>

css

<style>#container {width: 100%;height: 1080px;margin: 10px auto;border: 1px solid red;}
</style><style scoped>
.content {width: 80%;
}
.head {padding: 10px;height: 80px;display: flex;justify-content: space-around;
}
.head_content {display: flex;flex-direction: column;justify-content: space-between;align-items: center;
}
.body {margin-top: 10px;
}
.body_table1 {display: flex;
}
.map-content {width: 700px;height: 750px;overflow: hidden;
}
.map {width: 80%;height: 80%;
}
</style>

  • 全局样式
    • #container:设置 id 为 container 的元素的样式,包括宽度、高度、边距和边框。
  • 局部样式(scoped
    • .content:设置类名为 content 的元素的宽度。
    • .head:设置类名为 head 的元素的内边距、高度和使用 flex 布局,实现子元素的水平分布。
    • .head_content:使用 flex 布局,实现子元素的垂直分布和居中对齐。
    • 其他样式:定义了 .body.body_table1.map-content 和 .map 的样式,如 widthheight 和 overflow 等,用于布局和元素的显示。

完整代码:

<template><div class="content"><div><dv-border-box-8 :reverse="true"><div class="head"><div class="head_content"><h1>12344822</h1><h2>2024年收入情况(单位:元)</h2></div><div class="head_content"><h1>45620218</h1><h2>2024年总支出情况(单位:元)</h2></div></div></dv-border-box-8></div><div> <div id="container"></div></div></div>
</template><script>
import AMapLoader from '@amap/amap-jsapi-loader';
export default {name: "HeatmapComponent",data() {return {map: null,heatmap: null}},methods: {initMap() {AMapLoader.load({key: "1e31659e58fa7666fe0d08f4487ec5c2",version: "2.0",plugins: ['AMap.HeatMap']}).then((AMap) => {this.map = new AMap.Map("container", {resizeEnable: true,center: [114.91934, 32.010736],zoom: 9,mapStyle: 'amap://styles/fresh'});this.map.plugin(["AMap.HeatMap"], () => {// 初始化heatmap对象this.heatmap = new AMap.HeatMap(this.map, {radius: 100,opacity: [0, 32]});// 设置数据集this.heatmap.setDataSet({data: [{ "lng": 114.05867, "lat": 32.116885, "count": 200 },{ "lng": 114.125595, "lat": 32.101005, "count": 220 },{ "lng": 114.512838, "lat": 32.20436, "count": 120 },{ "lng": 114.91934, "lat": 32.010736, "count": 100 },{ "lng": 114.740392, "lat": 32.34312, "count": 100 },{ "lng": 114.91934, "lat": 32.010736, "count": 90 },{ "lng": 114.879309, "lat": 31.643914, "count": 100 },{ "lng": 115.051683, "lat": 32.131426, "count": 120 },{ "lng": 115.420101, "lat": 32.474772, "count": 180 },{ "lng": 115.406894, "lat": 31.79832, "count": 190 },{ "lng": 115.654066, "lat": 32.169239, "count": 200 },],max: 220});});}).catch(e => {console.log(e);});},showHeatmap() {this.heatmap.show();},hideHeatmap() {this.heatmap.hide();}},mounted() {this.initMap();}
}
</script><style>#container {width: 100%;height: 1080px;margin: 10px auto;border: 1px solid red;}
</style><style scoped>
.content {width: 80%;
}
.head {padding: 10px;height: 80px;display: flex;justify-content: space-around;
}
.head_content {display: flex;flex-direction: column;justify-content: space-between;align-items: center;
}
.body {margin-top: 10px;
}
.body_table1 {display: flex;
}
.map-content {width: 700px;height: 750px;overflow: hidden;
}
.map {width: 80%;height: 80%;
}
</style>

效果截图:

 

 


http://www.ppmy.cn/news/1564627.html

相关文章

python编程-OpenCV(图像读写-图像处理-图像滤波-角点检测-边缘检测)边缘检测

OpenCV中边缘检测四种常用算子&#xff1a; &#xff08;1&#xff09;Sobel算子 Sobel算子是一种基于梯度的边缘检测算法。它通过对图像进行卷积操作来计算图像的梯度&#xff0c;并将梯度的大小作为边缘的强度。它使用两个3x3的卷积核&#xff0c;分别用于计…

redis做为缓存,mysql的数据如何与redis进行同步呢?

Redis作为缓存与MySQL之间的数据同步问题&#xff0c;特别是涉及到双写一致性&#xff08;即缓存与数据库的写操作要保持一致&#xff09;时&#xff0c;通常有两种常见的解决方案。它们分别适用于不同的一致性要求和延迟容忍度。以下是两种常见的解决方案的详细解释&#xff1…

与 Spring Boot 的无缝集成:ShardingSphere 快速集成实践

ShardingSphere 是一个轻量级的开源分布式数据库中间件&#xff0c;它支持分库分表、分布式事务、读写分离等功能。它能够与各种应用框架进行集成&#xff0c;其中与 Spring Boot 的集成非常流行&#xff0c;因为它能够帮助开发者在 Spring Boot 项目中快速实现高性能的分布式数…

【Azure 架构师学习笔记】- Azure Function (2) --实操1

本文属于【Azure 架构师学习笔记】系列。 本文属于【Azure Function 】系列。 接上文【Azure 架构师学习笔记】- Azure Function (1) --环境搭建和背景介绍 前言 上一文介绍了环境搭建&#xff0c;接下来就在本地环境下使用一下。 环境准备 这里我下载了最新的VS studio&…

鸿蒙动态路由实现方案

背景 随着CSDN 鸿蒙APP 业务功能的增加&#xff0c;以及为了与iOS、Android 端统一页面跳转路由&#xff0c;以及动态下发路由链接&#xff0c;路由重定向等功能。鸿蒙动态路由方案的实现迫在眉睫。 实现方案 鸿蒙版本动态路由的实现原理&#xff0c;类似于 iOS与Android的实…

C++中.h文件中的实现方法

在 C 中&#xff0c;.h 文件和 Java 中的接口有一些相似之处&#xff0c;但它们的作用和用法还是有很大区别。具体来说&#xff0c;.h 文件通常用于声明&#xff0c;但也可以包含一些实现&#xff0c;特别是在某些特殊情况下。 1. C .h 文件的基本用途 C 的头文件&#xff08…

Postman环境变量全局变量设置

在公司中&#xff0c;一般会存在开发环境、测试环境、线上环境等&#xff0c;如果需要在不 同的环境下切换做接口测试&#xff0c;显然我们需要把所有接口的域名进行修改&#xff0c;如果接 口测试用例较多&#xff0c;那么修改会非常费力&#xff0c;postman可直接通过切换环境…

mac 安装mongodb

本文分享2种mac本地安装mongodb的方法&#xff0c;一种是通过homebrew安装&#xff0c;一种是通过tar包安装 homebrew安装 brew tap mongodb/brew brew upate brew install mongodb-community8.0tar包安装 安装mongodb 1.下载mongodb社区版的tar包 mongdb tar包下载地址 2…