| | |
| | | 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 |
| | |
| | | |
| | | //路线OverLay |
| | | var routeOverLay: RouteOverLay? = null |
| | | |
| | | //起点/终点回拉线 |
| | | private val leaderLines = mutableListOf<Polyline>() |
| | | |
| | | //上次计算路线起点定位 |
| | | var lastCalculateRouteStartLocation: AMapNaviLocation? = null |
| | |
| | | } |
| | | 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 |