From 6bf6a2347ffa3db43e45268fdb5a3a209d634e35 Mon Sep 17 00:00:00 2001 From: chenfufeng Date: Tue, 23 Jul 2024 16:27:29 +0800 Subject: [PATCH] =?UTF-8?q?[6.5.0][Fix]=E8=A7=A3=E5=86=B3=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=BB=93=E6=9D=9F=E5=90=8E=E5=8D=A1=E7=89=87=E6=9C=AA?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../travelreality/TravelRealityModel.kt | 165 +++++++++++++++--- .../core/function/view/TravelRealityView.kt | 18 +- 2 files changed, 156 insertions(+), 27 deletions(-) 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 a08518983c..7697a45bf1 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 @@ -2,6 +2,7 @@ package com.mogo.eagle.core.function.business.travelreality import android.content.Context import android.graphics.Bitmap +import android.graphics.Point import android.graphics.drawable.Drawable import android.util.Log import com.amap.api.maps.model.LatLng @@ -35,10 +36,13 @@ class TravelRealityModel private constructor() { @Volatile private var eventKey = "" + @Volatile private var deviceKey = "" + @Volatile private var trackKey = "" + @Volatile private var liveKey = "" @@ -56,22 +60,28 @@ class TravelRealityModel private constructor() { /** * 查询道路事件 */ - fun getEventsWithTrajRequest(reqData: EventReqEntity, - onSuccess: ((List) -> Unit), onError: ((String) -> Unit)){ + fun getEventsWithTrajRequest( + reqData: EventReqEntity, + onSuccess: ((List) -> Unit), onError: ((String) -> Unit) + ) { eventKey = "getEvents_${System.currentTimeMillis()}" request?>>(eventKey) { loader { - apiResponseCall{ + apiResponseCall { val time = System.currentTimeMillis().toString() val md5String = "${ROAD_EVENT_TRAJECTORY.uppercase(Locale.getDefault())}$time" Log.d("TravelRealityModel", "查询道路事件轨迹点个数为:${reqData.points.size}") - getNetWorkApi(HostConst.getNDEHost()).getEventsWithTrajRequest(Md5Util.getMD5Result(md5String), time, reqData) + getNetWorkApi(HostConst.getNDEHost()).getEventsWithTrajRequest( + Md5Util.getMD5Result( + md5String + ), time, reqData + ) } } onSuccess { onSuccess.invoke(it.data ?: ArrayList()) } - onError{ + onError { onError.invoke(it.message ?: "") } } @@ -84,7 +94,7 @@ class TravelRealityModel private constructor() { deviceKey = "getDevice_${System.currentTimeMillis()}" request?>>(deviceKey) { loader { - apiCall{ + apiCall { val time = System.currentTimeMillis().toString() val md5String = "${CROSS_DEVICE.uppercase(Locale.getDefault())}$time" val loc = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() @@ -92,13 +102,17 @@ class TravelRealityModel private constructor() { if (cityCode.isEmpty()) { cityCode = "0734" } - getNetWorkApi(HostConst.getNDEHost()).getCrossDevice(Md5Util.getMD5Result(md5String), time, "", loc.longitude, loc.latitude, cityCode) + getNetWorkApi(HostConst.getNDEHost()).getCrossDevice( + Md5Util.getMD5Result( + md5String + ), time, "", loc.longitude, loc.latitude, cityCode + ) } } onSuccess { onSuccess.invoke(it.result ?: ArrayList()) } - onError{ + onError { onError.invoke(it.message ?: "") } } @@ -117,15 +131,16 @@ class TravelRealityModel private constructor() { if (liveKey.isNotEmpty()) { cancel(liveKey) } + cancelDownload() } /** * 智慧路口路网范围 */ fun getCityRoadRange(onSuccess: ((List?>?) -> Unit), onError: ((String) -> Unit)) { - request?>?>>{ + request?>?>> { loader { - apiCall{ + apiCall { val time = System.currentTimeMillis().toString() val md5String = "${CITY_ROAD_RANGE.uppercase(Locale.getDefault())}$time" val loc = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() @@ -133,13 +148,17 @@ class TravelRealityModel private constructor() { if (cityCode.isEmpty()) { cityCode = "0734" } - getNetWorkApi(HostConst.getNDEHost()).getCityRoadRange(Md5Util.getMD5Result(md5String), time, loc.longitude, loc.latitude, cityCode) + getNetWorkApi(HostConst.getNDEHost()).getCityRoadRange( + Md5Util.getMD5Result( + md5String + ), time, loc.longitude, loc.latitude, cityCode + ) } } onSuccess { onSuccess.invoke(it.result) } - onError{ + onError { onError.invoke(it.message ?: "") } } @@ -148,11 +167,14 @@ class TravelRealityModel private constructor() { /** * 智慧道路轨迹 */ - fun getCityRoadTrack(onSuccess: ((List?>?>?) -> Unit), onError: ((String) -> Unit)) { + fun getCityRoadTrack( + onSuccess: ((List?>?>?) -> Unit), + onError: ((String) -> Unit) + ) { trackKey = "getTrack_${System.currentTimeMillis()}" request?>?>?>>(trackKey) { loader { - apiCall{ + apiCall { val time = System.currentTimeMillis().toString() val md5String = "${CITY_ROAD_TRACK.uppercase(Locale.getDefault())}$time" val loc = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() @@ -160,13 +182,17 @@ class TravelRealityModel private constructor() { if (cityCode.isEmpty()) { cityCode = "0734" } - getNetWorkApi(HostConst.getNDEHost()).getCityRoadTrack(Md5Util.getMD5Result(md5String), time, loc.longitude, loc.latitude, cityCode) + getNetWorkApi(HostConst.getNDEHost()).getCityRoadTrack( + Md5Util.getMD5Result( + md5String + ), time, loc.longitude, loc.latitude, cityCode + ) } } onSuccess { onSuccess.invoke(it.result) } - onError{ + onError { onError.invoke(it.message ?: "") } } @@ -194,7 +220,8 @@ class TravelRealityModel private constructor() { ) val md5String = "/${BATCH_LIVE.uppercase(Locale.getDefault())}$time" MoGoRetrofitFactory.getInstanceNoCallAdapter(HostConst.getNDEHost()) - .create(INDERoadCameraApiService::class.java).cameraLiveBatchRequest(Md5Util.getMD5Result(md5String), time, map) + .create(INDERoadCameraApiService::class.java) + .cameraLiveBatchRequest(Md5Util.getMD5Result(md5String), time, map) } } onSuccess { @@ -206,18 +233,18 @@ class TravelRealityModel private constructor() { } } - fun downloadImage(context: Context, url: String?, - latLng: LatLng, - onSuccess: ((Bitmap, LatLng) -> Unit), - onFailed: ((LatLng) -> Unit) + fun downloadImage( + context: Context, url: String?, + latLng: LatLng, + onSuccess: ((Bitmap, LatLng) -> Unit), + onFailed: ((LatLng) -> Unit) ) { if (url.isNullOrEmpty()) return val radiusPx = AutoSizeUtils.dp2px(context, 24f).toFloat() val options = RequestOptions().transform( - GranularRoundedCorners(radiusPx, radiusPx,0f,0f) + GranularRoundedCorners(radiusPx, radiusPx, 0f, 0f) ) - Glide.with(context) - .asBitmap() + Glide.with(context).asBitmap() .apply(options) .load(url) .into(object : CustomTarget() { @@ -234,11 +261,22 @@ class TravelRealityModel private constructor() { }) } + private fun cancelDownload() { + + } + /** * 计算Marker相对最近线段ab应该摆放的位置 * 0:左,1:上,2:右,3:下 */ - fun calculateOrientation(pLon: Double, pLat: Double, aLon: Double, aLat: Double, bLon: Double, bLat: Double): Int { + fun calculateOrientation( + pLon: Double, + pLat: Double, + aLon: Double, + aLat: Double, + bLon: Double, + bLat: Double + ): Int { // 0:左,1:上,2:右,3:下 var orientation = 0 // 线段与正北方向的夹角,范围[0,360] @@ -260,6 +298,7 @@ class TravelRealityModel private constructor() { 1 } } + 2 -> { orientation = if (abAngle > 180) { 1 @@ -267,6 +306,7 @@ class TravelRealityModel private constructor() { 3 } } + else -> {// 点p在线段ab所在的直线上 orientation = 1// 未计算后面线段,写死上方 } @@ -293,6 +333,7 @@ class TravelRealityModel private constructor() { } } } + 2 -> {// 顺时针方向为右侧 orientation = when { abAngle in 0.0..90.0 -> { @@ -312,6 +353,7 @@ class TravelRealityModel private constructor() { } } } + else -> {// 点p在线段ab所在的直线上 orientation = 0// 未计算后面线段,写死左侧 } @@ -363,4 +405,77 @@ class TravelRealityModel private constructor() { } } } + + fun calculateVertex(context: Context, orientation: Int, point: Point): List { + val anchorPair = calculateAnchor(orientation) + val pointList = ArrayList() + var width = 0 + var height = 0 + if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) { + when (orientation) { + 0 -> {// 内容居左,箭头朝右 + width = AutoSizeUtils.dp2px(context, 390f) + height = AutoSizeUtils.dp2px(context, 320f) + } + + 1 -> { + width = AutoSizeUtils.dp2px(context, 320f) + height = AutoSizeUtils.dp2px(context, 390f) + } + + 2 -> { + width = AutoSizeUtils.dp2px(context, 390f) + height = AutoSizeUtils.dp2px(context, 320f) + } + + else -> { + width = AutoSizeUtils.dp2px(context, 320f) + height = AutoSizeUtils.dp2px(context, 390f) + } + } + } else { + when (orientation) { + 0 -> {// 内容居左,箭头朝右 + width = AutoSizeUtils.dp2px(context, 396f) + height = AutoSizeUtils.dp2px(context, 324f) + } + + 1 -> { + width = AutoSizeUtils.dp2px(context, 324f) + height = AutoSizeUtils.dp2px(context, 396f) + } + + 2 -> { + width = AutoSizeUtils.dp2px(context, 396f) + height = AutoSizeUtils.dp2px(context, 324f) + } + + else -> { + width = AutoSizeUtils.dp2px(context, 324f) + height = AutoSizeUtils.dp2px(context, 396f) + } + } + } + var leftTopP: Point = 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() + rightTopP.x = (leftTopP.x + width + 0.5).toInt() + rightTopP.y = leftTopP.y + + var leftBottomP: Point = Point() + leftBottomP.x = leftTopP.x + leftBottomP.y = (leftTopP.y + height + 0.5).toInt() + + var rightBottomP: Point = Point() + rightBottomP.x = (leftTopP.x + width + 0.5).toInt() + rightBottomP.y = (leftTopP.y + height + 0.5).toInt() + + pointList.add(leftTopP) + pointList.add(rightTopP) + pointList.add(leftBottomP) + pointList.add(rightBottomP) + return pointList + } } \ No newline at end of file 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 6d74725598..f9ec3211ab 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 @@ -275,6 +275,10 @@ class TravelRealityView @JvmOverloads constructor( * 清除所有Marker和Polyline */ fun clearAllMarkersAndPolyline() { + Log.d(TAG, "clearAllMarkersAndPolyline") + nonFrequentHandler?.removeCallbacksAndMessages(null) + travelNetWorkModel.cancelAllRequest() + retryCount = 0 // 清除之前的所有Marker Message.obtain().apply { what = CLEAR_ALL_DATA @@ -393,6 +397,7 @@ class TravelRealityView @JvmOverloads constructor( CallerPlanningRottingListenerManager.removeListener("${TAG}${this.hashCode()}") nonFrequentHandler?.looper?.quitSafely() nonFrequentHandler = null + travelNetWorkModel.cancelAllRequest() } private fun initHandlers() { @@ -1111,8 +1116,6 @@ class TravelRealityView @JvmOverloads constructor( Log.d(TAG, "下发全局轨迹!") globalPathResp?.let { globalPath -> // nonFrequentHandler?.removeCallbacksAndMessages(null) - Log.d(TAG, "取消之前的网络请求!") - travelNetWorkModel.cancelAllRequest() val pointList = ArrayList() globalPath.wayPointsList.forEach { loc -> @@ -1169,6 +1172,17 @@ class TravelRealityView @JvmOverloads constructor( } } + private fun getRectVertex(orientation: Int, latLng: LatLng) { + if (mAMap != null && mAMap!!.projection != null) { + + val point = mAMap!!.projection!!.toScreenLocation(latLng) + point?.let { + val pointList = travelNetWorkModel.calculateVertex(context, orientation, it) + + } + } + } + interface OnDrawListener { // isEvent为true表示是事件,反之则表示全息路口 fun onDraw(eventList: List, isEvent: Boolean)