[3.2.0][Opt]全览模式绘制线流畅性优化
This commit is contained in:
@@ -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<LatLng>?, bitmap: Bitmap) {
|
||||
if (coordinates.isNullOrEmpty()) return
|
||||
clearSitePolyline()
|
||||
val textureList = arrayListOf<BitmapDescriptor>()
|
||||
val texIndexList = arrayListOf<Int>()
|
||||
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<LatLng>, bitmap: Bitmap) {
|
||||
Log.d("cff", "绘制站点线!!!")
|
||||
val textureList = arrayListOf<BitmapDescriptor>()
|
||||
textureList.add(BitmapDescriptorFactory.fromBitmap(bitmap))
|
||||
val texIndexList = arrayListOf<Int>()
|
||||
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<List<LatLng>, 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<List<LatLng>, 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()
|
||||
|
||||
Reference in New Issue
Block a user