[6.5.0][Opt]调整下行程全览线的粗细

This commit is contained in:
chenfufeng
2024-07-15 16:37:35 +08:00
parent 1977a8c06f
commit 2624efb9aa
4 changed files with 179 additions and 109 deletions

View File

@@ -129,21 +129,20 @@ class TravelRealityView @JvmOverloads constructor(
private var rightPadding: Int = 100
private var bottomPadding: Int = 300
private var roadRangeBitmap: BitmapDescriptor? = null
// 绘制智慧道路的范围
private var roadRange = 56f
private var roadRangeDrawable: Int = -1
private var globalPathColor: Int = Color.parseColor("#49DEAE")
private var roadTrajectoryColor: Int = Color.parseColor("#0FB2D8")
private val roadTrajectoryBitmap by lazy {
BitmapDescriptorFactory.fromResource(R.drawable.mogo_road_over)
}
@Volatile
private var roadRange = minRoadRange
@Volatile
private var roadWidth = minRoadWidth
@Volatile
private var globalWidth = minGlobalWidth
private var roadRangeBitmap: BitmapDescriptor? = null
// 绘制智慧道路范围内的带箭头的轨迹线
private var roadWidth = 28f
private var roadTrajectoryDrawable: Int = -1
private var roadTrajectoryColor: Int = Color.parseColor("#0FB2D8")
private var roadTrajectoryBitmap: BitmapDescriptor? = null
// 轨迹线
private var globalWidth = 18f
private var globalPathColor: Int = Color.parseColor("#49DEAE")
// // 测试时使用
@@ -215,6 +214,8 @@ class TravelRealityView @JvmOverloads constructor(
typedArray.getResourceId(R.styleable.TravelRealityView_compassDrawable, -1)
roadRangeDrawable =
typedArray.getResourceId(R.styleable.TravelRealityView_roadRangeDrawable, -1)
roadTrajectoryDrawable =
typedArray.getResourceId(R.styleable.TravelRealityView_roadTrajectoryDrawable, -1)
globalPathColor = typedArray.getInt(
R.styleable.TravelRealityView_globalPathColor,
Color.parseColor("#49DEAE")
@@ -266,7 +267,9 @@ class TravelRealityView @JvmOverloads constructor(
LayoutInflater.from(context).inflate(R.layout.module_travel_reality_view, this)
mMapView = mapView.findViewById(R.id.travelMapView)
roadRangeBitmap =
BitmapDescriptorFactory.fromResource(if (roadRangeDrawable != -1) roadRangeDrawable else R.drawable.taxi_map_arrow_arrived)
BitmapDescriptorFactory.fromResource(if (roadRangeDrawable != -1) roadRangeDrawable else R.drawable.mogo_road_over)
roadTrajectoryBitmap =
BitmapDescriptorFactory.fromResource(if (roadTrajectoryDrawable != -1) roadTrajectoryDrawable else R.drawable.road_trajectory_arrow_nor)
initAMapView()
}
@@ -301,15 +304,22 @@ class TravelRealityView @JvmOverloads constructor(
if (loc.latitude.toInt() == 0 || loc.longitude.toInt() == 0) {
mAMap?.moveCamera(CameraUpdateFactory.zoomTo(14f))
} else {
mAMap?.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinateConverterWgsToGcj(loc.latitude, loc.longitude), 14f))
mAMap?.moveCamera(
CameraUpdateFactory.newLatLngZoom(
coordinateConverterWgsToGcj(
loc.latitude,
loc.longitude
), 14f
)
)
}
//设置地图的样式
mAMap?.uiSettings?.let {
//所有手势
it.setAllGesturesEnabled(true)
//地图缩放级别的交换按钮
it.isZoomControlsEnabled = false
it.isZoomGesturesEnabled = false
it.isZoomControlsEnabled = true
it.isZoomGesturesEnabled = true
//指南针
it.isCompassEnabled = false
//设置倾斜手势是否可用。
@@ -418,15 +428,15 @@ class TravelRealityView @JvmOverloads constructor(
globalData[0].lon
)
Log.w(TAG, "起终点距离为:$distance")
if (distance < 2000) {
roadRange = maxRoadRange
roadWidth = minRoadWidth
globalWidth = minGlobalWidth
} else {
roadRange = minRoadRange
roadWidth = maxRoadWidth
globalWidth = maxGlobalWidth
}
// if (distance < 2000) {
// roadRange = maxRoadRange
// roadWidth = minRoadWidth
// globalWidth = minGlobalWidth
// } else {
// roadRange = minRoadRange
// roadWidth = maxRoadWidth
// globalWidth = maxGlobalWidth
// }
val endOption = MarkerOptions()
endOption.icon(BitmapDescriptorFactory.fromResource(endPointDrawable))
@@ -462,8 +472,10 @@ class TravelRealityView @JvmOverloads constructor(
) {
return@forEach
}
eventBean.orientation = travelNetWorkModel.calculateOrientation(eventBean.lon, eventBean.lat, globalPoint.lon,
globalPoint.lat, globalList[index + 1].lon, globalList[index + 1].lat,)
eventBean.orientation = travelNetWorkModel.calculateOrientation(
eventBean.lon, eventBean.lat, globalPoint.lon,
globalPoint.lat, globalList[index + 1].lon, globalList[index + 1].lat,
)
filterEventWithType(eventBean, eventOptionsList, eventDrawMap)
listener?.onDraw(eventDrawMap.values.toList(), true)
}
@@ -483,19 +495,31 @@ class TravelRealityView @JvmOverloads constructor(
val ipList = mutableListOf<String>()
roadEventList[0].let {
it.ip?.let { ip ->
ipPointMap[ip] = VideoMarkerEntity(coordinateConverterWgsToGcj(it.lat, it.lon), it.title, it.orientation)
ipPointMap[ip] = VideoMarkerEntity(
coordinateConverterWgsToGcj(it.lat, it.lon),
it.title,
it.orientation
)
ipList.add(ip)
}
}
roadEventList[(roadEventList.size - 1) / 2].let {
it.ip?.let { ip ->
ipPointMap[ip] = VideoMarkerEntity(coordinateConverterWgsToGcj(it.lat, it.lon), it.title, it.orientation)
ipPointMap[ip] = VideoMarkerEntity(
coordinateConverterWgsToGcj(it.lat, it.lon),
it.title,
it.orientation
)
ipList.add(ip)
}
}
roadEventList[roadEventList.size - 1].let {
it.ip?.let { ip ->
ipPointMap[ip] = VideoMarkerEntity(coordinateConverterWgsToGcj(it.lat, it.lon), it.title, it.orientation)
ipPointMap[ip] = VideoMarkerEntity(
coordinateConverterWgsToGcj(it.lat, it.lon),
it.title,
it.orientation
)
ipList.add(ip)
}
}
@@ -538,7 +562,8 @@ class TravelRealityView @JvmOverloads constructor(
eventBean.title = "道路施工"
roadEventList.add(eventBean)
if (!eventDrawMap.containsKey("800002")) {
eventDrawMap["800002"] = EventDrawBean(R.drawable.mogo_shigong_image, "道路施工")
eventDrawMap["800002"] =
EventDrawBean(R.drawable.mogo_shigong_image, "道路施工")
}
}
@@ -591,7 +616,11 @@ class TravelRealityView @JvmOverloads constructor(
val ipList = mutableListOf<String>()
roadEventList.forEach {
it.ip?.let { ip ->
ipPointMap[ip] = VideoMarkerEntity(coordinateConverterWgsToGcj(it.lat, it.lon), it.title, it.orientation)
ipPointMap[ip] = VideoMarkerEntity(
coordinateConverterWgsToGcj(it.lat, it.lon),
it.title,
it.orientation
)
ipList.add(ip)
}
}
@@ -599,10 +628,12 @@ class TravelRealityView @JvmOverloads constructor(
for (i in crossDeviceListTmp.indices) {
if (maxSize > 0 && !crossDeviceListTmp[i].deviceInfoList.isNullOrEmpty()) {
crossDeviceListTmp[i].deviceInfoList!![0].deviceIp?.let {
ipPointMap[it] = VideoMarkerEntity(coordinateConverterWgsToGcj(
crossDeviceListTmp[i].deviceInfoList!![0].lat,
crossDeviceListTmp[i].deviceInfoList!![0].lon
), "全息路口", crossDeviceListTmp[i].deviceInfoList!![0].orientation)
ipPointMap[it] = VideoMarkerEntity(
coordinateConverterWgsToGcj(
crossDeviceListTmp[i].deviceInfoList!![0].lat,
crossDeviceListTmp[i].deviceInfoList!![0].lon
), "全息路口", crossDeviceListTmp[i].deviceInfoList!![0].orientation
)
ipList.add(it)
maxSize--
}
@@ -642,9 +673,16 @@ class TravelRealityView @JvmOverloads constructor(
var view: EventVideoView
if (ipPointMap[ip] != null) {
markerOption.position(ipPointMap[ip]?.latLng)
view = EventVideoView(context, title = ipPointMap[ip]!!.title, orientation = ipPointMap[ip]!!.orientation)
view = EventVideoView(
context,
title = ipPointMap[ip]!!.title,
orientation = ipPointMap[ip]!!.orientation
)
pair = travelNetWorkModel.calculateAnchor(ipPointMap[ip]!!.orientation)
Log.d(TAG, "绘制时位置为:${ipPointMap[ip]?.latLng},标题为:${ipPointMap[ip]!!.title},方向为:${ipPointMap[ip]!!.orientation},锚点为:${pair}")
Log.d(
TAG,
"绘制时位置为:${ipPointMap[ip]?.latLng},标题为:${ipPointMap[ip]!!.title},方向为:${ipPointMap[ip]!!.orientation},锚点为:${pair}"
)
markerOption.anchor(pair.first, pair.second)
} else {
return@let
@@ -656,7 +694,12 @@ class TravelRealityView @JvmOverloads constructor(
markerOption.position(ipPointMap[ip]?.latLng)
pair = travelNetWorkModel.calculateAnchor(ipPointMap[ip]?.orientation ?: 0)
markerOption.anchor(pair.first, pair.second)
downloadImage(roadCamera.imageUrl!!, ipPointMap[ip]?.latLng, ipPointMap[ip]?.title, ipPointMap[ip]?.orientation ?: 0)
downloadImage(
roadCamera.imageUrl!!,
ipPointMap[ip]?.latLng,
ipPointMap[ip]?.title,
ipPointMap[ip]?.orientation ?: 0
)
}
liveOptionsList.add(markerOption)
}
@@ -690,8 +733,14 @@ class TravelRealityView @JvmOverloads constructor(
return@loop
}
// 计算事件Marker朝向
deviceBean.orientation = travelNetWorkModel.calculateOrientation(deviceBean.lon, deviceBean.lat,
globalPoint.lon, globalPoint.lat, globalList[index + 1].lon, globalList[index + 1].lat)
deviceBean.orientation = travelNetWorkModel.calculateOrientation(
deviceBean.lon,
deviceBean.lat,
globalPoint.lon,
globalPoint.lat,
globalList[index + 1].lon,
globalList[index + 1].lat
)
deviceInPaths.add(deviceBean)
crossOptionsList.add(MarkerOptions().apply {
position(
@@ -708,7 +757,10 @@ class TravelRealityView @JvmOverloads constructor(
}
}
if (deviceInPaths.isNotEmpty()) {
listener?.onDraw(arrayListOf(EventDrawBean(R.drawable.mogo_quanxi_lukou, "全息路口")), false)
listener?.onDraw(
arrayListOf(EventDrawBean(R.drawable.mogo_quanxi_lukou, "全息路口")),
false
)
}
deviceInPathList = arrayListOf(CrossDeviceBean("", 0.0, "", 0.0, deviceInPaths))
// 绘制路口设备
@@ -722,7 +774,7 @@ class TravelRealityView @JvmOverloads constructor(
roadRangeOptions.isUseTexture = true
roadRangeOptions.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound)
roadRangeOptions.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
roadRangeOptions.customTexture = roadTrajectoryBitmap
roadRangeOptions.customTexture = roadRangeBitmap
roadRangeList.forEach { pointList ->
pointList?.let {
@@ -739,21 +791,22 @@ class TravelRealityView @JvmOverloads constructor(
private fun handleRoadTrajectories(roadTrajectoryList: List<List<List<Double>?>?>?) {
if (roadTrajectoryList.isNullOrEmpty()) return
val globalList = reqData
// 绘制智慧道路范围
val roadTrajectoryOptionsList = ArrayList<PolylineOptions>()
val globalOptionList = ArrayList<PolylineOptions>()
val globalIndexSet = HashSet<Int>()
if (globalList.isNullOrEmpty()) {
if (globalList.isNullOrEmpty()) {// 无轨迹时以道路中心线为中轴画给定宽度的纹理
val boundsBuilder = LatLngBounds.Builder()
var latLngTmp: LatLng
roadTrajectoryList.forEach { trajectoryList ->
val options = PolylineOptions()
trajectoryList?.forEach loop@{ trajPointList ->
if (trajPointList.isNullOrEmpty() || trajPointList.size < 2) return@loop
options.width(AutoSizeUtils.dp2px(context, minRoadRange).toFloat())
options.width(AutoSizeUtils.dp2px(context, roadRange).toFloat())
options.isUseTexture = true
options.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound)
options.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
options.customTexture = roadTrajectoryBitmap
options.customTexture = roadRangeBitmap
latLngTmp = coordinateConverterWgsToGcj(
trajPointList[1],
trajPointList[0]
@@ -778,8 +831,8 @@ class TravelRealityView @JvmOverloads constructor(
} else {
roadTrajectoryList.forEach { trajectoryList ->
var distanceTmp: Double
var lastIndex = -1
var polylineOptionTmp: PolylineOptions? = null
// var lastIndex = -1
// var polylineOptionTmp: PolylineOptions? = null
trajectoryList?.forEachIndexed { index, trajPointList ->
if (trajPointList.isNullOrEmpty()) return@forEachIndexed
@@ -813,54 +866,54 @@ class TravelRealityView @JvmOverloads constructor(
if (distanceTmp < 50) {
Log.d(TAG, "智慧道路内点索引为:$i")
globalIndexSet.add(i)
if (lastIndex < 0 || index - lastIndex > 1) {
// 绘制新的智慧路段轨迹
polylineOptionTmp = PolylineOptions()
polylineOptionTmp?.let { optionTmp ->
buildPolylineOption(
optionTmp,
roadRange,
roadTrajectoryBitmap
)
optionTmp.add(
coordinateConverterWgsToGcj(
trajPointList[1],
trajPointList[0]
)
)
optionTmp.add(
coordinateConverterWgsToGcj(
trajectoryList[index + 1]!![1],
trajectoryList[index + 1]!![0]
)
)
// 待绘制多段智慧道路的轨迹线
roadTrajectoryOptionsList.add(optionTmp)
}
lastIndex = index + 1
} else if (index == lastIndex) {
polylineOptionTmp?.add(
coordinateConverterWgsToGcj(
trajectoryList[index + 1]!![1],
trajectoryList[index + 1]!![0]
)
)
lastIndex = index + 1
} else if (index - lastIndex == 1) {
polylineOptionTmp?.add(
coordinateConverterWgsToGcj(
trajPointList[1],
trajPointList[0]
)
)
polylineOptionTmp?.add(
coordinateConverterWgsToGcj(
trajectoryList[index + 1]!![1],
trajectoryList[index + 1]!![0]
)
)
lastIndex = index + 1
}
// if (lastIndex < 0 || index - lastIndex > 1) {
// // 绘制新的智慧路段轨迹
// polylineOptionTmp = PolylineOptions()
// polylineOptionTmp?.let { optionTmp ->
// buildPolylineOption(
// optionTmp,
// roadRange,
// roadRangeBitmap
// )
// optionTmp.add(
// coordinateConverterWgsToGcj(
// trajPointList[1],
// trajPointList[0]
// )
// )
// optionTmp.add(
// coordinateConverterWgsToGcj(
// trajectoryList[index + 1]!![1],
// trajectoryList[index + 1]!![0]
// )
// )
// // 待绘制多段智慧道路的轨迹线
// roadTrajectoryOptionsList.add(optionTmp)
// }
// lastIndex = index + 1
// } else if (index == lastIndex) {
// polylineOptionTmp?.add(
// coordinateConverterWgsToGcj(
// trajectoryList[index + 1]!![1],
// trajectoryList[index + 1]!![0]
// )
// )
// lastIndex = index + 1
// } else if (index - lastIndex == 1) {
// polylineOptionTmp?.add(
// coordinateConverterWgsToGcj(
// trajPointList[1],
// trajPointList[0]
// )
// )
// polylineOptionTmp?.add(
// coordinateConverterWgsToGcj(
// trajectoryList[index + 1]!![1],
// trajectoryList[index + 1]!![0]
// )
// )
// lastIndex = index + 1
// }
}
}
}
@@ -868,17 +921,29 @@ class TravelRealityView @JvmOverloads constructor(
}
var lastIndex = -1
var optionTmp: PolylineOptions? = null
var polylineOptionTmp: PolylineOptions? = null
globalList.forEachIndexed { index, point ->
if (!globalIndexSet.contains(index)) return@forEachIndexed
Log.w(TAG, "智慧道路内点索引为:$index")
if (lastIndex < 0 || index - lastIndex > 1) {
globalOptionList.add(PolylineOptions().also {
optionTmp = it
buildPolylineOptionWithColor(it, roadWidth, roadTrajectoryColor)
// 生成在智慧道路范围内的轨迹
buildPolylineOptionWithTexture(it, roadWidth, roadTrajectoryBitmap!!)
it.add(coordinateConverterWgsToGcj(point.lat, point.lon))
})
roadTrajectoryOptionsList.add(PolylineOptions().also {
polylineOptionTmp = it
buildPolylineOption(
polylineOptionTmp!!,
roadRange,
roadRangeBitmap!!
)
it.add(coordinateConverterWgsToGcj(point.lat, point.lon))
})
} else {
optionTmp?.add(coordinateConverterWgsToGcj(point.lat, point.lon))
polylineOptionTmp?.add(coordinateConverterWgsToGcj(point.lat, point.lon))
}
lastIndex = index
}
@@ -902,16 +967,16 @@ class TravelRealityView @JvmOverloads constructor(
optionTmp.customTexture = descriptor
}
private fun buildPolylineOptionWithColor(
private fun buildPolylineOptionWithTexture(
optionTmp: PolylineOptions,
width: Float,
color: Int
descriptor: BitmapDescriptor
) {
optionTmp.width(AutoSizeUtils.dp2px(context, width).toFloat())
optionTmp.isUseTexture = false
optionTmp.isUseTexture = true
optionTmp.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound)
optionTmp.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
optionTmp.color(color)
optionTmp.customTexture = descriptor
}
private fun drawCarMarker(location: MogoLocation) {
@@ -1021,18 +1086,21 @@ class TravelRealityView @JvmOverloads constructor(
})
// 获取道路事件
val cityCode = CallerMapUIServiceManager.getCityCode() ?: "0734"
travelNetWorkModel.getEventsWithTrajRequest(EventReqEntity(pointList, cityCode), onSuccess = {
Log.d(TAG, "Events result is:$it")
handleRoadEvent(it)
}, onError = {
Log.d(TAG, "Events error is:$it")
})
travelNetWorkModel.getEventsWithTrajRequest(
EventReqEntity(pointList, cityCode),
onSuccess = {
Log.d(TAG, "Events result is:$it")
handleRoadEvent(it)
},
onError = {
Log.d(TAG, "Events error is:$it")
})
if (!isRoadTrackReq) {
handleRoadTrajectories(roadTrackList)
}
}
}
interface OnDrawListener {
// isEvent为true表示是事件反之则表示全息路口
fun onDraw(eventList: List<EventDrawBean>, isEvent: Boolean)

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

View File

@@ -60,6 +60,8 @@
<attr name="compassDrawable" />
<!-- 智慧道路范围纹理 -->
<attr name="roadRangeDrawable" format="reference" />
<!-- 带箭头的轨迹线纹理 -->
<attr name="roadTrajectoryDrawable" format="reference" />
<attr name="globalPathColor" format="color" />
<attr name="roadTrajectoryColor" format="color" />
<!-- 起点图片 -->