Skip to content
Open
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
61 changes: 45 additions & 16 deletions packages/uni-h5/src/view/components/map/MapMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -528,7 +547,7 @@ export default /*#__PURE__*/ defineSystemComponent({
}
})
let lastRtate = 0
if (autoRotate) {
if (autoRotate && !getIsAMap()) {
if (marker.lastPosition) {
lastRtate = (
maps as QQMaps | GoogleMaps
Expand All @@ -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', {})
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-h5/src/view/components/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
Expand Down