Skip to content

BMapViewer 组件 ​

BMapViewer组件是基于vue3封装的Cesium加载组件,可以通过简单的参数传递即可实现地图加载。

示例 ​

完整示例可参考方式 1:Vue 组件加载。

vue
<template>
  <BMapViewer 
      :sceneMode="0" 
      :camera="mapConfig" 
      @ready="ready" 
      @click="onClick" 
      ref="cesiumRef">
  </BMapViewer>
</template>

API ​

Attributes-属性 ​

属性名说明类型默认可选值
id可选容器 idstringundefined
sceneMode地图模式,平面2D和3D地球number00:2D模式
1:3D模式
camera有值时挂载后自动初始化;没有值时等待调用 initMapobject | nullnull参考 mapConfig
baseColor地球颜色string#112441

Events-事件 ​

事件名说明类型callback参数
ready当前组件实例首次加载完成时触发,每次挂载只触发一次Functionviewer (Cesium.Viewer)
error地图加载失败时触发Functionerr (Error)
click鼠标左键点击事件Function{ lon, lat, feature }

Exposes-暴露 ​

名称说明类型参数类型
initMap传入相机参数并幂等初始化;重复调用返回当前 ViewerFunctionmapConfig (Object,首次调用必传)
reinitializeMap传入相机参数,显式销毁并重建 Viewer,不会重复触发 readyFunctionmapConfig (Object)
startClick开启点击事件(默认开启)Function-
stopClick关闭点击事件Function-
flyTo相机飞行到指定位置Functiondestination, duration?
getViewer获取当前 Cesium ViewerFunction-
setCameraHeightRange动态修改并立即应用相机高度范围Function{ minHeight?, maxHeight? }
getCameraHeightRange获取当前相机高度范围Function-
restrictMaxiHeight立即按当前范围约束相机高度Function-

手动初始化 ​

不传 camera 时,组件不会在挂载阶段自动创建 Viewer。此时通过组件 ref 调用 initMap:

vue
<script setup>
import { onMounted, ref } from 'vue'

const cesiumRef = ref(null)

onMounted(() => {
  cesiumRef.value.initMap({
    longitude: 125.8337,
    latitude: 44.1471,
    height: 12000,
    pitch: -45,
  })
})
</script>

<template>
  <BMapViewer ref="cesiumRef" :scene-mode="1" @ready="ready" />
</template>

Slots-插槽 ​

插槽名说明
tool用于在地图上层放置自定义工具栏、控件等 DOM 元素,配合相对/绝对定位使用

基于 Apache-2.0 许可发布