首页 前端知识 1 echarts与map相遇

1 echarts与map相遇

2024-03-24 22:03:50 前端知识 前端哥 596 261 我要收藏

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 = title
                const 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 = title
                const 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/wjCYAO2tEVXN6Pj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O6uQeZHWhSsvjJTqaQdKOABQIwGkfMtXOjRx7CtPKr5vWq8/ixFzj2OoszJnHwTRTyN9zSECw9CUCsk6Blzhk4c7uzVHjSSiECELuysUnES98GUdrP0cSvS1V3OWkG/VAux0FRSpXNqw6Bn0lEYL3ONxzgOCTUxjGHiYQNSjwMU9G8XDarZUdoQM8d3IQDR3+PBHmKWjD7yc7519D8cY1jHET54s7Igiugu8ruFbVcC67d/geb2lvOAIxXsKQe8BrtdcelBvf95HwCQtLoi6e/uLo+Mf/Bc8hqG+0I7n9F7/md5bOy7SZUsJcUPlIjW92LsFnBw3MgYWzZ917WoKuzyd7k34EK/cXovrrj7Xf+qs6Yz4Eww/4f/NG/tGVq/nnCBEllTYvfeoj7n8M8tX1pHU5IcGIlz/yKfCi0nf2Cnl2A+49Hw70QTMzzvXNtv3wsai19ZDprGMnO0pQhuJUs0Q7UshhCYmxRhCgfplZb7Qbsvzfzf3Jc43sTsHZu1Dxjgb7B8tC3+V9NRGatW71b33g8WFtuqNAXQ5ZIwxymGCitUWJsLgJVKxBhW0DmjLgsn/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 = this
      const 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 = title
                const 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 = title
                const 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
})
}
}
}


转载请注明出处或者链接地址:https://www.qianduange.cn//article/4094.html
标签
评论
会员中心 联系我 留言建议 回顶部
复制成功!