Skip to content

Commit

Permalink
feat: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
yue1123 committed Oct 28, 2022
1 parent 4650900 commit 3c7feca
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/components/map/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@
const mapContainer = ref<HTMLDivElement | null>()
let map: BMapGL.Map = null!
// 是否初始化
let initd = false
let initd = ref<boolean>(false)
// 地图初始化的发布
const { ready } = useLifeCycle()
const { uid, proxy } = getCurrentInstance()!
// const mapContainerId = 'baidu-map-container' + uid
const props = withDefaults(defineProps<BaiduMapProps>(), {
width: '100%',
height: '550px',
Expand Down Expand Up @@ -327,8 +326,8 @@
initCustomStyle()
startWatchProps()
bindEvents(props, vueEmits, map)
if (!initd) {
initd = true
if (!initd.value) {
initd.value = true
nextTick(() => ready(map))
if (plugins) {
initPlugins(plugins, pluginsSourceLink)
Expand Down Expand Up @@ -458,7 +457,7 @@
}
// 设置地图类型
function setMapType(mapType: _MapType): void {
map!.setMapType(window[mapType])
window[mapType] !== undefined && map!.setMapType(window[mapType])
}
function setHeading(heading: number): void {
map!.setHeading(heading)
Expand Down Expand Up @@ -503,9 +502,7 @@
enableAutoResize ? map!.enableAutoResize() : map!.disableAutoResize()
}
onMounted(() => {
init()
})
onMounted(init)
/**
* 销毁地图,当使用 WebGL 渲染地图时,如果确认不再使用该地图实例,则需要
* 调用本方法销毁 WebGL 上下文,否则频繁创建新地图实例会导致浏览器报:
Expand Down

0 comments on commit 3c7feca

Please sign in to comment.