From b841798efab2a9b4ac1647b4ac822890c289bf7e Mon Sep 17 00:00:00 2001 From: chenfufeng Date: Mon, 12 Jun 2023 13:30:34 +0800 Subject: [PATCH] =?UTF-8?q?[3.2.0][Opt]=E5=85=A8=E8=A7=88=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E7=BB=98=E5=88=B6=E7=BA=BF=E6=B5=81=E7=95=85=E6=80=A7?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eagle/core/function/view/OverMapView.kt | 106 +++++++++++------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt index 793957b2a2..081e069386 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt @@ -100,7 +100,8 @@ class OverMapView @JvmOverloads constructor( private var mCompassMarker: Marker? = null private var mStartMarker: Marker? = null private var mEndMarker: Marker? = null - private var mBottomPolyline: Polyline? = null + + // private var mBottomPolyline: Polyline? = null private var mCoveredPolyline: Polyline? = null private var mSitePolyline: Polyline? = null @@ -126,6 +127,9 @@ class OverMapView @JvmOverloads constructor( @Volatile private var lastTime = 0L + @Volatile + private var isPointsChanged = false + /** * 高频的 */ @@ -736,26 +740,11 @@ class OverMapView @JvmOverloads constructor( fun drawSitePolyline(coordinates: List?, bitmap: Bitmap) { if (coordinates.isNullOrEmpty()) return clearSitePolyline() - val textureList = arrayListOf() - val texIndexList = arrayListOf() - for (i in coordinates.indices) { - // 线段数比点数少一个 - if (i == 0) continue - textureList.add(BitmapDescriptorFactory.fromBitmap(bitmap)) - texIndexList.add(i - 1) - } if (mAMap != null) { - //设置线段纹理 - val polylineOptions = PolylineOptions() - polylineOptions.addAll(coordinates) - polylineOptions.width(14f) //线段宽度 - polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound) - polylineOptions.customTextureList = textureList - polylineOptions.customTextureIndex = texIndexList - // 绘制线 Message.obtain().apply { what = DRAW_SITE_LINE - obj = polylineOptions + obj = Pair(coordinates, bitmap) + Log.d("cff", "发送绘制站点轨迹!") nonFrequentHandler?.sendMessage(this) } } @@ -767,6 +756,7 @@ class OverMapView @JvmOverloads constructor( fun clearSitePolyline() { Message.obtain().apply { what = CLEAR_SITE_POLYLINE + Log.d("cff", "发送清除站点轨迹!") nonFrequentHandler?.sendMessage(this) } } @@ -796,22 +786,33 @@ class OverMapView @JvmOverloads constructor( if (texIndexList.size > 0) { texIndexList.clear() } + if (isClearArrived) { + textureList.add(transparentBitmap)// index:0 + } else { + // 已走过的置灰 + textureList.add(arrivedBitmap)// index:0 + } + // 未走过的纹理 + textureList.add(unArrivedBitmap)// index:1 for (i in coordinates.indices) { // 线段数比点数少一个 if (i == 0) continue if (i <= locIndex) { - if (isClearArrived) { - textureList.add(transparentBitmap) - } else { - // 已走过的置灰 - textureList.add(arrivedBitmap) - } + texIndexList.add(0) } else { - // 未走过的纹理 - textureList.add(unArrivedBitmap) + texIndexList.add(1) } - texIndexList.add(i - 1) } + if (mCoveredPolyline != null) { + mCoveredPolyline!!.options.customTextureList = textureList + mCoveredPolyline!!.options.customTextureIndex = texIndexList + if (isPointsChanged) { + mCoveredPolyline!!.points = coordinates + isPointsChanged = false + } + return + } + if (mAMap != null && coordinates.size > 2) { Log.d( TAG, @@ -825,12 +826,7 @@ class OverMapView @JvmOverloads constructor( polylineOptions.customTextureList = textureList polylineOptions.customTextureIndex = texIndexList // 绘制线 - mBottomPolyline = mCoveredPolyline mCoveredPolyline = mAMap?.addPolyline(polylineOptions) - if (mBottomPolyline != null) { - mBottomPolyline!!.remove() - mBottomPolyline = null - } } Log.d(TAG, "绘制全局轨迹线耗时为:${System.currentTimeMillis() - time}ms") } @@ -979,17 +975,42 @@ class OverMapView @JvmOverloads constructor( } } - private fun realDrawSitePolyline(options: PolylineOptions) { - mSitePolyline = mAMap?.addPolyline(options) + private fun realDrawSitePolyline(coordinates: List, bitmap: Bitmap) { + Log.d("cff", "绘制站点线!!!") + val textureList = arrayListOf() + textureList.add(BitmapDescriptorFactory.fromBitmap(bitmap)) + val texIndexList = arrayListOf() + for (i in coordinates.indices) { + // 线段数比点数少一个 + if (i == 0) continue + texIndexList.add(0) + } + if (mAMap != null) { + if (mSitePolyline != null) { + mSitePolyline!!.options.customTextureList = textureList + mSitePolyline!!.options.customTextureIndex = texIndexList + mSitePolyline!!.points = coordinates + return + } + //设置线段纹理 + val polylineOptions = PolylineOptions() + polylineOptions.addAll(coordinates) + polylineOptions.width(14f) //线段宽度 + polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound) + polylineOptions.customTextureList = textureList + polylineOptions.customTextureIndex = texIndexList + // 绘制线 + mSitePolyline = mAMap?.addPolyline(polylineOptions) + } } private fun realClearPolyline() { - mBottomPolyline?.remove() - mCoveredPolyline?.remove() + mCoveredPolyline?.points = emptyList() } private fun realClearSitePolyline() { - mSitePolyline?.remove() + Log.d("cff", "清除站点线!!!") + mSitePolyline?.points = emptyList() } fun realClearV2XMarkers() { @@ -1065,6 +1086,7 @@ class OverMapView @JvmOverloads constructor( lastTime = System.currentTimeMillis() } MarkerDrawerManager.stopLoopCalCarLocation() + isPointsChanged = true globalPathResp?.let { ThreadUtils.getIoPool().execute { handlePlanningData(it.wayPointsList) @@ -1141,7 +1163,6 @@ class OverMapView @JvmOverloads constructor( super.handleMessage(msg) when (msg.what) { DRAW_POLY_LINE -> { - removeMessages(CLEAR_POLY_LINE) removeMessages(DRAW_POLY_LINE) (msg.obj as Pair, Int>).apply { realDrawPolyline(first, second) @@ -1154,7 +1175,6 @@ class OverMapView @JvmOverloads constructor( } } CLEAR_POLY_LINE -> { - removeMessages(DRAW_POLY_LINE) removeMessages(CLEAR_POLY_LINE) realClearPolyline() } @@ -1168,12 +1188,12 @@ class OverMapView @JvmOverloads constructor( super.handleMessage(msg) when (msg.what) { DRAW_SITE_LINE -> { - removeMessages(CLEAR_SITE_POLYLINE) + Log.d("cff", "准备真正执行绘制站点线") removeMessages(DRAW_SITE_LINE) // 绘制站点轨迹线时停止绘制全局轨迹,降低性能损耗 MarkerDrawerManager.isStopCalculate = true - (msg.obj as PolylineOptions).apply { - realDrawSitePolyline(this) + (msg.obj as Pair, Bitmap>).apply { + realDrawSitePolyline(first, second) } } DRAW_V2X_MARKERS -> { @@ -1199,7 +1219,7 @@ class OverMapView @JvmOverloads constructor( } } CLEAR_SITE_POLYLINE -> { - removeMessages(DRAW_SITE_LINE) + Log.d("cff", "准备真正执行清除站点线") removeMessages(CLEAR_SITE_POLYLINE) MarkerDrawerManager.isStopCalculate = false realClearSitePolyline()