function normalizeCoordinate(value) {
|
const number = Number(value)
|
return Number.isFinite(number) ? number : 0
|
}
|
|
export function hasMeetingPointLocation(point = {}) {
|
return Boolean(normalizeCoordinate(point.latitude || point.meetingPointLatitude) && normalizeCoordinate(point.longitude || point.meetingPointLongitude))
|
}
|
|
export function buildMeetingPointPayload(point = {}) {
|
const latitude = normalizeCoordinate(point.latitude || point.meetingPointLatitude)
|
const longitude = normalizeCoordinate(point.longitude || point.meetingPointLongitude)
|
|
return {
|
scenicId: point.scenicId || '',
|
scenicName: point.scenicName || '',
|
meetingPointId: point.id || point.meetingPointId || '',
|
meetingPointName: point.name || point.meetingPointName || '汇合点',
|
meetingPointAddress: point.address || point.meetingPointAddress || '',
|
latitude,
|
longitude
|
}
|
}
|
|
export function buildMeetingPointCircles(point = {}) {
|
const payload = buildMeetingPointPayload(point)
|
if (!hasMeetingPointLocation(payload)) {
|
return []
|
}
|
|
return [
|
{
|
latitude: payload.latitude,
|
longitude: payload.longitude,
|
radius: 36,
|
strokeWidth: 4,
|
color: '#4d8fe899',
|
fillColor: '#4d8fe833'
|
}
|
]
|
}
|
|
export function openMeetingPointPage(point = {}) {
|
const payload = buildMeetingPointPayload(point)
|
if (!hasMeetingPointLocation(payload)) {
|
uni.showToast({
|
title: '汇合点坐标暂未配置',
|
icon: 'none'
|
})
|
return
|
}
|
openSystemLocation(payload).catch((error) => {
|
console.log('Open meeting point location failed', error)
|
uni.showToast({
|
title: '暂时无法打开地图导航',
|
icon: 'none'
|
})
|
})
|
}
|
|
export function parseMeetingPointPayload(payload = '') {
|
if (!payload) {
|
return null
|
}
|
|
try {
|
const parsed = JSON.parse(decodeURIComponent(payload))
|
return buildMeetingPointPayload(parsed)
|
} catch (error) {
|
console.log('Parse meeting point payload failed', error)
|
return null
|
}
|
}
|
|
export function openSystemLocation(point = {}) {
|
const payload = buildMeetingPointPayload(point)
|
if (!hasMeetingPointLocation(payload)) {
|
uni.showToast({
|
title: '汇合点坐标暂未配置',
|
icon: 'none'
|
})
|
return Promise.reject(new Error('Missing meeting point coordinates'))
|
}
|
|
return new Promise((resolve, reject) => {
|
uni.openLocation({
|
latitude: payload.latitude,
|
longitude: payload.longitude,
|
scale: 18,
|
name: payload.meetingPointName,
|
address: payload.meetingPointAddress,
|
success() {
|
resolve(payload)
|
},
|
fail(error) {
|
reject(error)
|
}
|
})
|
})
|
}
|