Skip to content

Commit

Permalink
Merge pull request #472 from StarJacky/release-3.6.8-app
Browse files Browse the repository at this point in the history
fix: 修复异常id处理
  • Loading branch information
tangcq-code authored Dec 7, 2023
2 parents 0e4fafb + 1e985b4 commit e5e971f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
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

0 comments on commit e5e971f

Please sign in to comment.