1 echarts与map相遇

news/2024/11/26 5:49:39/

echarts与map

版本

    "echarts": "^5.1.2","echarts-gl": "^2.0.9",

效果

在这里插入图片描述

基本方法

echarts中地图大多是以地理坐标为主,数据格式使用geojson数据格式。geojson是GIS数据格式中第二常用格式,使用GIS软件都能实现数据转换。

步骤

1数据准备

从上图中可以看出,地图包括深蓝色底图、青色厚度、 地图定位坐标点、插图部分。插图的图框也是很绘制的包含插图的外包矩形,也是地理数据。

  • 深蓝地图和青色厚度是相同的地图,只是渲染方式不一样。面类型数据
  • 地图定位坐标点采用的经纬度,点类型数据
  • 插图图框是边界矩形,插图内容是面状群岛分布
    数据来源大部分来自阿里datav,一小部分数据自己制作。
https://datav.aliyun.com/portal/school/atlas/area_selector

2开发准备

地图部分单独写组件,新建vue组件,编写模板,样式等

  <div id="map" class="chartBox" />

组件引用等

3注册地图

import hainan from '@/api/gis/provinces_hn.json' //底图
import sansha from '@/api/gis/ss.json'  //插图
import boundry from '@/api/gis/chatuboundry.json' //插图框echarts.registerMap('hn', hainan)echarts.registerMap('ss', sansha)echarts.registerMap('boundry', boundry)

4 配置项

底图

底图是放了两个hn图层,上面hn图层设置了透明度,渲染填充和边界,并增加鼠标移入事件,可进行放大、缩小、移动。作为厚度的图层其缩放、移动跟随第一个图层变化。两个底图定位中心一样,长宽比一样。

          {map: 'hn', //注册底图zlevel: 5, //层次顺序roam: true,  //缩放平移aspectScale: 1.1, //长宽比center: [109.786246, 18.464193], //定位中心zoom: 0.8, //初始缩放级别scaleLimit: { //最大最小缩放级别min: 0.2,max: 50},label: {   //底图文字标注show: true,color: '#ffffff',shadowColor: '#134ae6',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2},itemStyle: {  //不同市的渲染color: '#153294', // 背景opacity: 0.9,borderWidth: '1', // 边框宽度borderColor: 'rgba(255,255,255,0.3)' // 边框颜色},emphasis: { //鼠标移入后label: {  //底图文字标注show: true,color: '#ffffff',shadowColor: '#134ae6',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2},itemStyle: { //不同市的渲染areaColor: '#0CBFFF',opacity: 0.9}}},{map: 'hn',top: '12%',silent: true,aspectScale: 1.1,zlevel: 4,center: [109.786246, 18.464193],zoom: 0.8,itemStyle: {color: '#01EAF8', // 背景opacity: 1,borderWidth: '1', // 边框宽度borderColor: '#3C5FA1' // 边框颜色}},

三沙群岛

 {map: 'ss',zlevel: 6,roam: false,aspectScale: 0.7,center: [14.87585417960884, 4.8374873458189995],zoom: 0.148,label: {show: true,color: '#ffffff',shadowColor: '#2074FF',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2},itemStyle: {color: '#ffffff', // 背景opacity: 1,borderWidth: 1, // 边框宽度borderColor: 'rgba(255,255,255,0.3)' // 边框颜色// borderopacity: 0.6},emphasis: {itemStyle: {color: '#153294',opacity: 0.9},label: {show: true,color: '#ffffff',shadowColor: '#2074FF',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2}}},

插图图框

 {map: 'boundry',zlevel: 6,roam: false,aspectScale: 0.7,center: [14.87585417960884, 4.8374873458189995],zoom: 0.148,label: {show: false},itemStyle: {color: '#153294', // 背景opacity: 0.2,borderWidth: 2, // 边框宽度borderColor: '#01EAF8' // 边框颜色},tooltip: {// show: false}}

定位点

定位点是自己采集的经纬度数据,格式如下

{"location" :[{"name": "某某某地方","X": "110.386274","Y": "20.026688"}]
}

定位点主要采用series方式添加到底图上

          {name: 'jcy',type: 'scatter',map: 'hn',zlevel: 10,coordinateSystem: 'geo',geoIndex: 0,symbolSize: [30, 60],symbol: `image://${that.images}`,data: that.cityInfo.location.map(d => {return {name: d.name,value: [parseFloat(d.X),parseFloat(d.Y)]}}),tooltip: {backgroundColor: 'rgba(0,0,0,0.5)',borderColor: 'rgba(0,0,0,0)',extraCssText: 'box-shadow: 0 0 0 rgba(255, 255, 255, 0.7);',zIndex: 400,formatter: function(params) {let html = ''var title = `<div style="color:#ffffff;margin-bottom: 12px; font-size: 14px">${params.name}</div>`html = titleconst item = that.jcyInfo.find(t => t.name === params.name)if (item) {const info = `<div style=" line-height: 30px;color:#7BE6FF;font-size:10px;"><span style="display:inline-block;margin-right:4px;width:8px;height:8px;border-radius:50%;"></span><span style="margin-right:30px;color:#7BE6FF">进行中的个案总数:</span><span style="float:right;color:#7BE6FF">${item.num}</span></div>`html += info}return html}}},

三沙群岛也有定位点,在插图上同样也可以添加

  {name: 'scjcy',type: 'scatter',map: 'ss',zlevel: 500,coordinateSystem: 'geo',geoIndex: 3,symbolSize: [30, 60],symbol: `image://${that.images}`,data: [{name: '三沙市三沙群岛某某',value: [114.375028, 10.547062]},{'name': '三沙市某某某',value: [112.345028, 16.837062]}],tooltip: {backgroundColor: 'rgba(0,0,0,0.5)',borderColor: 'rgba(0,0,0,0)',extraCssText: 'box-shadow: 0 0 0 rgba(255, 255, 255, 0.7);',zIndex: 500,formatter: function(params) {console.log(params)let html = ''var title = `<div style="color:#ffffff;margin-bottom: 12px; font-size: 14px">${params.name}</div>`html = titleconst item = that.jcyInfo.find(t => t.name === params.name)if (item) {const info = `<div style=" line-height: 30px;color:#7BE6FF;font-size:10px;"><span style="display:inline-block;margin-right:4px;width:8px;height:8px;border-radius:50%;"></span><span style="margin-right:30px;color:#7BE6FF">进行中的个案总数:</span><span style="float:right;color:#7BE6FF">${item.num}</span></div>`html += info}return html}}}

注意这里定位图标用本地图片没成功,看api说需要使用一个在线地址,或者base64 但是要加上image://${that.images}

5 底图移动事件

      this.myChart.on('georoam', function(params) {var option = that.myChart.getOption()// 获得option对象if (params.zoom != null && params.zoom !== undefined) { // 捕捉到缩放时option.geo[1].zoom = option.geo[0].zoom // 下层geo的缩放等级跟着上层的geo一起改变option.geo[1].center = option.geo[0].center// 下层的geo的中心位置随着上层geo一起改变} else { // 捕捉到拖曳时option.geo[1].center = option.geo[0].center// 下层的geo的中心位置随着上层geo一起改变// option.geo[2].center = option.geo[0].center// option.geo[3].center = option.geo[0].center}that.myChart.setOption(option)// 设置option})

6 初始化

      this.myChart = echarts.init(document.getElementById('map')) // 这里是为了获得容器所在位置this.myChart.setOption(option)

完整代码

<template><div class="grid-echarts__wrapper"><div id="map" class="chartBox" /></div>
</template>
<script>
import * as echarts from 'echarts'
import 'echarts-gl'
import hainan from '@/api/gis/provinces_hn.json'
import sansha from '@/api/gis/ss.json'
import boundry from '@/api/gis/chatuboundry.json'
import { getHelpMapData } from '@/api/bigScreenNew/help.js'export default {name: 'GL',data() {return {option: null,images: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACkAAABQCAYAAACETVz/AAAAAXNSR0IArs4c6QAAFZNJREFUaEPNmnts3ed535/3/rucC8/hISnKlCzRijSTthNHXVK7UMImXtDYcUynof8o2mHbH8GK9o+hAbq1Wyqy6I0bOgwosBVFu2FD/wjCYAO2tEVXN6PjtLGdMo1jH9lSJJoyKd6OqHP/Xd7r8DuHpChLMqTUin3AAxKH5/z44fd5vs/zvs/vRfDePJC7xXVQ/7Vb/equ/urude7qM9mbb4Z6F8q9q/+o0HcM6QD6781g5mZv+NxCtYpgBrKv/ccCAMycm3wH+izAWXC7V8q+3ZHKdwR5S8BdsMVzNZRfb6PTGd7p01B9vo4mn1h2sATZF7QP593UxJCDjHoyg7570HeF7ME5gLk5QGdhFjLFzk3W0OfWTyKvXkei00FrIzES3RQdAYCtkkSHAWAdAEZC7lbXANJQuLG879LNyy4p+e4bh/NuojrkZiYn3RzMwtldZd9N1dtC7gHuh3aiiuD5ZVytj6PJDC7XwNe8LiaJRiN5gxrpOMJSoVaoUaFLneVtNyAa7vzVCuRPtm35cmjHDg3Y6uZlN1nyHTwxbmEvHc7O9lLgdqC3hOwD9iREmXpDkzU0VB3CtbCGT5RS1FwTpMN9HLg2YbHEMVW44BkUa7t/PZ9i16LE+YZZFcbWp4FJTdsWRdEkesCeS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g8WFtuqNAXQ5ZIwxymGCitUWJsLgJVKxBhW0DmjLgsn/wbC977lTFu4a8rmb2U1/RDPZ6OnwNL8IQmlqoOfTcc+b663uH5+8e8EeD3D17fv2w/W74ezd7Jvr3fLLT+jMz2fHq3UBkcP0/dzcK7kXxjor5LTpB7wTMLUEPvrl3K+4fBvgjKflO4H6eHgS+uev+KOrdde++XU898Pqusje+8x8Kt3e1/w+Ju5sVJc1VnQAAAABJRU5ErkJggg==',cityInfo: require('@/api/gis/jcy.json'),jcyInfo: []}},mounted() {this.getData()},beforeDestroy() {},methods: {getData() {getHelpMapData().then(res => {if (res.code === 200) {this.jcyInfo = res.data}this.initCharts()})},initCharts() {const that = thisconst option = {animation: false,tooltip: {},series: [{name: 'jcy',type: 'scatter',map: 'hn',zlevel: 10,coordinateSystem: 'geo',geoIndex: 0,symbolSize: [30, 60],symbol: `image://${that.images}`,data: that.cityInfo.location.map(d => {return {name: d.name,value: [parseFloat(d.X),parseFloat(d.Y)]}}),tooltip: {backgroundColor: 'rgba(0,0,0,0.5)',borderColor: 'rgba(0,0,0,0)',extraCssText: 'box-shadow: 0 0 0 rgba(255, 255, 255, 0.7);',zIndex: 400,formatter: function(params) {let html = ''var title = `<div style="color:#ffffff;margin-bottom: 12px; font-size: 14px">${params.name}</div>`html = titleconst item = that.jcyInfo.find(t => t.name === params.name)if (item) {const info = `<div style=" line-height: 30px;color:#7BE6FF;font-size:10px;"><span style="display:inline-block;margin-right:4px;width:8px;height:8px;border-radius:50%;"></span><span style="margin-right:30px;color:#7BE6FF">进行中的个案总数:</span><span style="float:right;color:#7BE6FF">${item.num}</span></div>`html += info}return html}}},{name: 'scjcy',type: 'scatter',map: 'ss',zlevel: 500,coordinateSystem: 'geo',geoIndex: 3,symbolSize: [30, 60],symbol: `image://${that.images}`,data: [{name: '三沙市三沙群岛人民检察院',value: [114.375028, 10.547062]},{'name': '三沙市人民检察院',value: [112.345028, 16.837062]}],tooltip: {backgroundColor: 'rgba(0,0,0,0.5)',borderColor: 'rgba(0,0,0,0)',extraCssText: 'box-shadow: 0 0 0 rgba(255, 255, 255, 0.7);',zIndex: 500,formatter: function(params) {console.log(params)let html = ''var title = `<div style="color:#ffffff;margin-bottom: 12px; font-size: 14px">${params.name}</div>`html = titleconst item = that.jcyInfo.find(t => t.name === params.name)if (item) {const info = `<div style=" line-height: 30px;color:#7BE6FF;font-size:10px;"><span style="display:inline-block;margin-right:4px;width:8px;height:8px;border-radius:50%;"></span><span style="margin-right:30px;color:#7BE6FF">进行中的个案总数:</span><span style="float:right;color:#7BE6FF">${item.num}</span></div>`html += info}return html}}}],geo: [{map: 'hn',zlevel: 5,roam: true,aspectScale: 1.1,center: [109.786246, 18.464193],zoom: 0.8,scaleLimit: {min: 0.2,max: 50},label: {show: true,color: '#ffffff',shadowColor: '#134ae6',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2},itemStyle: {color: '#153294', // 背景opacity: 0.9,borderWidth: '1', // 边框宽度borderColor: 'rgba(255,255,255,0.3)' // 边框颜色},emphasis: {label: {show: true,color: '#ffffff',shadowColor: '#134ae6',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2},itemStyle: {areaColor: '#0CBFFF',opacity: 0.9}}},{map: 'hn',top: '12%',silent: true,aspectScale: 1.1,zlevel: 4,center: [109.786246, 18.464193],zoom: 0.8,itemStyle: {color: '#01EAF8', // 背景opacity: 1,borderWidth: '1', // 边框宽度borderColor: '#3C5FA1' // 边框颜色}},{map: 'ss',zlevel: 6,roam: false,aspectScale: 0.7,center: [14.87585417960884, 4.8374873458189995],zoom: 0.148,label: {show: true,color: '#ffffff',shadowColor: '#2074FF',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2},itemStyle: {color: '#ffffff', // 背景opacity: 1,borderWidth: 1, // 边框宽度borderColor: 'rgba(255,255,255,0.3)' // 边框颜色// borderopacity: 0.6},emphasis: {itemStyle: {color: '#153294',opacity: 0.9},label: {show: true,color: '#ffffff',shadowColor: '#2074FF',shadowOffsetX: 15,shadowOffsetY: 15,textBorderColor: '#134ae6',textBorderType: 'solid',textBorderWidth: 2}}},{map: 'boundry',zlevel: 6,roam: false,aspectScale: 0.7,center: [14.87585417960884, 4.8374873458189995],zoom: 0.148,label: {show: false},itemStyle: {color: '#153294', // 背景opacity: 0.2,borderWidth: 2, // 边框宽度borderColor: '#01EAF8' // 边框颜色},tooltip: {// show: false}}]}this.myChart = echarts.init(document.getElementById('map')) // 这里是为了获得容器所在位置echarts.registerMap('hn', hainan)echarts.registerMap('ss', sansha)echarts.registerMap('boundry', boundry)this.myChart.setOption(option)this.myChart.on('georoam', function(params) {var option = that.myChart.getOption()// 获得option对象if (params.zoom != null && params.zoom !== undefined) { // 捕捉到缩放时option.geo[1].zoom = option.geo[0].zoom // 下层geo的缩放等级跟着上层的geo一起改变option.geo[1].center = option.geo[0].center// 下层的geo的中心位置随着上层geo一起改变} else { // 捕捉到拖曳时option.geo[1].center = option.geo[0].center// 下层的geo的中心位置随着上层geo一起改变// option.geo[2].center = option.geo[0].center// option.geo[3].center = option.geo[0].center}that.myChart.setOption(option)// 设置option})}}
}
</script>
<style lang="scss" scoped>
@import "@bigScreen/styles/mixins";.wrapper {height: 100%;overflow: hidden;
}.chartBox {width: 100%;height: 100%;
}
</style>

.geo[1].zoom = option.geo[0].zoom // 下层geo的缩放等级跟着上层的geo一起改变
option.geo[1].center = option.geo[0].center// 下层的geo的中心位置随着上层geo一起改变
} else { // 捕捉到拖曳时
option.geo[1].center = option.geo[0].center// 下层的geo的中心位置随着上层geo一起改变
// option.geo[2].center = option.geo[0].center
// option.geo[3].center = option.geo[0].center
}
that.myChart.setOption(option)// 设置option
})
}
}
}



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

相关文章

【2023 · CANN训练营第一季】应用开发(初级)第四章——模型推理

AscendCL运行资源管理 申请运行管理资源时&#xff0c;需按顺序依次申请: Device、Context、Stream&#xff0c;然后根据实际需求调用aclrtGetRunMode接口获取软件栈的运行模型(当同一个应用既支持在Host运行&#xff0c;也支持在Device运行时&#xff0c;在编程时需要就需要根…

系列1——geotools简介

geotools简介 官网 https://docs.geotools.org/latest/userguide/index.html 架构图 常用功能列表 ModulePurposegt-renderImplements of Java2D rendering engine to draw a mapgt-jdbcImplements for accessing spatial databasegt-mainImplements for accessing spatial…

C++——哈希表

哈希表&#xff08;Hash table&#xff09;&#xff0c;也被称为散列表&#xff0c;是一种常用的数据结构&#xff0c;用于实现键-值对的存储和检索。它通过将键映射到数组中的索引位置来实现快速的数据查找。 在 C 中&#xff0c;可以使用标准库中的 unordered_map 类来实现哈…

LDO基本知识

本文引用TI文档 压降 压降电压 VDO 是指为实现正常稳压&#xff0c;输入电压 VIN 必须高出 所需输出电压 VOUT(nom) 的最小压差。 如果 VIN 低于此值&#xff0c;线性稳压器将以压降状态工作&#xff0c;不再调 节所需的输出电压。在这种情况下&#xff0c;输出电压 VOUT(drop…

传染病学模型 | Matlab实现SEIRS传染病学模型 (SEIRS Epidemic Model)

文章目录 效果一览基本描述模型介绍程序设计参考资料效果一览 基本描述 传染病学模型 | Matlab实现SEIRS传染病学模型 (SEIRS Epidemic Model) 模型介绍 SEIRS是一种基于计算机模拟的传染病学模型,用于研究人群中传染病的传播和控制。与其他传染病学模型不同,SEIRS模型考虑了…

Java集合类型对象的快速初始化

在Java中&#xff0c; 集合类型的对象初始化&#xff0c; 一般是先创建对象&#xff0c; 然后往集合里面增加元素&#xff0c;这种写法直观&#xff0c;但是撰写代码的时候感觉比较冗余&#xff0c; 是否有什么酷炫的方式简化定义初始化呢&#xff1f; 本篇介绍字符串数组、Lis…

python为什么长期霸占榜首

Python霸占榜首 只因它真的很强 Python&#xff0c;年龄可能比很多读者都要大&#xff0c;但是它在更新快速的编程界却一直表现出色&#xff0c;甚至有人把它比作是编程界的《葵花宝典》&#xff0c;只是Python的速成之法相较《葵花宝典》有过之而无不及。 Python简洁&#x…

python列表获取 value值

caseinfo[{name: 获取token,request: {method: get, url: /cgi-bin/token, headers: none,datas:{grant_type: client_credential,appid: wx2ed6b772cc34974d, secret: aca6a76b0a57f9d32a90a716318d6736}}, validate: none}] 举例说明&#xff0c;近期在学习python的时候需要获…