Skip to content

Commit

Permalink
feat(runtime-web): createMapContext 新增根据高德地图是否初始化成功返回不同值
Browse files Browse the repository at this point in the history
  • Loading branch information
hwaphon committed Feb 23, 2024
1 parent f1f8441 commit 221540b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/runtime-web/src/components/src/api/ui/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@ const MAP_INFO = {
needStyleV7: false
}

const MAP_CONTAINER_SELECTOR = '.tiga-map-container' // 需要和 ./map.ts 中地图的外层组件 class 保持一致

export default {
createMapContext(id) {
return new CreateMapContext(id)
const context = new CreateMapContext(id)
const { map } = context

if (!map) return null
if (typeof map.querySelector === 'function') {
const container = map.querySelector(MAP_CONTAINER_SELECTOR)
// 如果父容器底层没有节点,说明高德地图渲染失败了,这个时候需要返回 null,让业务方做兜底处理
if (container && container.children && container.children.length <= 0)
return null
}

return context
},
getMapInfo() {
return Promise.resolve(MAP_INFO)
}
}

class CreateMapContext {
private map: any
map: any

constructor(mapId) {
if (
Expand Down

0 comments on commit 221540b

Please sign in to comment.