initMap() {
this.bdMap = new this.BMapGL.Map("map-container"); // 创建Map实例
this.bdMap.centerAndZoom(
new this.BMapGL.Point(
this.mapConfig.center.lng,
this.mapConfig.center.lat
),
this.mapConfig.zoom
); // 初始化地图,设置中心点坐标和地图级别
this.bdMap.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
if (this.mapConfig.style?.custom) {
const { custom, styleJson, styleId } = this.mapConfig.style;
let config;
if (custom === "styleJson") {
config = { styleJson }; // styleJson与ak无关联
} else if (custom === "styleId") {
config = { styleId }; // 发布的styleID需要与ak为同一个用户
}
this.$nextTick(() => {
this.bdMap.setMapStyleV2(config);
});
}
const add = () => {
this.$emit("map-loaded", {
map: this.bdMap,
BMapGL: this.BMapGL,
})
if (this.listenOnce) {
this.bdMap.removeEventListener("tilesloaded",add);
}
}
this.bdMap.addEventListener("tilesloaded",add);
},