Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复异常id处理 #472

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/taro-components/src/components/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,16 @@ export class Map implements ComponentInterface {
_removeMarkers = (option) => {
// 获取所有覆盖物
const overlays = this.map.getOverlays()
let newTargetMarker = {}
option.markerIds.forEach((id) => {
// 查找指定 id 的 Marker 对象
const targetMarker = overlays.find(
(overlay: any) => overlay instanceof BMapGL.Marker && String(overlay.id) === id
)
newTargetMarker = targetMarker
this.map.removeOverlay(targetMarker)
})
return newTargetMarker
}

/* 沿指定路径移动 marker,用于轨迹回放等场景。动画完成时触发回调事件,若动画进行中,对同一 marker 再次调用 moveAlong 方法,前一次的动画将被打断 */
Expand Down Expand Up @@ -1095,16 +1098,15 @@ export class Map implements ComponentInterface {
_removeGroundOverlay = (option) => {
// 获取所有图层
const overlays = this.map.getOverlays()

let newTargetOverlay = ''
// 找到要更新的图层
const targetOverlay = overlays.find((overlay) => overlay._id === option.id)

newTargetOverlay = targetOverlay
if (targetOverlay) {
// 如果找到了对应的图层,执行删除操作
this.map.removeOverlay(targetOverlay)
} else {
console.error(`未找到id为${option.id}的自定义图片图层`)
}
return newTargetOverlay
}

/* 限制地图的显示范围。此接口同时会限制地图的最小缩放整数级别。 */
Expand Down
26 changes: 19 additions & 7 deletions packages/taro-mpharmony/src/api/media/map/MapContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,18 @@ export class MapContext implements Taro.MapContext {

removeGroundOverlay (_option: Taro.MapContext.RemoveGroundOverlayOption): Promise<TaroGeneral.CallbackResult> {
try {
this.Map._removeGroundOverlay(_option)
const newTargetOverlay = this.Map._removeGroundOverlay(_option)
const successResult: TaroGeneral.CallbackResult = {
errMsg: 'removeGroundOverlay:ok',
}
_option?.success?.(successResult)
_option?.complete?.({ errMsg: 'removeGroundOverlay:ok' })
if (newTargetOverlay) {
_option?.success?.(successResult)
_option?.complete?.({ errMsg: 'removeGroundOverlay:ok' })
} else {
const errorResult: TaroGeneral.CallbackResult = { errMsg: `removeGroundOverlay:fail,未找到id为${_option.id}的自定义图片图层` }
_option?.fail?.(errorResult)
_option?.complete?.(errorResult)
}

return Promise.resolve(successResult)
} catch (e) {
Expand Down Expand Up @@ -371,13 +377,19 @@ export class MapContext implements Taro.MapContext {

removeMarkers (_option: Taro.MapContext.RemoveMarkersOption): Promise<TaroGeneral.CallbackResult> {
try {
this.Map._removeMarkers(_option)
const TargetMarker = this.Map._removeMarkers(_option)
const successResult: TaroGeneral.CallbackResult = {
errMsg: 'removeMarkers:ok',
}
_option?.success?.(successResult)
_option?.complete?.({ errMsg: 'removeMarkers:ok' })

if (TargetMarker) {
_option?.success?.(successResult)
_option?.complete?.({ errMsg: 'removeMarkers:ok' })
} else {
const errorResult: TaroGeneral.CallbackResult = { errMsg: `removeMarkers:fail,未找到该id的marker` }
_option?.fail?.(errorResult)
_option?.complete?.(errorResult)
}

return Promise.resolve(successResult)
} catch (e) {
const errorResult: TaroGeneral.CallbackResult = { errMsg: `removeMarkers:${e}` }
Expand Down
Loading