From 0376eba508e85392f39112d20889b0212b6451a7 Mon Sep 17 00:00:00 2001 From: chenfufeng Date: Thu, 21 Nov 2024 18:07:43 +0800 Subject: [PATCH] =?UTF-8?q?[6.8.0][Feat]Bus=E6=96=B0=E5=A2=9E=E9=80=94?= =?UTF-8?q?=E7=BB=8F=E7=AB=99=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/function/view/TravelRealityView.kt | 172 ++++++++++++++++-- 1 file changed, 158 insertions(+), 14 deletions(-) diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt index c75d2cf03c..8f23653e39 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/TravelRealityView.kt @@ -33,6 +33,7 @@ import com.amap.api.maps.model.PolylineOptions import com.mogo.eagle.core.data.config.FunctionBuildConfig import com.mogo.eagle.core.data.map.MogoLatLng import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.data.map.SiteMarkerBean import com.mogo.eagle.core.data.och.OchInfo import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener @@ -95,6 +96,7 @@ class TravelRealityView @JvmOverloads constructor( private const val DRAW_END_MARKER = 10 private const val UPDATE_VIDEO_MARKER = 11 private const val HIDE_CAR_MARKER = 12 + private const val DRAW_SITE_MARKERS = 13 // private const val CLEAR_POLY_LINE = 12 // private const val CLEAR_ROAD_EVENT = 13 @@ -128,6 +130,14 @@ class TravelRealityView @JvmOverloads constructor( private val globalPolylineList by lazy { ArrayList() } + private val siteMarkerList by lazy { + ArrayList() + } + + // Bus会用到 + private val mSiteList by lazy { + ArrayList() + } @Volatile private var mLocation: MogoLocation? = null @@ -139,6 +149,8 @@ class TravelRealityView @JvmOverloads constructor( @Volatile private var isMapDestroyed = false + @Volatile + private var ochType = -1 // =============自定义属性相关============= private var mapStylePath: String? = null @@ -151,6 +163,7 @@ class TravelRealityView @JvmOverloads constructor( private var topPadding: Int = 150 private var rightPadding: Int = 100 private var bottomPadding: Int = 300 + // 订单结束弹窗 private var isOrderEnd = false @@ -244,9 +257,17 @@ class TravelRealityView @JvmOverloads constructor( private var mPolyline: Polyline? = null private var mSmallStartMarker: Marker? = null private var mSmallEndMarker: Marker? = null + + // 目前Taxi用到 private var mStartLatLng: LatLng? = null private var mEndLatLng: LatLng? = null + // Bus会用到 + private var mSmallSiteList: List? = null + + // Bus有起终点和途经站点 + private var smallSiteMarkerList: ArrayList? = null + init { try { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TravelRealityView) @@ -344,7 +365,11 @@ class TravelRealityView @JvmOverloads constructor( } // 显示小地图样式 changeMapSettings(true) - resumeStartEndMarker() + if (ochType == 1) { + resumeSiteMarkers() + } else {// 接收到type为0的数据 + resumeStartEndMarker() + } globalPathResp?.let { if (it.wayPointsList.size > 0) { drawRotting() @@ -355,7 +380,11 @@ class TravelRealityView @JvmOverloads constructor( hideSmallCarMarker() // 显示行程总览地图样式 changeMapSettings(false) - resumeStartEndMarker() + if (ochType == 1) { + resumeSiteMarkers() + } else {// 接收到type为0的数据 + resumeStartEndMarker() + } // 绘制自车 mLocation?.let { drawCarMarker(it) } val globalPath = reqData @@ -1543,6 +1572,7 @@ class TravelRealityView @JvmOverloads constructor( } } + private fun clearPolyline() { if (mPolyline != null) { mPolyline!!.points = emptyList() @@ -1698,27 +1728,68 @@ class TravelRealityView @JvmOverloads constructor( override fun invokeOchInfo(ochInfo: OchInfo) { super.invokeOchInfo(ochInfo) Log.d(TAG, "invokeOchInfo:$ochInfo") + ochType = ochInfo.type if (ochInfo.type == 0) { val locationList = ochInfo.latLonList - locationList?.let { locList-> - if (locList.isEmpty() || locList.size < 2) { - mStartLatLng = null - mEndLatLng = null - UiThreadHandler.post { - hideStartEndMarker() - } - } else { - // 设置开始结束Marker位置 - mStartLatLng = LatLng(locList[0].latitude, locList[0].longitude) - mEndLatLng = LatLng(locList[1].latitude, locList[1].longitude) + locationList?.let { locList -> + drawStartAndEnd(locList) + } + } else if (ochInfo.type == 1) { + val siteDataList = ochInfo.siteMarkerList + siteDataList?.let { siteList -> + val markerOptionsList: ArrayList = ArrayList() + siteList.forEach { it -> + markerOptionsList.add(MarkerOptions().apply { + position(LatLng(it.latLng.lat!!, it.latLng.lon!!)) + anchor(it.anchorX, it.anchorY) + icon(BitmapDescriptorFactory.fromResource(it.resId)) + }) + mSiteList.add( + SiteMarkerBean( + com.mogo.eagle.core.data.v2x.Point( + it.latLng.lon, + it.latLng.lat + ), it.resId, it.anchorX, it.anchorY + ) + ) } + mSmallSiteList = siteDataList if (!isPlayingAnim) { - drawStartAndEnd() + drawSiteMarkers(markerOptionsList) + } else { + UiThreadHandler.post { + drawSiteMarkers(markerOptionsList) + } } } } } + private fun drawStartAndEnd(locList: List) { + if (locList.isEmpty() || locList.size < 2) { + mStartLatLng = null + mEndLatLng = null + if (isSmallMap) { + UiThreadHandler.post { + hideStartEndMarker() + } + } else { + drawStartEndMarker(ArrayList()) + } + } else { + // 设置开始结束Marker位置 + mStartLatLng = LatLng(locList[0].latitude, locList[0].longitude) + mEndLatLng = LatLng(locList[1].latitude, locList[1].longitude) + } + if (!isPlayingAnim) { + drawStartAndEnd() + } else { + UiThreadHandler.post { + drawStartAndEnd() + } + } + } + private fun resumeStartEndMarker() { if (mStartLatLng != null && mEndLatLng != null) { drawStartAndEnd() @@ -1757,6 +1828,51 @@ class TravelRealityView @JvmOverloads constructor( } } + private fun drawSiteMarkers(markerOptionsList: ArrayList) { + if (isSmallMap) { + if (markerOptionsList.isEmpty()) { + UiThreadHandler.post { + smallSiteMarkerList?.forEach { + it.destroy() + } + smallSiteMarkerList = null + } + } else { + UiThreadHandler.post { + smallSiteMarkerList = mAMap?.addMarkers(markerOptionsList, false) + } + } + } else { + Message.obtain().apply { + what = DRAW_SITE_MARKERS + obj = markerOptionsList + nonFrequentHandler?.sendMessage(this) + } + } + } + + private fun resumeSiteMarkers() { + val markerOptionsList: ArrayList = ArrayList() + if (isSmallMap) { + mSmallSiteList?.forEach { + markerOptionsList.add(MarkerOptions().apply { + position(LatLng(it.latLng.lat!!, it.latLng.lon!!)) + anchor(it.anchorX, it.anchorY) + icon(BitmapDescriptorFactory.fromResource(it.resId)) + }) + } + } else { + mSiteList.forEach { + markerOptionsList.add(MarkerOptions().apply { + position(LatLng(it.latLng.lat!!, it.latLng.lon!!)) + anchor(it.anchorX, it.anchorY) + icon(BitmapDescriptorFactory.fromResource(it.resId)) + }) + } + } + drawSiteMarkers(markerOptionsList) + } + interface OnDrawListener { // isEvent为true表示是事件,反之则表示全息路口 fun onDraw(eventList: List, isEvent: Boolean) @@ -1881,6 +1997,12 @@ class TravelRealityView @JvmOverloads constructor( realDrawEndMarker(msg.obj as ArrayList) } + DRAW_SITE_MARKERS -> { + removeMessages(DRAW_SITE_MARKERS) + if (isMapDestroyed) return + realDrawSiteMarkers(msg.obj as ArrayList) + } + UPDATE_VIDEO_MARKER -> { removeMessages(UPDATE_VIDEO_MARKER) if (isMapDestroyed) return @@ -2116,6 +2238,24 @@ class TravelRealityView @JvmOverloads constructor( } } + private fun realDrawSiteMarkers(options: ArrayList) { + CallerLogger.d("$M_MAP$TAG", "realDrawSiteMarkers") + if (options.isEmpty()) { + siteMarkerList.forEach { + it.destroy() + } + siteMarkerList.clear() + } else { + options.forEach { + mAMap?.let { map -> + siteMarkerList.add(map.addMarker(it).also { marker -> + marker.isClickable = false + }) + } + } + } + } + private fun realDrawRoadRange(polylineOptions: PolylineOptions) { // mAMap?.addPolyline(polylineOptions) } @@ -2127,6 +2267,10 @@ class TravelRealityView @JvmOverloads constructor( mStartMarker = null mEndMarker?.destroy() mEndMarker = null + siteMarkerList.forEach { + it.destroy() + } + siteMarkerList.clear() // 清除道路事件icon eventMarkerList.forEach { it.destroy()