package com.xw.yunwei.ui.work.checkInMission
|
|
import android.graphics.Color
|
import android.os.Bundle
|
import android.util.Log
|
import android.view.View
|
import androidx.core.os.bundleOf
|
import androidx.core.view.isVisible
|
import com.amap.api.maps.AMap
|
import com.amap.api.maps.AMapUtils
|
import com.amap.api.maps.CameraUpdateFactory
|
import com.amap.api.maps.model.BitmapDescriptorFactory
|
import com.amap.api.maps.model.CameraPosition
|
import com.amap.api.maps.model.CircleOptions
|
import com.amap.api.maps.model.LatLng
|
import com.amap.api.maps.model.MarkerOptions
|
import com.amap.api.maps.model.Polyline
|
import com.amap.api.maps.model.PolylineOptions
|
import com.amap.api.navi.AMapNavi
|
import com.amap.api.navi.AMapNaviIndependentRouteListener
|
import com.amap.api.navi.AMapNaviListener
|
import com.amap.api.navi.TTSPlayListener
|
import com.amap.api.navi.enums.NaviType
|
import com.amap.api.navi.enums.TransportType
|
import com.amap.api.navi.enums.TravelStrategy
|
import com.amap.api.navi.model.AMapCalcRouteResult
|
import com.amap.api.navi.model.AMapLaneInfo
|
import com.amap.api.navi.model.AMapModelCross
|
import com.amap.api.navi.model.AMapNaviCameraInfo
|
import com.amap.api.navi.model.AMapNaviCross
|
import com.amap.api.navi.model.AMapNaviLocation
|
import com.amap.api.navi.model.AMapNaviPath
|
import com.amap.api.navi.model.AMapNaviPathGroup
|
import com.amap.api.navi.model.AMapNaviRouteNotifyData
|
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo
|
import com.amap.api.navi.model.AMapServiceAreaInfo
|
import com.amap.api.navi.model.AMapTravelInfo
|
import com.amap.api.navi.model.AimLessModeCongestionInfo
|
import com.amap.api.navi.model.AimLessModeStat
|
import com.amap.api.navi.model.NaviInfo
|
import com.amap.api.navi.model.NaviLatLng
|
import com.amap.api.navi.model.NaviPoi
|
import com.amap.api.navi.model.RouteOverlayOptions
|
import com.amap.api.navi.view.RouteOverLay
|
import com.blankj.utilcode.util.GsonUtils
|
import com.blankj.utilcode.util.SpanUtils
|
import com.google.gson.reflect.TypeToken
|
import com.xw.common.CommonDialog
|
import com.xw.common.utils.BindUtils.getResColor
|
import com.xw.common.utils.ToastUtilCommon
|
import com.xw.yunwei.BR
|
import com.xw.yunwei.BaseBusinessActivity
|
import com.xw.yunwei.R
|
import com.xw.yunwei.constants.Key
|
import com.xw.yunwei.databinding.ActivityCruiseCheckInBinding
|
import com.xw.yunwei.extension.colorIdToColorValue
|
import com.xw.yunwei.model.CheckInMissionPointInfo
|
import com.xw.yunwei.model.CruiseCheckInOperationResult
|
import com.xw.yunwei.ui.work.amap.custom.view.CarOverlay
|
import com.xw.yunwei.ui.work.amap.util.NaviUtil
|
import com.xw.yunwei.ui.work.checkInMission.util.Utils
|
import com.xw.yunwei.ui.work.checkInMission.viewmodel.CruiseCheckInViewModel
|
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.ThreadMode
|
import java.text.SimpleDateFormat
|
import java.util.Date
|
|
//巡游打卡导航页
|
class CruiseCheckInActivity :
|
BaseBusinessActivity<ActivityCruiseCheckInBinding, CruiseCheckInViewModel>(),
|
AMapNaviListener, TTSPlayListener, AMapNaviIndependentRouteListener {
|
companion object {
|
//获取跳转此页面参数
|
fun getParams(
|
id: String,
|
points: List<CheckInMissionPointInfo>,
|
startPoint: NaviPoi,
|
type: Int,
|
): Bundle {
|
return bundleOf(
|
Key.ID to id,
|
Key.POINTS to GsonUtils.toJson(points),
|
Key.START_POINT to startPoint,
|
Key.TYPE to type
|
)
|
}
|
}
|
|
//导航对象
|
var aMapNavi: AMapNavi? = null
|
|
//设备位置类
|
var carOverlay: CarOverlay? = null
|
|
//路线OverLay
|
var routeOverLay: RouteOverLay? = null
|
|
//起点/终点回拉线
|
private val leaderLines = mutableListOf<Polyline>()
|
|
//上次计算路线起点定位
|
var lastCalculateRouteStartLocation: AMapNaviLocation? = null
|
override fun getBindingVariable() = BR.viewModel
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
if (!EventBus.getDefault().isRegistered(this)) {
|
EventBus.getDefault().register(this)
|
}
|
|
binding.amapView.onCreate(savedInstanceState)
|
|
initAMapView()
|
|
aMapNavi = AMapNavi.getInstance(this)?.also {
|
it.isNaviTravelView = true
|
it.addAMapNaviListener(this)
|
it.addTTSPlayListener(this)
|
it.setUseInnerVoice(true, true)
|
it.setEmulatorNaviSpeed(75)
|
}
|
|
viewModel.id = intent.getStringExtra(Key.ID) ?: ""
|
viewModel.points.postValue(
|
GsonUtils.fromJson(
|
intent.getStringExtra(Key.POINTS),
|
object : TypeToken<List<CheckInMissionPointInfo>>() {}.type
|
)
|
)
|
viewModel.startPoint = intent.getParcelableExtra(Key.START_POINT)
|
viewModel.type = intent.getIntExtra(Key.TYPE, 0)
|
|
viewModel.checkOutTimeOut()
|
}
|
|
//初始化高德导航控件
|
private fun initAMapView() {
|
binding.amapView.map?.also { it ->
|
it.mapType = AMap.MAP_TYPE_NAVI
|
|
it.uiSettings?.setZoomInByScreenCenter(false)
|
it.uiSettings?.isZoomControlsEnabled = false
|
it.setOnMapLoadedListener {
|
it.setPointToCenter(
|
binding.amapView.width / 2,
|
binding.amapView.height / 2
|
)
|
it.moveCamera(CameraUpdateFactory.zoomTo(16f))
|
carOverlay = CarOverlay(this, binding.amapView).apply {
|
setLock(false)
|
}
|
viewModel.needCalculateRoute.postValue(true)
|
}
|
it.setOnMarkerClickListener { marker ->
|
if (binding.slFloatNotice.isVisible) {
|
return@setOnMarkerClickListener false
|
}
|
val poi = marker.`object` as NaviPoi?
|
viewModel.points.value?.find {
|
it.lat?.toDoubleOrNull() == poi?.coordinate?.latitude &&
|
it.lon?.toDoubleOrNull() == poi?.coordinate?.longitude
|
}?.also {
|
viewModel.choicePoint.postValue(it)
|
}
|
return@setOnMarkerClickListener true
|
}
|
}
|
}
|
|
override fun setObservable() {
|
super.setObservable()
|
viewModel.needCalculateRoute.observe(this) { it ->
|
if (!it || viewModel.getEndPoint() == null) {
|
return@observe
|
}
|
aMapNavi?.also { it ->
|
if (viewModel.type == 0) {
|
it.travelInfo = AMapTravelInfo(TransportType.Walk)
|
val success = it.calculateWalkRoute(
|
viewModel.startPoint,
|
viewModel.getPassingPoints(),
|
viewModel.getEndPoint()!!,
|
TravelStrategy.SINGLE
|
)
|
if (!success) {
|
Log.d(TAG, "步行路线计算失败,检查参数情况")
|
}
|
}
|
if (viewModel.type == 1) {
|
it.travelInfo = AMapTravelInfo(TransportType.Ride)
|
val success = it.calculateRideRoute(
|
viewModel.startPoint,
|
viewModel.getPassingPoints(),
|
viewModel.getEndPoint()!!,
|
TravelStrategy.SINGLE
|
)
|
if (!success) {
|
Log.d(TAG, "骑行路线计算失败,检查参数情况")
|
}
|
}
|
}
|
}
|
viewModel.points.observe(this) {
|
refreshNextPointInfo()
|
}
|
viewModel.isOverview.observe(this) { it ->
|
binding.ivOverview.setImageResource(if (it) R.mipmap.ic_route_arrow_close else R.mipmap.ic_route_arrow)
|
binding.tvOverview.text = if (it) "退出全览" else "全览"
|
if (it) {
|
routeOverLay?.zoomToSpan()
|
} else {
|
binding.amapView.map?.also {
|
viewModel.aMapNaviLocation?.also { location ->
|
it.animateCamera(
|
CameraUpdateFactory.newCameraPosition(
|
CameraPosition.fromLatLngZoom(
|
LatLng(
|
location.coord.latitude,
|
location.coord.longitude
|
), 16f
|
)
|
)
|
)
|
}
|
}
|
}
|
}
|
viewModel.hadExpand.observe(this) {
|
binding.ivFlexing.setImageResource(if (it) R.mipmap.ic_down else R.mipmap.ic_up)
|
binding.llLocationInfo.visibility = if (it) View.VISIBLE else View.GONE
|
}
|
viewModel.couldCheckIn.observe(this) {
|
binding.tvCheckIn.setBackgroundResource(if (it) R.drawable.shape_blue_5_bg_4 else R.drawable.shape_gray_4_bg_4)
|
binding.tvCheckInNotice.visibility = if (it) View.INVISIBLE else View.VISIBLE
|
binding.tvFloatCheckIn.setBackgroundResource(if (it) R.drawable.shape_blue_5_bg_4 else R.drawable.shape_gray_4_bg_4)
|
}
|
viewModel.checkInOperationInfo.observe(this) {
|
viewModel.getNextPoint()?.also { nextPoint ->
|
viewModel.couldCheckIn.postValue(it.isLocationInCheckInRange())
|
if (!it.isEffective()) {
|
binding.llTimeoutNotice.visibility = View.GONE
|
binding.slFloatNotice.visibility = View.GONE
|
return@observe
|
}
|
binding.tvTime.text = nextPoint.time
|
binding.tvAddress.text = nextPoint.address
|
|
if (it.needShowCheckInNotice() && !viewModel.showCheckInNoticeHistory.contains(it.checkLocationId)) {
|
viewModel.showCheckInNoticeHistory.add(it.checkLocationId!!)
|
viewModel.choicePoint.postValue(null)
|
viewModel.hadExpand.postValue(false)
|
binding.slFloatNotice.visibility = View.VISIBLE
|
SpanUtils.with(binding.tvFloatNotice)
|
.append("您已到达")
|
.setForegroundColor(getResColor(com.xw.common.R.color.gray_9))
|
.append("【${it.message ?: nextPoint.address ?: ""}】")
|
.setForegroundColor(getResColor(com.xw.common.R.color.blue_5))
|
.append("打卡点,是否立即打卡?")
|
.setForegroundColor(getResColor(com.xw.common.R.color.gray_9))
|
.create()
|
}
|
if (it.needShowTimeoutNotice()) {
|
binding.tvTimeoutNotice.text = it.message
|
binding.llTimeoutNotice.visibility = View.VISIBLE
|
binding.llTimeoutNotice.postDelayed(Runnable {
|
if (isFinishing || isDestroyed) {
|
return@Runnable
|
}
|
binding.ivCloseTimeoutNotice.performClick()
|
}, 3000)
|
}
|
}
|
}
|
viewModel.choicePoint.observe(this) {
|
if (it == null) {
|
binding.llClickLocationInfo.visibility = View.GONE
|
binding.ivFlexing.visibility = View.VISIBLE
|
binding.tvClickLocationCheckIn.setOnClickListener(null)
|
return@observe
|
}
|
binding.llClickLocationInfo.visibility = View.VISIBLE
|
binding.ivFlexing.visibility = View.GONE
|
binding.tvClickLocationTime.text = it.time
|
binding.tvClickLocationAddress.text = it.address
|
if (it.locationId == viewModel.checkInOperationInfo.value?.checkLocationId) {
|
binding.tvClickLocationCheckIn.setBackgroundResource(R.drawable.shape_blue_5_bg_4)
|
binding.tvClickLocationCheckInNotice.visibility = View.INVISIBLE
|
} else {
|
binding.tvClickLocationCheckIn.setBackgroundResource(R.drawable.shape_gray_4_bg_4)
|
binding.tvClickLocationCheckInNotice.visibility = View.VISIBLE
|
}
|
binding.tvClickLocationCheckIn.setOnClickListener { _ ->
|
binding.llClickLocationInfo.visibility = View.GONE
|
binding.ivFlexing.visibility = View.VISIBLE
|
binding.tvClickLocationCheckIn.setOnClickListener(null)
|
viewModel.jumpToCheckInPage(it)
|
}
|
}
|
}
|
|
//刷新下一个打卡点信息
|
private fun refreshNextPointInfo() {
|
viewModel.getNextPoint()?.also {
|
binding.tvTime.text = it.time
|
binding.tvAddress.text = it.address
|
}
|
}
|
|
//刷新预计耗时和剩余距离
|
private fun refreshCostDurationDistance(path: AMapNaviPath) {
|
binding.tvDistanceCostTime.text =
|
"${Utils.getFriendlyDistance(path.allLength)} ${
|
Utils.getFriendlyTime(path.allTime)
|
}"
|
val arrivalTime = System.currentTimeMillis() + (path.allTime * 1000)
|
binding.tvEstimatedTimeOfArrival.text =
|
"${SimpleDateFormat("HH:mm").format(Date(arrivalTime))}到达"
|
}
|
|
override fun setListener() {
|
super.setListener()
|
binding.llExit.setOnClickListener {
|
CommonDialog.showTipsDialog(
|
context = this,
|
content = "是否退出导航?",
|
rightText = "确认退出",
|
rightBlock = {
|
finish()
|
return@showTipsDialog true
|
})
|
}
|
binding.llOverview.setOnClickListener {
|
viewModel.isOverview.postValue(!(viewModel.isOverview.value ?: false))
|
}
|
binding.ivFlexing.setOnClickListener {
|
if (binding.slFloatNotice.isVisible) {
|
return@setOnClickListener
|
}
|
viewModel.hadExpand.postValue(!(viewModel.hadExpand.value ?: false))
|
//binding.slFloatNotice.visibility = View.GONE
|
}
|
binding.tvFloatDelayCheckIn.setOnClickListener { _ ->
|
binding.slFloatNotice.visibility = View.GONE
|
binding.ivFlexing.performClick()
|
}
|
binding.tvFloatCheckIn.setOnClickListener { _ ->
|
binding.slFloatNotice.visibility = View.GONE
|
viewModel.getNextPoint()?.also { nextPoint ->
|
viewModel.jumpToCheckInPage(nextPoint)
|
}
|
}
|
binding.tvCheckIn.setOnClickListener {
|
viewModel.getNextPoint()?.also { nextPoint ->
|
viewModel.jumpToCheckInPage(nextPoint)
|
}
|
}
|
binding.ivCloseTimeoutNotice.setOnClickListener {
|
binding.llTimeoutNotice.animate()
|
.alpha(0f)
|
.setDuration(300) // 动画时长(毫秒)
|
.withEndAction {
|
binding.llTimeoutNotice.visibility = View.GONE // 动画结束后隐藏控件
|
binding.llTimeoutNotice.alpha = 1f
|
}
|
.start()
|
}
|
binding.llClickLocationInfoBack.setOnClickListener {
|
viewModel.choicePoint.postValue(null)
|
}
|
}
|
|
override fun onResume() {
|
super.onResume()
|
binding.amapView.onResume()
|
}
|
|
override fun onPause() {
|
super.onPause()
|
binding.amapView.onPause()
|
}
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
super.onSaveInstanceState(outState)
|
binding.amapView.onSaveInstanceState(outState)
|
}
|
|
override fun onBackPressed() {
|
//super.onBackPressed()
|
binding.llExit.performClick()
|
}
|
|
//清除地图上的路线
|
private fun clearRouteFromMap() {
|
routeOverLay?.also {
|
it.removeFromMap()
|
it.destroy()
|
}
|
routeOverLay = null
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
if (EventBus.getDefault().isRegistered(this)) {
|
EventBus.getDefault().unregister(this)
|
}
|
clearRouteFromMap()
|
carOverlay?.also {
|
it.destroy()
|
}
|
carOverlay = null
|
binding.amapView.onDestroy()
|
aMapNavi?.also {
|
it.removeAMapNaviListener(this)
|
it.removeTTSPlayListener(this)
|
it.stopNavi()
|
AMapNavi.destroy()
|
}
|
}
|
|
override fun onInitNaviFailure() {
|
|
}
|
|
override fun onInitNaviSuccess() {
|
|
}
|
|
override fun onStartNavi(p0: Int) {
|
|
}
|
|
override fun onTrafficStatusUpdate() {
|
|
}
|
|
override fun onLocationChange(p0: AMapNaviLocation?) {
|
p0?.also { location ->
|
carOverlay?.also { it ->
|
viewModel.aMapNaviLocation = location
|
val latLng = LatLng(location.coord.latitude, location.coord.longitude)
|
it.draw(binding.amapView.map, latLng, location.bearing)
|
}
|
independentCalculateRoute()
|
}
|
refreshNextPointInfo()
|
}
|
|
override fun onGetNavigationText(p0: Int, p1: String?) {
|
|
}
|
|
override fun onGetNavigationText(p0: String?) {
|
|
}
|
|
override fun onEndEmulatorNavi() {
|
|
}
|
|
override fun onArriveDestination() {
|
|
}
|
|
override fun onCalculateRouteFailure(p0: Int) {
|
Log.d(TAG, "${if (viewModel.type == 0) "步行" else "骑行"}路线计算失败,$p0")
|
ToastUtilCommon.showError("${if (viewModel.type == 0) "步行" else "骑行"}路线计算失败")
|
}
|
|
override fun onReCalculateRouteForYaw() {
|
|
}
|
|
override fun onReCalculateRouteForTrafficJam() {
|
|
}
|
|
override fun onArrivedWayPoint(p0: Int) {
|
|
}
|
|
override fun onGpsOpenStatus(p0: Boolean) {
|
|
}
|
|
override fun onNaviInfoUpdate(p0: NaviInfo?) {
|
|
}
|
|
override fun updateCameraInfo(p0: Array<out AMapNaviCameraInfo?>?) {
|
|
}
|
|
override fun updateIntervalCameraInfo(
|
p0: AMapNaviCameraInfo?,
|
p1: AMapNaviCameraInfo?,
|
p2: Int
|
) {
|
|
}
|
|
override fun onServiceAreaUpdate(p0: Array<out AMapServiceAreaInfo?>?) {
|
|
}
|
|
override fun showCross(p0: AMapNaviCross?) {
|
|
}
|
|
override fun hideCross() {
|
|
}
|
|
override fun showModeCross(p0: AMapModelCross?) {
|
|
}
|
|
override fun hideModeCross() {
|
|
}
|
|
override fun showLaneInfo(
|
p0: Array<out AMapLaneInfo?>?,
|
p1: ByteArray?,
|
p2: ByteArray?
|
) {
|
|
}
|
|
override fun showLaneInfo(p0: AMapLaneInfo?) {
|
|
}
|
|
override fun hideLaneInfo() {
|
|
}
|
|
override fun onCalculateRouteSuccess(p0: IntArray?) {
|
|
}
|
|
override fun notifyParallelRoad(p0: Int) {
|
|
}
|
|
override fun OnUpdateTrafficFacility(p0: Array<out AMapNaviTrafficFacilityInfo?>?) {
|
|
}
|
|
override fun OnUpdateTrafficFacility(p0: AMapNaviTrafficFacilityInfo?) {
|
|
}
|
|
override fun updateAimlessModeStatistics(p0: AimLessModeStat?) {
|
|
}
|
|
override fun updateAimlessModeCongestionInfo(p0: AimLessModeCongestionInfo?) {
|
|
}
|
|
override fun onPlayRing(p0: Int) {
|
|
}
|
|
override fun onCalculateRouteSuccess(p0: AMapCalcRouteResult?) {
|
Log.d(TAG, "${if (viewModel.type == 0) "步行" else "骑行"}路线计算成功,$p0")
|
aMapNavi?.naviPath?.takeIf {
|
!isFinishing && !isDestroyed
|
}?.also { path ->
|
clearRouteFromMap()
|
binding.amapView.map?.clear()
|
refreshCostDurationDistance(path)
|
initRouteOverlay(path)
|
initArea()
|
initMarker()
|
initCarOverlay(path)
|
// 开启导航
|
aMapNavi?.startNavi(NaviType.GPS)
|
binding.amapView.postDelayed({
|
if (isFinishing || isDestroyed) {
|
return@postDelayed
|
}
|
viewModel.isOverview.postValue(false)
|
}, 100L)
|
}
|
}
|
|
//初始化路线
|
private fun initRouteOverlay(path: AMapNaviPath) {
|
routeOverLay = RouteOverLay(binding.amapView.map, path, this).apply {
|
setTrafficLine(true)
|
setLightsVisible(false)
|
setStartPointBitmap(null)
|
setEndPointBitmap(null)
|
setWayPointBitmap(null)
|
showRouteStart(false)
|
showRouteEnd(false)
|
// setPassRouteVisible(false)
|
routeOverlayOptions = RouteOverlayOptions().apply {
|
setOnRouteCameShow(false)
|
}
|
addToMap()
|
}
|
drawLeaderLines(path)
|
}
|
|
//绘制起点/终点的回拉线(人到路线起点、路线终点到建筑内终点)
|
private fun drawLeaderLines(naviPath: AMapNaviPath) {
|
binding.amapView.map?.also { aMap ->
|
leaderLines.forEach { it.remove() }
|
leaderLines.clear()
|
|
val coordList = naviPath.coordList ?: return
|
if (coordList.isEmpty()) return
|
val routeStart = LatLng(coordList.first().latitude, coordList.first().longitude)
|
val routeEnd = LatLng(coordList.last().latitude, coordList.last().longitude)
|
val lineColor = getResColor(com.xw.common.R.color.gray_6)
|
|
viewModel.startPoint?.coordinate?.also { startLatLng ->
|
if (AMapUtils.calculateLineDistance(startLatLng, routeStart) > 5) {
|
aMap.addPolyline(
|
PolylineOptions()
|
.add(startLatLng, routeStart)
|
.width(13f)
|
.color(lineColor)
|
.setDottedLine(true)
|
)?.also { leaderLines.add(it) }
|
}
|
}
|
|
viewModel.getEndPoint()?.coordinate?.also { endLatLng ->
|
if (AMapUtils.calculateLineDistance(routeEnd, endLatLng) > 5) {
|
aMap.addPolyline(
|
PolylineOptions()
|
.add(routeEnd, endLatLng)
|
.width(13f)
|
.color(lineColor)
|
.setDottedLine(true)
|
)?.also { leaderLines.add(it) }
|
}
|
}
|
}
|
}
|
|
//初始化marker
|
private fun initMarker() {
|
binding.amapView.map?.also {
|
// viewModel.startPoint?.also { startPoint ->
|
// it.addMarker(
|
// MarkerOptions()
|
// .position(
|
// LatLng(
|
// startPoint.coordinate.latitude,
|
// startPoint.coordinate.longitude
|
// )
|
// )
|
// .icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_start_point))
|
// .anchor(0.5f, 0.5f)
|
// )?.apply {
|
// isClickable = true
|
// `object` = startPoint
|
// }
|
// }
|
viewModel.getEndPoint()?.also { endPoint ->
|
it.addMarker(
|
MarkerOptions()
|
.position(
|
LatLng(
|
endPoint.coordinate.latitude,
|
endPoint.coordinate.longitude
|
)
|
)
|
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_end_point))
|
.anchor(0.5f, 0.5f)
|
)?.apply {
|
isClickable = true
|
`object` = endPoint
|
}
|
}
|
viewModel.getPassingPoints().forEach { point ->
|
it.addMarker(
|
MarkerOptions()
|
.position(
|
LatLng(
|
point.coordinate.latitude,
|
point.coordinate.longitude
|
)
|
)
|
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pass_point))
|
.anchor(0.5f, 0.5f)
|
)?.apply {
|
isClickable = true
|
`object` = point
|
}
|
}
|
}
|
}
|
|
//初始化范围
|
private fun initArea() {
|
binding.amapView.map?.also { it ->
|
viewModel.points.value?.filter { !it.hadCheckIn() }?.forEach { point ->
|
it.addCircle(CircleOptions().apply {
|
center(
|
LatLng(
|
point.lat?.toDoubleOrNull() ?: 0.0,
|
point.lon?.toDoubleOrNull() ?: 0.0
|
)
|
)
|
radius(point.openRange?.toDoubleOrNull() ?: 0.0)
|
fillColor(R.color.color_1a026ee4.colorIdToColorValue(application))
|
strokeColor(Color.TRANSPARENT)
|
})
|
}
|
}
|
}
|
|
//初始化车标
|
private fun initCarOverlay(path: AMapNaviPath) {
|
carOverlay?.also { it ->
|
it.reset()
|
path.endPoint?.also { end ->
|
it.setEndPoi(LatLng(end.latitude, end.longitude))
|
}
|
val latLng = viewModel.aMapNaviLocation?.let {
|
NaviLatLng(it.coord.latitude, it.coord.longitude)
|
} ?: NaviLatLng(
|
viewModel.startPoint!!.coordinate.latitude,
|
viewModel.startPoint!!.coordinate.longitude
|
)
|
val rotate = NaviUtil.getRotate(latLng, path.coordList.first())
|
it.draw(binding.amapView.map, viewModel.startPoint!!.coordinate, rotate)
|
}
|
}
|
|
//POI独立算路
|
//独立路径规划是指路径规划的结果不会自动应用于当前导航,也不会干扰当前的导航
|
private fun independentCalculateRoute() {
|
viewModel.aMapNaviLocation?.takeIf {
|
(lastCalculateRouteStartLocation == null || NaviUtil.calculateDistance(
|
lastCalculateRouteStartLocation!!.coord,
|
it.coord
|
) > 10) && viewModel.getEndPoint() != null
|
}?.also { location ->
|
aMapNavi?.also {
|
when (viewModel.type) {
|
0, 1 -> {
|
lastCalculateRouteStartLocation = location
|
val success = it.independentCalculateRoute(
|
NaviPoi(
|
"起点",
|
LatLng(location.coord.latitude, location.coord.longitude),
|
""
|
),
|
viewModel.getEndPoint()!!,
|
viewModel.getPassingPoints(),
|
TravelStrategy.SINGLE.value,
|
if (viewModel.type == 0) TransportType.Walk else TransportType.Ride,
|
this
|
)
|
if (!success) {
|
Log.d(
|
TAG,
|
"${if (viewModel.type == 0) "步行" else "骑行"}独立算路失败,检查参数情况"
|
)
|
}
|
}
|
}
|
}
|
}
|
}
|
|
override fun onCalculateRouteFailure(p0: AMapCalcRouteResult?) {
|
|
}
|
|
override fun onNaviRouteNotify(p0: AMapNaviRouteNotifyData?) {
|
|
}
|
|
override fun onGpsSignalWeak(p0: Boolean) {
|
|
}
|
|
override fun onPlayStart(p0: String?) {
|
viewModel.hadPlayTTS = true
|
}
|
|
override fun onPlayEnd(p0: String?) {
|
viewModel.hadPlayTTS = false
|
}
|
|
override fun onIndependentCalculateSuccess(p0: AMapNaviPathGroup?) {
|
Log.d(TAG, "${if (viewModel.type == 0) "步行" else "骑行"}独立算路成功${p0}")
|
p0?.takeIf {
|
it.mainPath != null && !isFinishing && !isDestroyed
|
}?.also {
|
refreshCostDurationDistance(it.mainPath)
|
clearRouteFromMap()
|
initRouteOverlay(it.mainPath)
|
}
|
}
|
|
override fun onIndependentCalculateFail(p0: AMapCalcRouteResult?) {
|
Log.d(TAG, "${if (viewModel.type == 0) "步行" else "骑行"}独立算路失败,$p0")
|
}
|
|
override fun onIndependentCalculateInvoke(p0: Int) {
|
|
}
|
|
@Suppress("unused")
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
fun onMessageEvent(event: CruiseCheckInOperationResult) {
|
if (event.cruiseCheckInRuleId != viewModel.id) {
|
return
|
}
|
viewModel.refreshPoints(event.checkLocationId, event.checkIn, event.checkInResult)
|
}
|
}
|