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 别搞错了 要不然你就库库找报错吧!

相关推荐

  1. Vue2.6+Echarts+Bmap构建地图

    2024-02-07 06:54:04       33 阅读
  2. vue项目快速构建

    2024-02-07 06:54:04       10 阅读
  3. vue接入高德地图

    2024-02-07 06:54:04       43 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-07 06:54:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-07 06:54:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-07 06:54:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-07 06:54:04       20 阅读

热门阅读

  1. 练习宏的题目

    2024-02-07 06:54:04       33 阅读
  2. 大语言模型训练数据集(1)

    2024-02-07 06:54:04       37 阅读
  3. 【STAT4052】Introduction to Statistical Learning

    2024-02-07 06:54:04       25 阅读
  4. swift结算体系

    2024-02-07 06:54:04       35 阅读
  5. 14.Swift函数

    2024-02-07 06:54:04       28 阅读
  6. ChatGPT学习大纲

    2024-02-07 06:54:04       34 阅读
  7. 数据结构刷题 -- 客房预约

    2024-02-07 06:54:04       29 阅读
  8. 动态数据源

    2024-02-07 06:54:04       27 阅读
  9. CGAL::2D Arrangements-2

    2024-02-07 06:54:04       28 阅读
  10. vscode代码快捷键

    2024-02-07 06:54:04       27 阅读
  11. 【Kotlin】自定义Json反序列化

    2024-02-07 06:54:04       32 阅读