当前位置: 首页 > article >正文

Vue2.6+Echarts+Bmap构建地图

Vue2.6+Echarts+Bmap构建地图

在你的页面中引入 你的echarts库中的bmap库

// 引入依赖库 在echarts中使用bmap进行创建地图
import "echarts/extension/bmap/bmap"

然后直接开始写你的地图组件 搭建页面

<template>
    <div class="wrapper">
        <div class="echarts" id="charts"></div>
    </div>
</template>

<script>
// 引入依赖库 在echarts中使用bmap进行创建地图
import "echarts/extension/bmap/bmap"
export default {
    name: '',
    components: {},
    data: () => {
        return {
            opstion: {}
        }
    },
    mounted() {
        this.isShowcharts()
    },
    methods: {
        isShowcharts() {
            const charts = this.$echarts.init(document.getElementById("charts"));
            const opstion = {
                bmap: {
                    key: 'G1LFyjrNGIkns5OfpZnrCGAKxpycPLwb',
                    center: [104.114129, 37.550339],
                    zoom: 5,
                    roam: false,
                    //地图样式库
                    mapStyle: {
                        styleJson: [{
                            'featureType': 'water',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#d1d1d1'
                            }
                        }, {
                            'featureType': 'land',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#f3f3f3'
                            }
                        }, {
                            'featureType': 'railway',
                            'elementType': 'all',
                            'stylers': {
                                'visibility': 'off'
                            }
                        }, {
                            'featureType': 'highway',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#fdfdfd'
                            }
                        }, {
                            'featureType': 'highway',
                            'elementType': 'labels',
                            'stylers': {
                                'visibility': 'off'
                            }
                        }, {
                            'featureType': 'arterial',
                            'elementType': 'geometry',
                            'stylers': {
                                'color': '#fefefe'
                            }
                        }, {
                            'featureType': 'arterial',
                            'elementType': 'geometry.fill',
                            'stylers': {
                                'color': '#fefefe'
                            }
                        }, {
                            'featureType': 'poi',
                            'elementType': 'all',
                            'stylers': {
                                'visibility': 'off'
                            }
                        }, {
                            'featureType': 'green',
                            'elementType': 'all',
                            'stylers': {
                                'visibility': 'off'
                            }
                        }, {
                            'featureType': 'subway',
                            'elementType': 'all',
                            'stylers': {
                                'visibility': 'off'
                            }
                        }, {
                            'featureType': 'manmade',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#d1d1d1'
                            }
                        }, {
                            'featureType': 'local',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#d1d1d1'
                            }
                        }, {
                            'featureType': 'arterial',
                            'elementType': 'labels',
                            'stylers': {
                                'visibility': 'off'
                            }
                        }, {
                            'featureType': 'boundary',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#fefefe'
                            }
                        }, {
                            'featureType': 'building',
                            'elementType': 'all',
                            'stylers': {
                                'color': '#d1d1d1'
                            }
                        }, {
                            'featureType': 'label',
                            'elementType': 'labels.text.fill',
                            'stylers': {
                                'color': '#999999'
                            }
                        }]
                    }
                }
            }
            charts.setOption(opstion)
        },
    }
};
</script>

<style scoped>
.wrapper {
    width: 100vw;
    height: 100vh;
    background-color: antiquewhite;
}

.echarts {
    width: 100%;
    height: 100%;
}
</style>

建议不要使用v-charts 有bug我就是先用的v-charts 然后改成echarts的

另外如果你用了bmap去构建你的地图也就是用百度地图去写地图你需要在你的index.html文件中引入 百度api2.0

  <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ"></script>

要不然你的echarts地图无法构建 remember is 2.0 别搞错了 要不然你就库库找报错吧!


http://www.kler.cn/a/231052.html

相关文章:

  • Mongodb启动为Windows服务开机自启动
  • 数据结构之归并排序
  • 【自动化测试】---Selenium+Java
  • RabbitMQ-4.MQ的可靠性
  • 微信小程序(三十六)事件传参
  • hummingbird,一个非常好用的 Python 库!
  • 从领域外到领域内:LLM在Text-to-SQL任务中的演进之路
  • 计算机毕业设计 | SpringBoot大型旅游网站 旅行后台管理系统(附源码)
  • 【C++航海王:追寻罗杰的编程之路】类与对象你学会了吗?(下)
  • 零基础学Python之面向对象
  • 计算机科学导论(2)计算机如何存储音频
  • CopyOnWriteArrayList底层原理全面解析【建议收藏】
  • 为什么是0.1uF电容?
  • 洛谷:P1219 [USACO1.5] 八皇后 Checker Challenge(dfs深度优先遍历求解)
  • 登录+JS逆向进阶【过咪咕登录】(附带源码)
  • 2023年全国职业院校技能大赛软件测试赛题第3套
  • 【数据结构】链表OJ面试题3(题库+解析)
  • SpringBoot3整合Mybatis-Plus,自定义动态数据源starter
  • MOS管防反接电路设计
  • 部署 Zabbix 监控平台