Vue Components for Baidu MapVGL (Vue 2)
raw JSON →vue-mapvgl is a Vue 2 component library designed to integrate Baidu's MapVGL 3D geographic information visualization library with Vue applications via vue-bmap-gl. It provides a set of pre-built components (e.g., `el-bmapv-point-layer`, `el-bmapv-heat-map-layer`) that simplify the process of adding advanced 3D data visualizations like heatmaps, flow lines, and complex geometric layers onto Baidu Maps GL instances. The package is currently at version 0.0.34, which is specific to Vue 2 environments. The project's 0.x line has been officially announced as unmaintained due to Baidu's documentation certification requirements, making it an abandoned package for Vue 2 development. A separate `@next` version exists for Vue 3, but this registry entry pertains to the 0.x series. It relies heavily on `vue-bmap-gl` for the underlying Baidu Maps GL instance.
Common errors
error [Vue warn]: Unknown custom element: <el-bmap> ↓
Vue.use(VueBMap); and Vue.use(VueMapvgl); are called before creating the Vue instance, typically in main.js. error Baidu Map API is not loaded or ak is invalid. ↓
VueBMap.initBMapApiLoader({ ak: 'YOUR_KEY' }) is called with a valid, active Baidu Maps API Key and that the key has appropriate permissions. error TypeError: Cannot read properties of undefined (reading 'View') ↓
vue-bmap-gl and vue-mapvgl are installed and registered correctly. Ensure the Baidu Maps API (including WebGL version) is loaded and the mapvgl script is accessible. Warnings
breaking The `vue-mapvgl` project for Vue 2 (0.x versions) has been officially declared as unmaintained due to Baidu's requirements for open-source documentation certification. This means there will be no further updates, bug fixes, or security patches for this version. ↓
gotcha A Baidu Maps API Key (AK) is strictly required for `vue-bmap-gl` (and thus `vue-mapvgl`) to function. Without a valid AK, the map will not load or function correctly, often leading to blank maps or errors in the console. ↓
gotcha Coordinate order in `mapvgl` layers is typically `[longitude, latitude]` (`[lng, lat]`). However, some Baidu Map API methods or external data sources might provide coordinates in `[latitude, longitude]` (`[lat, lng]`) order, leading to incorrect rendering. ↓
Install
npm install vue-mapvgl yarn add vue-mapvgl pnpm add vue-mapvgl Imports
- VueMapvgl wrong
const VueMapvgl = require('vue-mapvgl')correctimport VueMapvgl from 'vue-mapvgl' - VueBMap wrong
import { VueBMap } from 'vue-bmap-gl'correctimport VueBMap from 'vue-bmap-gl' - el-bmapv-point-layer
<el-bmapv-point-layer :data="pointData"></el-bmapv-point-layer>
Quickstart
import Vue from 'vue';
import App from './App.vue';
import VueBMap from 'vue-bmap-gl';
import VueMapvgl from 'vue-mapvgl';
import 'vue-bmap-gl/dist/style.css';
Vue.use(VueBMap);
Vue.use(VueMapvgl);
VueBMap.initBMapApiLoader({
// Replace 'YOUR_BAIDU_MAP_AK' with your actual Baidu Maps API Key
// Get a key from: http://lbsyun.baidu.com/apiconsole/key#/home
ak: process.env.VUE_APP_BAIDU_MAP_AK ?? 'YOUR_BAIDU_MAP_AK_MISSING',
v: '1.0' // Baidu SDK version, default is 1.0
});
new Vue({
render: h => h(App),
}).$mount('#app');
// In App.vue
<template>
<div id="app">
<el-bmap vid="bmap-demo" :zoom="13" :center="center" class="map-container">
<el-bmapv-view>
<el-bmapv-point-layer :data="points" :options="layerOptions"></el-bmapv-point-layer>
</el-bmapv-view>
</el-bmap>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
center: [116.404, 39.915], // Beijing coordinates
points: [
{ geometry: { type: 'Point', coordinates: [116.404, 39.915] } },
{ geometry: { type: 'Point', coordinates: [116.45, 39.92] } },
{ geometry: { type: 'Point', coordinates: [116.38, 39.90] } }
],
layerOptions: {
size: 20,
color: 'rgba(50, 50, 255, 0.8)',
shape: 'circle'
}
};
},
mounted() {
console.log('Map initialized with vue-mapvgl layers.');
}
};
</script>
<style>
.map-container {
width: 100vw;
height: 100vh;
}
</style>