diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt index 7697a45bf1..3144c5c464 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/business/travelreality/TravelRealityModel.kt @@ -406,6 +406,9 @@ class TravelRealityModel private constructor() { } } + /** + * 根据卡片朝向和卡片定位计算四个顶点的屏幕坐标 + */ fun calculateVertex(context: Context, orientation: Int, point: Point): List { val anchorPair = calculateAnchor(orientation) val pointList = ArrayList() @@ -414,61 +417,61 @@ class TravelRealityModel private constructor() { if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) { when (orientation) { 0 -> {// 内容居左,箭头朝右 - width = AutoSizeUtils.dp2px(context, 390f) - height = AutoSizeUtils.dp2px(context, 320f) + width = AutoSizeUtils.dp2px(context, 420f) + height = AutoSizeUtils.dp2px(context, 350f) } 1 -> { - width = AutoSizeUtils.dp2px(context, 320f) - height = AutoSizeUtils.dp2px(context, 390f) + width = AutoSizeUtils.dp2px(context, 350f) + height = AutoSizeUtils.dp2px(context, 420f) } 2 -> { - width = AutoSizeUtils.dp2px(context, 390f) - height = AutoSizeUtils.dp2px(context, 320f) + width = AutoSizeUtils.dp2px(context, 420f) + height = AutoSizeUtils.dp2px(context, 350f) } else -> { - width = AutoSizeUtils.dp2px(context, 320f) - height = AutoSizeUtils.dp2px(context, 390f) + width = AutoSizeUtils.dp2px(context, 350f) + height = AutoSizeUtils.dp2px(context, 420f) } } } else { when (orientation) { 0 -> {// 内容居左,箭头朝右 - width = AutoSizeUtils.dp2px(context, 396f) - height = AutoSizeUtils.dp2px(context, 324f) + width = AutoSizeUtils.dp2px(context, 426f) + height = AutoSizeUtils.dp2px(context, 354f) } 1 -> { - width = AutoSizeUtils.dp2px(context, 324f) - height = AutoSizeUtils.dp2px(context, 396f) + width = AutoSizeUtils.dp2px(context, 354f) + height = AutoSizeUtils.dp2px(context, 426f) } 2 -> { - width = AutoSizeUtils.dp2px(context, 396f) - height = AutoSizeUtils.dp2px(context, 324f) + width = AutoSizeUtils.dp2px(context, 426f) + height = AutoSizeUtils.dp2px(context, 354f) } else -> { - width = AutoSizeUtils.dp2px(context, 324f) - height = AutoSizeUtils.dp2px(context, 396f) + width = AutoSizeUtils.dp2px(context, 354f) + height = AutoSizeUtils.dp2px(context, 426f) } } } - var leftTopP: Point = Point() + var leftTopP = Point() leftTopP.x = (point.x - width * anchorPair.first + 0.5).toInt() leftTopP.y = (point.y - height * anchorPair.second + 0.5).toInt() - var rightTopP: Point = Point() + var rightTopP = Point() rightTopP.x = (leftTopP.x + width + 0.5).toInt() rightTopP.y = leftTopP.y - var leftBottomP: Point = Point() + var leftBottomP = Point() leftBottomP.x = leftTopP.x leftBottomP.y = (leftTopP.y + height + 0.5).toInt() - var rightBottomP: Point = Point() + var rightBottomP = Point() rightBottomP.x = (leftTopP.x + width + 0.5).toInt() rightBottomP.y = (leftTopP.y + height + 0.5).toInt() 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 f9ec3211ab..33f90264fe 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 @@ -76,7 +76,7 @@ class TravelRealityView @JvmOverloads constructor( private const val DRAW_END_MARKER = 10 private const val UPDATE_VIDEO_MARKER = 11 -// private const val CLEAR_POLY_LINE = 12 + // private const val CLEAR_POLY_LINE = 12 // private const val CLEAR_ROAD_EVENT = 13 // private const val CLEAR_CROSS_DEVICE = 14 // private const val CLEAR_ROAD_TRAJECTORY = 15 @@ -278,6 +278,7 @@ class TravelRealityView @JvmOverloads constructor( Log.d(TAG, "clearAllMarkersAndPolyline") nonFrequentHandler?.removeCallbacksAndMessages(null) travelNetWorkModel.cancelAllRequest() + reqData = null retryCount = 0 // 清除之前的所有Marker Message.obtain().apply { @@ -741,9 +742,12 @@ class TravelRealityView @JvmOverloads constructor( ) { Log.d(TAG, "请求获取缩略图,个数为:${ipList.size}!") travelNetWorkModel.batchRequestCrossLive(ipList, onSuccess = { + Log.d(TAG, "Cross live result is:$it") val liveOptionsList = ArrayList() var markerOption: MarkerOptions var pair: Pair + val vertexList = ArrayList() + it.forEach { roadCamera -> roadCamera.ip?.let { ip -> markerOption = MarkerOptions() @@ -751,6 +755,15 @@ class TravelRealityView @JvmOverloads constructor( if (roadCamera.imageUrl.isNullOrEmpty()) { var view: EventVideoView if (ipPointEntityMap[ip] != null) { + // 计算卡片四个顶点的高德地图经纬度 + ipPointEntityMap[ip]?.latLng?.let { pos -> + vertexList.addAll( + getRectVertex( + ipPointEntityMap[ip]!!.orientation, + pos + ) + ) + } markerOption.position(ipPointEntityMap[ip]?.latLng) view = EventVideoView( context, @@ -772,6 +785,15 @@ class TravelRealityView @JvmOverloads constructor( } else { // 需要下载缩略图 markerOption.icon(null) + // 计算卡片四个顶点的高德地图经纬度 + ipPointEntityMap[ip]?.latLng?.let { pos -> + vertexList.addAll( + getRectVertex( + ipPointEntityMap[ip]?.orientation ?: 0, + pos + ) + ) + } markerOption.position(ipPointEntityMap[ip]?.latLng) pair = travelNetWorkModel.calculateAnchor( ipPointEntityMap[ip]?.orientation ?: 0 @@ -789,7 +811,7 @@ class TravelRealityView @JvmOverloads constructor( } // 绘制事件卡片 drawMarkers(DRAW_LIVE_DETAIL, liveOptionsList) - Log.d(TAG, "Cross live result is:$it") + adjustCameraWithVertex(vertexList) }, onError = { Log.d(TAG, "Cross live error is:$it") }) @@ -1000,6 +1022,31 @@ class TravelRealityView @JvmOverloads constructor( drawPolylineList(DRAW_ROAD_TRAJECTORY, roadTrajectoryOptionsList) } + /** + * 调整视角以显示出卡片 + */ + private fun adjustCameraWithVertex(vertexLngList: List) { + val boundsBuilder = LatLngBounds.Builder() + vertexLngList.forEach { + boundsBuilder.include(it) + } + reqData?.forEach { + boundsBuilder.include(coordinateConverterWgsToGcj(it.lat, it.lon)) + } + if (mLocation != null) { + boundsBuilder.include(LatLng(mLocation!!.latitude, mLocation!!.longitude)) + } + + val cameraUpdate = CameraUpdateFactory.newLatLngBoundsRect( + boundsBuilder.build(), + AutoSizeUtils.dp2px(context, leftPadding.toFloat()), + AutoSizeUtils.dp2px(context, rightPadding.toFloat()), + AutoSizeUtils.dp2px(context, topPadding.toFloat()), + AutoSizeUtils.dp2px(context, bottomPadding.toFloat()) + ) + moveMapCamera(cameraUpdate) + } + private fun buildPolylineOption( optionTmp: PolylineOptions, width: Float, @@ -1172,15 +1219,27 @@ class TravelRealityView @JvmOverloads constructor( } } - private fun getRectVertex(orientation: Int, latLng: LatLng) { + /** + * 根据Marker朝向和坐标计算每个顶点在高德地图中的经纬度 + */ + private fun getRectVertex(orientation: Int, position: LatLng): List { + // 矩形顶点在高德地图中的坐标 + val latLngList = ArrayList() if (mAMap != null && mAMap!!.projection != null) { - - val point = mAMap!!.projection!!.toScreenLocation(latLng) + var latLng: LatLng? + // 经纬度转屏幕坐标 + var point = mAMap!!.projection!!.toScreenLocation(position) point?.let { - val pointList = travelNetWorkModel.calculateVertex(context, orientation, it) - + travelNetWorkModel.calculateVertex(context, orientation, it).forEach { screenP -> + // 每个顶点屏幕坐标转高德坐标 + latLng = mAMap!!.projection!!.fromScreenLocation(screenP) + if (latLng != null) { + latLngList.add(latLng!!) + } + } } } + return latLngList } interface OnDrawListener {