前端 vue 实现区域地图-并在地图上标注柱状图

效果图 西藏的区域规划以及柱状图
在这里插入图片描述

一、下载区域地图的js文件

区域地图可以在中国的区域地图 这里下载

二、实现代码

一个普通的html可以参考
实现广东省的区域地图并标注柱状图

三、vue里具体实现代码
1.做一个有具体宽高的dom

<template>
  <div class="box">
        <div id="centerMap"></div>
  </div>
</template>
    #centerMap{
      width: 100%;
      height: 550px;
    }

2.定义方法

  created() {
        this.centerChart()
  }
     centerChart(){
        var myChart = echarts.init(document.getElementById('centerMap'));
        var option = {}
        var geoCoordMap = {
            阿里地区: [82.564653, 33.063726],
            那曲市: [89.24948, 32.783399],
            拉萨市: [91.091762, 30.037072],
            日喀则市: [86.477854, 29.498529],
            山南市: [92.266609, 28.303935],
            林芝市: [95.239298, 29.198982],
            昌都市: [97.035183, 30.783725],
        }
        var customerBatteryCityData = [{
            name: "阿里地区",
            value: 70
        }, {
            name: "那曲市",
            value: 701
        }, {
            name: "拉萨市",
            value: 702
        }, {
            name: "日喀则市",
            value: 703
        }, {
            name: "山南市",
            value: 704
        }, {
            name: "林芝市",
            value: 705
        }, {
            name: "昌都市",
            value: 706
        }]
        // 获取json格式的数据 地图数据
        $.getJSON('/西藏自治区.json', function(geoJson) {
          echarts.registerMap('xizang', geoJson);
           var option = {
              // backgroundColor: '#131C38',
              tooltip: {
                    trigger: 'item',
                    show: true,
                    enterable: true,
                    textStyle: {
                        fontSize: 20,
                        color: '#fff'
                    },
                    backgroundColor: 'rgba(0,2,89,0.8)',
                    formatter: '{b}<br />{c}'
                },
                geo: [{
                    map: 'xizang',
                    aspectScale: 0.9,
                    roam: false, // 是否允许缩放
                    zoom: 1.2, // 默认显示级别
                    layoutSize: '95%',
                    layoutCenter: ['55%', '50%'],
                    itemStyle: {
                        normal: {
                            areaColor: {
                                type: 'linear-gradient',
                                x: 0,
                                y: 400,
                                x2: 0,
                                y2: 0,
                                colorStops: [{
                                    offset: 0,
                                    color: 'rgba(37,108,190,0.3)' // 0% 处的颜色
                                }, {
                                    offset: 1,
                                    color: 'rgba(15,169,195,0.3)' // 50% 处的颜色
                                }],
                                global: true // 缺省为 false
                            },
                            borderColor: '#4ecee6',
                            borderWidth: 1
                        },
                        emphasis: {
                            areaColor: {
                                type: 'linear-gradient',
                                x: 0,
                                y: 300,
                                x2: 0,
                                y2: 0,
                                colorStops: [{
                                    offset: 0,
                                    color: 'rgba(37,108,190,1)' // 0% 处的颜色
                                }, {
                                    offset: 1,
                                    color: 'rgba(15,169,195,1)' // 50% 处的颜色
                                }],
                                global: true // 缺省为 false
                            }
                        }
                    },
                    emphasis: {
                        itemStyle: {
                            areaColor: '#0160AD'
                        },
                        label: {
                            show: 0,
                            color: '#fff'
                        }
                    },
                    zlevel: 3
                }, {
                    map: 'xizang',
                    aspectScale: 0.9,
                    roam: false, // 是否允许缩放
                    zoom: 1.2, // 默认显示级别
                    layoutSize: '95%',
                    layoutCenter: ['55%', '50%'],
                    itemStyle: {
                        normal: {
                            borderColor: 'rgba(192,245,249,.6)',
                            borderWidth: 2,
                            shadowColor: '#2C99F6',
                            shadowOffsetY: 0,
                            shadowBlur: 120,
                            areaColor: 'rgba(29,85,139,.2)'
                        }
                    },
                    zlevel: 2,
                    silent: true
                }, {
                    map: 'xizang',
                    aspectScale: 0.9,
                    roam: false, // 是否允许缩放
                    zoom: 1.2, // 默认显示级别
                    layoutSize: '95%',
                    layoutCenter: ['55%', '51.5%'],
                    itemStyle: {
                        // areaColor: '#005DDC',
                        areaColor: 'rgba(0,27,95,0.4)',
                        borderColor: '#004db5',
                        borderWidth: 1
                    },
                    zlevel: 1,
                    silent: true
                }],
                series: [
                    // map
                    {
                        geoIndex: 0,
                        // coordinateSystem: 'geo',
                        showLegendSymbol: true,
                        type: 'map',
                        roam: true,
                        label: {
                            normal: {
                                show: false,
                                textStyle: {
                                    color: '#fff'
                                }
                            },
                            emphasis: {
                                show: false,
                                textStyle: {
                                    color: '#fff'
                                }
                            }
                        },
                        itemStyle: {
                            normal: {
                                borderColor: '#2ab8ff',
                                borderWidth: 1.5,
                                areaColor: '#12235c'
                            },
                            emphasis: {
                                areaColor: '#2AB8FF',
                                borderWidth: 0,
                                color: 'red'
                            }
                        },
                        map: 'xizang', // 使用
                        data: customerBatteryCityData
                            // data: this.difficultData //热力图数据   不同区域 不同的底色
                    },
                    // 柱状体的主干
                    {
                        type: 'lines',
                        zlevel: 5,
                        effect: {
                            show: false,
                            // period: 4, //箭头指向速度,值越小速度越快
                            // trailLength: 0.02, //特效尾迹长度[0,1]值越大,尾迹越长重
                            // symbol: 'arrow', //箭头图标
                            // symbol: imgDatUrl,
                            symbolSize: 5 // 图标大小
                        },
                        lineStyle: {
                            width: 20, // 尾迹线条宽度
                            color: 'rgb(22,255,255, .6)',
                            opacity: 1, // 尾迹线条透明度
                            curveness: 0 // 尾迹线条曲直度
                        },
                        label: {
                            show: 0,
                            position: 'end',
                            formatter: '245'
                        },
                        silent: true,
                        data: lineData()
                    },
                    // 柱状体的顶部
                    {
                        type: 'scatter',
                        coordinateSystem: 'geo',
                        geoIndex: 0,
                        zlevel: 5,
                        label: {
                            show: true,
                            formatter: function() {
                                return ``
                            },
                            position: "top"
                        },
                        symbol: 'circle',
                        symbolSize: [20, 10],
                        itemStyle: {
                            color: 'rgb(22,255,255, 1)',
                            opacity: 1
                        },
                        silent: true,
                        data: scatterData()
                    },
                    // 柱状体的底部
                    {
                        type: 'scatter',
                        coordinateSystem: 'geo',
                        geoIndex: 0,
                        zlevel: 4,
                        label: {
                            // 这儿是处理的
                            formatter: '{b}',
                            position: 'bottom',
                            color: '#fff',
                            fontSize: 12,
                            distance: 10,
                            show: true
                        },
                        symbol: 'circle',
                        symbolSize: [20, 10],
                        itemStyle: {
                            // color: '#F7AF21',
                            color: 'rgb(22,255,255, 1)',
                            opacity: 1
                        },
                        silent: true,
                        data: scatterData2()
                    },
                    // 底部外框
                    {
                        type: 'scatter',
                        coordinateSystem: 'geo',
                        geoIndex: 0,
                        zlevel: 4,
                        label: {
                            show: false
                        },
                        symbol: 'circle',
                        symbolSize: [40, 20],
                        itemStyle: {
                            color: {
                                type: 'radial',
                                x: 0.5,
                                y: 0.5,
                                r: 0.5,
                                colorStops: [{
                                    offset: 0,
                                    color: 'rgb(22,255,255, 0)' // 0% 处的颜色
                                }, {
                                    offset: 0.75,
                                    color: 'rgb(22,255,255, 0)' // 100% 处的颜色
                                }, {
                                    offset: 0.751,
                                    color: 'rgb(22,255,255, 1)' // 100% 处的颜色
                                }, {
                                    offset: 1,
                                    color: 'rgb(22,255,255, 1)' // 100% 处的颜色
                                }],
                                global: false // 缺省为 false
                            },

                            opacity: 1
                        },
                        silent: true,
                        data: scatterData2()
                    }
                ]
            }
            myChart.setOption(option);
        })
        // 动态计算柱形图的高度(定一个max)
        function lineMaxHeight() {
            const maxValue = Math.max(...customerBatteryCityData.map(item => item.value))
            return 0.9 / maxValue
        }
        // 柱状体的主干
        function lineData() {
            return customerBatteryCityData.map((item) => {
                return {
                    coords: [geoCoordMap[item.name],
                        [geoCoordMap[item.name][0], geoCoordMap[item.name][1] + item.value * lineMaxHeight()]
                    ]
                }
            })
        }
        // 柱状体的顶部
        function scatterData() {
            return customerBatteryCityData.map((item) => {
                return [geoCoordMap[item.name][0], geoCoordMap[item.name][1] + item.value * lineMaxHeight()]
            })
        }
        // 柱状体的底部
        function scatterData2() {
            return customerBatteryCityData.map((item) => {
                return {
                    name: item.name,
                    value: geoCoordMap[item.name]
                }
            })
        }
        if (option) {
            myChart.setOption(option);
        }
    }
``
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在GisViewer-Vue实现目标在地图上移动,您可以使用Leaflet地图库提供的`setView()`方法来改变地图视图的中心点和缩级别。同时,您需要将目标位置作为地图视图的新中心点,并在适当的时间间隔内更新地图视图以模拟目标的移动效果。 以下是一个示例代码,演示如何在GisViewer-Vue实现目标在地图上移动: ```vue <template> <div id="map-container"></div> </template> <script> import L from 'leaflet'; export default { mounted() { const map = L.map('map-container').setView([39.91, 116.38], 13); const targetMarker = L.marker([39.91, 116.38]).addTo(map); const targetLatLngs = [ [39.91, 116.38], [39.92, 116.39], [39.93, 116.40], [39.94, 116.41], [39.95, 116.42] ]; let index = 0; setInterval(() => { if (index >= targetLatLngs.length) { index = 0; } const targetLatLng = targetLatLngs[index++]; targetMarker.setLatLng(targetLatLng); map.setView(targetLatLng, 13); }, 1000); } }; </script> ``` 在上面的代码中,我们首先创建一个Leaflet地图对象,并将其设置为一个Vue组件的DOM元素。然后,我们创建一个目标标记,并将其添加到地图上。 接下来,我们定义一个目标位置数组,并在每个时间间隔内将地图视图移动到下一个目标位置。具体地,我们使用`setLatLng()`方法更新目标标记的位置,并使用`setView()`方法更新地图视图的中心点和缩级别。 请注意,上面的代码中的目标位置数组只是一个简单的示例,您可以根据自己的需求定义不同的目标位置数组来模拟不同的移动路径。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值