From deee13fc484f3bf994b7068b3ee1672d14dad740 Mon Sep 17 00:00:00 2001 From: yuhe <1641284022@qq.com> Date: Tue, 20 Aug 2024 20:04:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=20=E9=AB=98?= =?UTF-8?q?=E5=BE=B7=E5=9C=B0=E5=9B=BE=E5=9C=A8web=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=B8=8BtranslateMarker=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84bug=20(question/196586)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/view/components/map/MapMarker.tsx | 61 ++++++++++++++----- .../uni-h5/src/view/components/map/index.tsx | 2 +- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/packages/uni-h5/src/view/components/map/MapMarker.tsx b/packages/uni-h5/src/view/components/map/MapMarker.tsx index 8f865fd8fe2..eb5130d10c8 100644 --- a/packages/uni-h5/src/view/components/map/MapMarker.tsx +++ b/packages/uni-h5/src/view/components/map/MapMarker.tsx @@ -193,6 +193,11 @@ export default /*#__PURE__*/ defineSystemComponent({ } } onMapReady((map, maps, trigger) => { + if (getIsAMap()) { + AMap.plugin('AMap.MoveAnimation', function () { + marker = new AMap.Marker() + }) + } function updateMarker(option: Props) { const title = option.title let position: any @@ -478,22 +483,34 @@ export default /*#__PURE__*/ defineSystemComponent({ rotation = marker.getRotation() } const a = marker.getPosition() - const b = new (maps as QQMaps | GoogleMaps).LatLng( - destination.latitude, - destination.longitude - ) - const distance = - ( - maps as QQMaps | GoogleMaps - ).geometry.spherical.computeDistanceBetween(a as any, b as any) / - 1000 + let b: any + let distance = 0 + let MapsEvent: any + if (getIsAMap()) { + b = new (maps as AMap.NameSpace).LngLat( + destination.longitude, + destination.latitude + ) + distance = b.distanceTo(a) / 1000 + MapsEvent = (maps as AMap.NameSpace).Event + } else { + b = new (maps as QQMaps | GoogleMaps).LatLng( + destination.latitude, + destination.longitude + ) + distance = + ( + maps as QQMaps | GoogleMaps + ).geometry.spherical.computeDistanceBetween( + a as any, + b as any + ) / 1000 + MapsEvent = (maps as QQMaps | GoogleMaps).event + } const time = (typeof duration === 'number' ? duration : 1000) / (1000 * 60 * 60) const speed = distance / time - const MapsEvent = - (maps as QQMaps | GoogleMaps).event || - (maps as AMap.NameSpace).Event const movingEvent = MapsEvent.addListener( marker, 'moving', @@ -510,8 +527,10 @@ export default /*#__PURE__*/ defineSystemComponent({ } ) const event = MapsEvent.addListener(marker, 'moveend', () => { - event.remove() - movingEvent.remove() + if (!getIsAMap()) { + event.remove() + movingEvent.remove() + } marker.lastPosition = a as QLatLng marker.setPosition(b as any) const label = marker.label @@ -528,7 +547,7 @@ export default /*#__PURE__*/ defineSystemComponent({ } }) let lastRtate = 0 - if (autoRotate) { + if (autoRotate && !getIsAMap()) { if (marker.lastPosition) { lastRtate = ( maps as QQMaps | GoogleMaps @@ -547,7 +566,17 @@ export default /*#__PURE__*/ defineSystemComponent({ marker.setRotation(rotation + rotate) } if ('moveTo' in marker) { - marker.moveTo(b as QLatLng, speed) + if (getIsAMap()) { + marker.moveTo( + b as QLatLng, + { + duration: duration, + autoRotation: autoRotate, + } as any + ) + } else { + marker.moveTo(b as QLatLng, speed) + } } else { marker.setPosition(b as GLatLng) MapsEvent.trigger(marker, 'moveend', {}) diff --git a/packages/uni-h5/src/view/components/map/index.tsx b/packages/uni-h5/src/view/components/map/index.tsx index 06a4d771def..7c9b631f5cb 100644 --- a/packages/uni-h5/src/view/components/map/index.tsx +++ b/packages/uni-h5/src/view/components/map/index.tsx @@ -493,10 +493,10 @@ function useMap( if (context) { try { context.translate(data) + callOptions(data, `${type}:ok`) } catch (error: any) { callOptions(data, `${type}:fail ${error.message}`) } - callOptions(data, `${type}:ok`) } else { callOptions(data, `${type}:fail not found`) }