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 632d89133c..d42452e123 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 @@ -3,6 +3,8 @@ package com.mogo.eagle.core.function.business.travelreality import com.mogo.commons.constants.HostConst import com.mogo.eagle.core.data.BaseResponse import com.mogo.eagle.core.data.Response +import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager +import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager import com.mogo.eagle.core.network.MoGoRetrofitFactory import com.mogo.eagle.core.network.apiCall import com.mogo.eagle.core.network.apiResponseCall @@ -50,14 +52,15 @@ class TravelRealityModel private constructor() { /** * 查询路口设备 */ - fun getCrossDevice(lon: Double, lat: Double, cityCode: String?, - onSuccess: ((List) -> Unit), onError: ((String) -> Unit)) { + fun getCrossDevice(onSuccess: ((List) -> Unit), onError: ((String) -> Unit)) { request?>>{ loader { apiCall{ val time = System.currentTimeMillis().toString() val md5String = "${CROSS_DEVICE.uppercase(Locale.getDefault())}$time" - getNetWorkApi(HostConst.getNDEHost()).getCrossDevice(Md5Util.getMD5Result(md5String), time, "", lon, lat, cityCode) + val loc = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() + val cityCode = CallerMapUIServiceManager.getCityCode() ?: "0734" + getNetWorkApi(HostConst.getNDEHost()).getCrossDevice(Md5Util.getMD5Result(md5String), time, "", loc.longitude, loc.latitude, "0734") } } onSuccess { @@ -72,14 +75,15 @@ class TravelRealityModel private constructor() { /** * 智慧路口路网范围 */ - fun getCityRoadRange(lon: Double, lat: Double, cityCode: String?, - onSuccess: ((List?>?) -> Unit), onError: ((String) -> Unit)) { + fun getCityRoadRange(onSuccess: ((List?>?) -> Unit), onError: ((String) -> Unit)) { request?>?>>{ loader { apiCall{ val time = System.currentTimeMillis().toString() val md5String = "${CITY_ROAD_RANGE.uppercase(Locale.getDefault())}$time" - getNetWorkApi(HostConst.getNDEHost()).getCityRoadRange(Md5Util.getMD5Result(md5String), time, lon, lat, cityCode) + val loc = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() + val cityCode = CallerMapUIServiceManager.getCityCode() ?: "0734" + getNetWorkApi(HostConst.getNDEHost()).getCityRoadRange(Md5Util.getMD5Result(md5String), time, loc.longitude, loc.latitude, "0734") } } onSuccess { @@ -94,14 +98,15 @@ class TravelRealityModel private constructor() { /** * 智慧道路轨迹 */ - fun getCityRoadTrack(lon: Double, lat: Double, cityCode: String?, - onSuccess: ((List?>?>?) -> Unit), onError: ((String) -> Unit)) { + fun getCityRoadTrack(onSuccess: ((List?>?>?) -> Unit), onError: ((String) -> Unit)) { request?>?>?>>{ loader { apiCall{ val time = System.currentTimeMillis().toString() val md5String = "${CITY_ROAD_TRACK.uppercase(Locale.getDefault())}$time" - getNetWorkApi(HostConst.getNDEHost()).getCityRoadTrack(Md5Util.getMD5Result(md5String), time, lon, lat, cityCode) + val loc = CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84() + val cityCode = CallerMapUIServiceManager.getCityCode() ?: "0734" + getNetWorkApi(HostConst.getNDEHost()).getCityRoadTrack(Md5Util.getMD5Result(md5String), time, loc.longitude, loc.latitude, "0734") } } onSuccess { 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 4155ea76b0..911edc3f90 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 @@ -12,7 +12,6 @@ import android.os.Message import android.util.AttributeSet import android.util.Log import android.view.LayoutInflater -import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import com.amap.api.maps.AMap import com.amap.api.maps.CameraUpdate @@ -21,16 +20,17 @@ import com.amap.api.maps.CoordinateConverter import com.amap.api.maps.TextureMapView import com.amap.api.maps.model.BitmapDescriptor import com.amap.api.maps.model.BitmapDescriptorFactory -import com.amap.api.maps.model.CameraPosition import com.amap.api.maps.model.CustomMapStyleOptions import com.amap.api.maps.model.LatLng import com.amap.api.maps.model.LatLngBounds +import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.Polyline import com.amap.api.maps.model.PolylineOptions -import com.google.gson.reflect.TypeToken import com.mogo.eagle.core.data.map.MogoLocation import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener import com.mogo.eagle.core.function.api.autopilot.IMoGoPlanningRottingListener +import com.mogo.eagle.core.function.business.roadcross.net.NDERoadCameraNetWorkModel.Companion.ndeRoadCameraNetWorkModel import com.mogo.eagle.core.function.business.travelreality.CrossDeviceBean import com.mogo.eagle.core.function.business.travelreality.EventBean import com.mogo.eagle.core.function.business.travelreality.Point @@ -38,11 +38,10 @@ import com.mogo.eagle.core.function.business.travelreality.TravelRealityModel.Co import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager import com.mogo.eagle.core.function.call.autopilot.CallerPlanningRottingListenerManager import com.mogo.eagle.core.function.map.R +import com.mogo.eagle.core.function.smp.V2XMarkerView import com.mogo.eagle.core.utilcode.mogo.MapAssetStyleUtils -import com.mogo.eagle.core.utilcode.util.DrivingDirectionUtils -import com.mogo.eagle.core.utilcode.util.GsonUtils import com.mogo.eagle.core.utilcode.util.LocationUtils -import com.mogo.eagle.core.utilcode.util.ToastUtils +import com.mogo.eagle.core.utilcode.util.ThreadUtils import me.jessyan.autosize.utils.AutoSizeUtils import mogo.telematics.pad.MessagePad @@ -62,6 +61,33 @@ class TravelRealityView @JvmOverloads constructor( private var mMapView: TextureMapView? = null private var mAMap: AMap? = null + private var mCarMarker: Marker? = null + private var mCompassMarker: Marker? = null + + private var globalPolyline: Polyline? = null + private val eventMarkerList by lazy { + ArrayList() + } + private val deviceMarkerList by lazy { + ArrayList() + } + private val liveMarkerList by lazy { + ArrayList() + } + private val trajectoryPolylineList by lazy { + ArrayList() + } + private val globalPolylineList by lazy { + ArrayList() + } + private var mStartMarker: Marker? = null + private var mEndMarker: Marker? = null + + @Volatile + private var mLocation: MogoLocation? = null + + @Volatile + private var isMapLoaded = false // =============自定义属性相关============= private var mapStylePath: String? = null @@ -73,16 +99,18 @@ class TravelRealityView @JvmOverloads constructor( private var leftPadding: Int = 100 private var topPadding: Int = 150 private var rightPadding: Int = 100 - private var bottomPadding: Int = 250 + private var bottomPadding: Int = 300 private var roadRangeBitmap: BitmapDescriptor? = null 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) } - // 测试时使用 +// // 测试时使用 // private val pointBitmap1 by lazy { // BitmapDescriptorFactory.fromBitmap(getBitmap1()) // } @@ -107,7 +135,25 @@ class TravelRealityView @JvmOverloads constructor( @Volatile private var lastTime = 0L + @Volatile private var reqData: List? = null + private var retryCount = 0 + + @Volatile + private var deviceList: List? = null + + @Volatile + private var roadTrackList: List?>?>? = null + + @Volatile + private var isRoadTrackReq = false + + private val roadEventList by lazy { + ArrayList() + } + private val ipPointMap by lazy { + HashMap() + } private var testTime = 0L @@ -120,6 +166,10 @@ class TravelRealityView @JvmOverloads constructor( private const val DRAW_CROSS_DEVICE = 4 private const val DRAW_ROAD_RANGE = 5 private const val DRAW_ROAD_TRAJECTORY = 6 + private const val DRAW_GLOBAL_TRAJECTORY = 7 + private const val MOVE_MAP_CAMERA = 8 + private const val DRAW_LIVE_DETAIL = 9 + private const val DRAW_END_MARKER = 10 } init { @@ -133,6 +183,14 @@ class TravelRealityView @JvmOverloads constructor( typedArray.getResourceId(R.styleable.TravelRealityView_compassDrawable, -1) roadRangeDrawable = typedArray.getResourceId(R.styleable.TravelRealityView_roadRangeDrawable, -1) + globalPathColor = typedArray.getInt( + R.styleable.TravelRealityView_globalPathColor, + Color.parseColor("#49DEAE") + ) + roadTrajectoryColor = typedArray.getInt( + R.styleable.TravelRealityView_roadTrajectoryColor, + Color.parseColor("#0FB2D8") + ) startPointDrawable = typedArray.getResourceId(R.styleable.TravelRealityView_startPointDrawable, -1) endPointDrawable = @@ -206,24 +264,26 @@ class TravelRealityView @JvmOverloads constructor( mAMap?.moveCamera(CameraUpdateFactory.zoomTo(14f)) //设置地图的样式 mAMap?.uiSettings?.let { - //地图缩放级别的交换按钮 - it.isZoomControlsEnabled = true //所有手势 it.setAllGesturesEnabled(true) + //地图缩放级别的交换按钮 + it.isZoomControlsEnabled = false + it.isZoomGesturesEnabled = false //指南针 it.isCompassEnabled = false //设置倾斜手势是否可用。 it.isTiltGesturesEnabled = false //定位按钮 - it.isMyLocationButtonEnabled = true + it.isMyLocationButtonEnabled = false } mAMap?.setOnMapLoadedListener { + isMapLoaded = true mAMap?.setCustomMapStyle(mapStyleOptions) // 实时路况图层关闭,必须添加在loaded结束之后,其他位置不生效 mAMap?.isTrafficEnabled = false mAMap?.showBuildings(false) -// mAMap?.uiSettings?.isZoomControlsEnabled = false + mAMap?.uiSettings?.isZoomControlsEnabled = false // mAMap?.animateCamera(CameraUpdateFactory.changeTilt(30f)) } } @@ -234,10 +294,14 @@ class TravelRealityView @JvmOverloads constructor( // 注册定位监听 CallerChassisLocationGCJ02ListenerManager.addListener(TAG, this) initHandlers() + advanceRequest() } override fun onDetachedFromWindow() { super.onDetachedFromWindow() + isMapLoaded = false + deviceList = null + retryCount = 0 // 注册定位监听 CallerChassisLocationGCJ02ListenerManager.removeListener(TAG) CallerPlanningRottingListenerManager.removeListener(TAG) @@ -251,137 +315,18 @@ class TravelRealityView @JvmOverloads constructor( nonFrequentHandler = NonFrequentHandler(nonFrequentThread.looper) } - private fun reqTrajectoryTest() { - val json = - "[{\"lat\":26.81937733437377,\"lon\":112.57535281567407},{\"lat\":26.81945931447823,\"lon\":112.57532226983858}," + - "{\"lat\":26.820654610710495,\"lon\":112.5747724572884},{\"lat\":26.82123411157205,\"lon\":112.57446700543453}," + - "{\"lat\":26.82192608026401,\"lon\":112.5741080926201},{\"lat\":26.822091924747422,\"lon\":112.57402409051497}," + - "{\"lat\":26.82217198311328,\"lon\":112.57397827179898},{\"lat\":26.822751478727742,\"lon\":112.57368044319112}," + - "{\"lat\":26.823003074132348,\"lon\":112.57352007651988},{\"lat\":26.82327753332255,\"lon\":112.57333679968579}," + - "{\"lat\":26.823437581007436,\"lon\":112.57316880115862},{\"lat\":26.82353473462254,\"lon\":112.57304662092753}," + - "{\"lat\":26.823599481049378,\"lon\":112.57293971409484},{\"lat\":26.82373275263248,\"lon\":112.57268771854648}," + - "{\"lat\":26.823812678691333,\"lon\":112.57249681223165},{\"lat\":26.823863914316153,\"lon\":112.57221427243014}," + - "{\"lat\":26.823863543155838,\"lon\":112.57180955163894},{\"lat\":26.823848051950634,\"lon\":112.57155755260963}," + - "{\"lat\":26.82376752893978,\"lon\":112.57110700477688},{\"lat\":26.82321958288029,\"lon\":112.5686097226906}," + - "{\"lat\":26.82319656741949,\"lon\":112.56848752320151},{\"lat\":26.82317357600292,\"lon\":112.56838823588228}," + - "{\"lat\":26.822583129427166,\"lon\":112.56568437427828},{\"lat\":26.822567763188122,\"lon\":112.56559271125079}," + - "{\"lat\":26.822567763188122,\"lon\":112.56559271125079},{\"lat\":26.822613311780497,\"lon\":112.56540937833189}," + - "{\"lat\":26.822778835723827,\"lon\":112.56508853541045},{\"lat\":26.822778835723827,\"lon\":112.56508853541045}," + - "{\"lat\":26.82335830821441,\"lon\":112.56486696378353},{\"lat\":26.825073836123234,\"lon\":112.5642098752998}," + - "{\"lat\":26.82587831132585,\"lon\":112.56397299890796},{\"lat\":26.826602716871196,\"lon\":112.56375904383397}," + - "{\"lat\":26.826757011379495,\"lon\":112.56362152304669},{\"lat\":26.826757011379495,\"lon\":112.56362152304669}," + - "{\"lat\":26.826665118069972,\"lon\":112.56334650820811},{\"lat\":26.826515909977296,\"lon\":112.56299509732794}," + - "{\"lat\":26.826273047969202,\"lon\":112.56249089072236},{\"lat\":26.825741353462305,\"lon\":112.56136019981324}," + - "{\"lat\":26.825545885183946,\"lon\":112.5606802184245},{\"lat\":26.825515221290765,\"lon\":112.56057325303}," + - "{\"lat\":26.82537828319818,\"lon\":112.55950355643967},{\"lat\":26.825358966712418,\"lon\":112.55933545613247}," + - "{\"lat\":26.82533550731808,\"lon\":112.55894576231651},{\"lat\":26.825329684542123,\"lon\":112.55761615913678}," + - "{\"lat\":26.82531512968552,\"lon\":112.555644526428},{\"lat\":26.825332951146304,\"lon\":112.55488027750438}," + - "{\"lat\":26.825332951146304,\"lon\":112.55488027750438},{\"lat\":26.825582749368,\"lon\":112.55486497384544}," + - "{\"lat\":26.832195779849293,\"lon\":112.55566694572363},{\"lat\":26.83305984045991,\"lon\":112.55577387436938}," + - "{\"lat\":26.833412716051612,\"lon\":112.55581970205667},{\"lat\":26.833983005722352,\"lon\":112.55587315586395}," + - "{\"lat\":26.834465509986607,\"lon\":112.55588840477134},{\"lat\":26.83493085073919,\"lon\":112.55590365493417}," + - "{\"lat\":26.835735483067072,\"lon\":112.55581953062685},{\"lat\":26.83602718493831,\"lon\":112.55577365536547}," + - "{\"lat\":26.837897224427703,\"lon\":112.55530733220453},{\"lat\":26.840266626992527,\"lon\":112.55468046640051}," + - "{\"lat\":26.842555914048862,\"lon\":112.5540535884595},{\"lat\":26.842969582911035,\"lon\":112.55396184290737}," + - "{\"lat\":26.84317738357361,\"lon\":112.55392361286312},{\"lat\":26.843375636130915,\"lon\":112.55387774049657}," + - "{\"lat\":26.84422222305707,\"lon\":112.55380124821464},{\"lat\":26.845488430408043,\"lon\":112.553770582712}," + - "{\"lat\":26.845890797709917,\"lon\":112.55376290998989},{\"lat\":26.8462931778245,\"lon\":112.55376288026709}," + - "{\"lat\":26.846994945978572,\"lon\":112.55375518542454},{\"lat\":26.84857199311408,\"lon\":112.55372449688247}," + - "{\"lat\":26.850915603316924,\"lon\":112.55366317952681},{\"lat\":26.851264598540528,\"lon\":112.55367079677764}," + - "{\"lat\":26.851613580683804,\"lon\":112.55367077099322},{\"lat\":26.852782561801757,\"lon\":112.55366304158481}," + - "{\"lat\":26.854128918956658,\"lon\":112.55367058513775},{\"lat\":26.85416133799072,\"lon\":112.55367058274223}," + - "{\"lat\":26.854773485472688,\"lon\":112.55367053750845},{\"lat\":26.85698175172949,\"lon\":112.55364744520502}," + - "{\"lat\":26.859598084724535,\"lon\":112.55360903659395},{\"lat\":26.862271647879098,\"lon\":112.55358590979833}," + - "{\"lat\":26.865147332784925,\"lon\":112.55355512493922},{\"lat\":26.865349473200677,\"lon\":112.55355510999556}," + - "{\"lat\":26.86715728059924,\"lon\":112.5535473332667},{\"lat\":26.8700749470803,\"lon\":112.55353947446217}," + - "{\"lat\":26.87053068868336,\"lon\":112.55352415459471},{\"lat\":26.872084848173277,\"lon\":112.55350875349178}," + - "{\"lat\":26.87280568452292,\"lon\":112.55350870018658},{\"lat\":26.874220619342925,\"lon\":112.55348566625867}," + - "{\"lat\":26.874220619342925,\"lon\":112.55348566625867},{\"lat\":26.8743981499678,\"lon\":112.55359265628044}," + - "{\"lat\":26.876129653094548,\"lon\":112.55357724209203},{\"lat\":26.876238350333104,\"lon\":112.55357723405288}," + - "{\"lat\":26.87722422693687,\"lon\":112.55356187499282},{\"lat\":26.878499948626235,\"lon\":112.55353885139881}," + - "{\"lat\":26.878742146279425,\"lon\":112.5535464765656},{\"lat\":26.87904156585159,\"lon\":112.55356174057314}," + - "{\"lat\":26.879174347427238,\"lon\":112.55314900085355},{\"lat\":26.879174347427238,\"lon\":112.55314900085355}," + - "{\"lat\":26.879116545005985,\"lon\":112.55280505766768},{\"lat\":26.878943245115085,\"lon\":112.55184963298143}," + - "{\"lat\":26.878806472640868,\"lon\":112.55107761984246},{\"lat\":26.878713941862863,\"lon\":112.55052725736591}," + - "{\"lat\":26.878437158373803,\"lon\":112.5483333129957},{\"lat\":26.878283777019536,\"lon\":112.54691898636362}," + - "{\"lat\":26.8782233056314,\"lon\":112.54623090393771},{\"lat\":26.878174442724657,\"lon\":112.54563454956121}," + - "{\"lat\":26.878164554891434,\"lon\":112.54545869832023},{\"lat\":26.878123256507333,\"lon\":112.54483938643703}," + - "{\"lat\":26.878067664889805,\"lon\":112.54376893263695},{\"lat\":26.87802073724931,\"lon\":112.54141376662929}," + - "{\"lat\":26.878020473600568,\"lon\":112.54129141419749},{\"lat\":26.878006686433814,\"lon\":112.54021315914473}," + - "{\"lat\":26.877995617191544,\"lon\":112.53951724050327},{\"lat\":26.87798902932084,\"lon\":112.53912721215966}," + - "{\"lat\":26.87798417185096,\"lon\":112.53866069993084},{\"lat\":26.87797034314032,\"lon\":112.5376052819373}," + - "{\"lat\":26.877904771969245,\"lon\":112.53244233742839},{\"lat\":26.87789134593889,\"lon\":112.53163148144348}," + - "{\"lat\":26.87786602244677,\"lon\":112.53064465683066},{\"lat\":26.87782568523666,\"lon\":112.52976490461232}," + - "{\"lat\":26.877809833418425,\"lon\":112.52952775023115},{\"lat\":26.877809660077073,\"lon\":112.52945889830228}," + - "{\"lat\":26.877793497045896,\"lon\":112.52909933698427},{\"lat\":26.877765422377227,\"lon\":112.52855616264061}," + - "{\"lat\":26.877765422377227,\"lon\":112.52855616264061},{\"lat\":26.877651755590847,\"lon\":112.52662055504709}," + - "{\"lat\":26.87759103383806,\"lon\":112.52527397999641},{\"lat\":26.877578807673792,\"lon\":112.52497558422694}," + - "{\"lat\":26.877550150107766,\"lon\":112.5242334096616},{\"lat\":26.8775454631642,\"lon\":112.52390439907114}," + - "{\"lat\":26.8775705911727,\"lon\":112.52331523086403},{\"lat\":26.877599976720568,\"lon\":112.52289438998851}," + - "{\"lat\":26.877700379351634,\"lon\":112.52193791396827},{\"lat\":26.87783653603692,\"lon\":112.52081306743382}," + - "{\"lat\":26.87794659907845,\"lon\":112.51991775931802},{\"lat\":26.87803420576694,\"lon\":112.51918313363727}," + - "{\"lat\":26.878091905110153,\"lon\":112.51867041904868},{\"lat\":26.878169213335745,\"lon\":112.51766793293663}," + - "{\"lat\":26.878242581649566,\"lon\":112.5166271615322},{\"lat\":26.878273796063315,\"lon\":112.51619860194072}," + - "{\"lat\":26.878303472199264,\"lon\":112.51522667932018},{\"lat\":26.87829062072998,\"lon\":112.51472923351307}," + - "{\"lat\":26.878258848003124,\"lon\":112.51428535631486},{\"lat\":26.87790199901372,\"lon\":112.51153784231195}," + - "{\"lat\":26.87790199901372,\"lon\":112.51153784231195},{\"lat\":26.878286565374772,\"lon\":112.5113158617034}," + - "{\"lat\":26.878286565374772,\"lon\":112.5113158617034},{\"lat\":26.878431428456157,\"lon\":112.51129289027774}," + - "{\"lat\":26.878667958535303,\"lon\":112.5113158331442},{\"lat\":26.878667958535303,\"lon\":112.5113158331442}," + - "{\"lat\":26.878678138797152,\"lon\":112.51087957995009},{\"lat\":26.878690352202895,\"lon\":112.509831030359}," + - "{\"lat\":26.878699530812526,\"lon\":112.50970857034845},{\"lat\":26.878737491943227,\"lon\":112.5096473377598}," + - "{\"lat\":26.878737491943227,\"lon\":112.5096473377598},{\"lat\":26.87879075331014,\"lon\":112.5096014114246}," + - "{\"lat\":26.881275571457582,\"lon\":112.50961653268486},{\"lat\":26.881767589811375,\"lon\":112.50962414954007}," + - "{\"lat\":26.882122440471107,\"lon\":112.50967769900092},{\"lat\":26.88221980681574,\"lon\":112.50971596028774}," + - "{\"lat\":26.88257321771232,\"lon\":112.50993023747169},{\"lat\":26.88257321771232,\"lon\":112.50993023747169}," + - "{\"lat\":26.88351446532152,\"lon\":112.50900406412066},{\"lat\":26.883643691685222,\"lon\":112.50885097840336}," + - "{\"lat\":26.88371196217497,\"lon\":112.5087208584019},{\"lat\":26.884099751766627,\"lon\":112.5076492862477}," + - "{\"lat\":26.884099751766627,\"lon\":112.5076492862477},{\"lat\":26.884364549439884,\"lon\":112.50755741913363}," + - "{\"lat\":26.884829689791164,\"lon\":112.50750380663162},{\"lat\":26.884919429072728,\"lon\":112.50754206963039}," + - "{\"lat\":26.88496340137097,\"lon\":112.5075803360432},{\"lat\":26.88500174259158,\"lon\":112.50764921859975}," + - "{\"lat\":26.885013476143417,\"lon\":112.50774871879156},{\"lat\":26.885055608713724,\"lon\":112.50780994699682}," + - "{\"lat\":26.885055608713724,\"lon\":112.50780994699682},{\"lat\":26.885056259143553,\"lon\":112.50803191023526}," + - "{\"lat\":26.885018276929266,\"lon\":112.50808549033137},{\"lat\":26.884766782736666,\"lon\":112.50816204804912}," + - "{\"lat\":26.884722922723803,\"lon\":112.50816205133796},{\"lat\":26.884677447004925,\"lon\":112.50826155514717}," + - "{\"lat\":26.884616984162705,\"lon\":112.50845290622735},{\"lat\":26.884527446696502,\"lon\":112.50848352834187}," + - "{\"lat\":26.884367351784473,\"lon\":112.50851415573345},{\"lat\":26.884312184268587,\"lon\":112.50856008292808}," + - "{\"lat\":26.88427096917155,\"lon\":112.50881266232054},{\"lat\":26.884292303244706,\"lon\":112.50893512163981}," + - "{\"lat\":26.88426006366657,\"lon\":112.50899635443699},{\"lat\":26.884183964013573,\"lon\":112.50905759046893}," + - "{\"lat\":26.884146025794323,\"lon\":112.50912647736762},{\"lat\":26.884156260593674,\"lon\":112.51002196307275}," + - "{\"lat\":26.88423087653796,\"lon\":112.51010614790864},{\"lat\":26.884343609318197,\"lon\":112.51018267612086}," + - "{\"lat\":26.884452616959017,\"lon\":112.51028981912732},{\"lat\":26.88451038077976,\"lon\":112.51048115574633}," + - "{\"lat\":26.884507321034185,\"lon\":112.51074137875689},{\"lat\":26.884454856613047,\"lon\":112.51106283289384}," + - "{\"lat\":26.88435289830749,\"lon\":112.51141490315304},{\"lat\":26.884321054331565,\"lon\":112.51161389656696}]\n" - - reqData = GsonUtils.fromJson(json, object : TypeToken>() {}.type) - handleGlobalPath(reqData!!) - // 获取道路事件 - travelNetWorkModel.getEventsWithTrajRequest(reqData!!, onSuccess = { - Log.d(TAG, "111$it") - handleRoadEvent(it) - }, onError = { - Log.d(TAG, "111$it") - }) - // 获取路口设备 - travelNetWorkModel.getCrossDevice(112.583797, 26.817827, "0734", onSuccess = { - Log.d(TAG, "222$it") - handleCrossDevices(it) - }, onError = { - Log.d(TAG, "222$it") - }) + private fun advanceRequest() { + isRoadTrackReq = true // 获取智慧道路轨迹 - travelNetWorkModel.getCityRoadTrack(112.583797, 26.817827, "0734", onSuccess = { - Log.d(TAG, "333$it") + travelNetWorkModel.getCityRoadTrack(onSuccess = { + Log.d(TAG, "Road track result is:$it") + roadTrackList = it + isRoadTrackReq = false handleRoadTrajectories(it) }, onError = { - Log.d(TAG, "333$it") + isRoadTrackReq = false + Log.d(TAG, "Road track error is:$it") }) -// // 获取智慧路口路网范围 -// travelNetWorkModel.getCityRoadRange(112.583797, 26.817827, "0734", onSuccess = { -// Log.d(TAG, "444$it") -// handleRoadRange(it) -// }, onError = { -// Log.d(TAG, "444$it") -// }) } private fun handleGlobalPath(globalData: List) { @@ -392,17 +337,20 @@ class TravelRealityView @JvmOverloads constructor( globalOptions.width(AutoSizeUtils.dp2px(context, 20f).toFloat()) globalOptions.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound) globalOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound) - globalOptions.color(Color.parseColor("#49DEAE")) - + globalOptions.color(globalPathColor) + var pointTmp: LatLng globalData.forEach { globalPoint -> - val point = coordinateConverterWgsToGcj(globalPoint.lat, globalPoint.lon) + pointTmp = coordinateConverterWgsToGcj(globalPoint.lat, globalPoint.lon) // markerOptionsList1.add(MarkerOptions().also { -// it.position(point) +// it.position(pointTmp) // it.anchor(0.5f, 0.5f) // it.icon(pointBitmap1) // }) - boundsBuilder.include(point) - globalOptions.add(coordinateConverterWgsToGcj(globalPoint.lat, globalPoint.lon)) + boundsBuilder.include(pointTmp) + globalOptions.add(pointTmp) + } + if (mLocation != null) { + boundsBuilder.include(LatLng(mLocation!!.latitude, mLocation!!.longitude)) } val cameraUpdate = CameraUpdateFactory.newLatLngBoundsRect( @@ -412,8 +360,9 @@ class TravelRealityView @JvmOverloads constructor( AutoSizeUtils.dp2px(context, topPadding.toFloat()), AutoSizeUtils.dp2px(context, bottomPadding.toFloat()) ) - mAMap?.moveCamera(cameraUpdate) + moveMapCamera(cameraUpdate) +// // 旋转到水平位置 // val startPoint = globalData[0] // val endPoint = globalData[globalData.size - 1] // val angle = DrivingDirectionUtils.getLineAngle(endPoint.lon, endPoint.lat, startPoint.lon, startPoint.lat) @@ -421,15 +370,28 @@ class TravelRealityView @JvmOverloads constructor( // mAMap?.setMapStatusLimits(boundsBuilder.build()) // mAMap?.addMarkers(markerOptionsList1, false) + + val endOption = MarkerOptions() + endOption.icon(BitmapDescriptorFactory.fromResource(endPointDrawable)) + endOption.position( + coordinateConverterWgsToGcj( + globalData[globalData.size - 1].lat, + globalData[globalData.size - 1].lon + ) + ) + // 绘制终点 + drawEndMarker(endOption) + // 绘制全局轨迹 drawPolyline(DRAW_POLY_LINE, globalOptions) } private fun handleRoadEvent(eventList: List) { val globalList = reqData - if (eventList.isEmpty()) return + if (eventList.isEmpty() || globalList.isNullOrEmpty()) return testTime = System.currentTimeMillis() + val eventOptionsList = ArrayList() - globalList?.forEachIndexed { index, globalPoint -> + globalList.forEachIndexed { index, globalPoint -> if (index >= 0 && index < globalList.size - 1) { eventList.forEach { eventBean -> if (LocationUtils.pointToLine( @@ -443,63 +405,153 @@ class TravelRealityView @JvmOverloads constructor( ) { return@forEach } - when (eventBean.poiType) { - "10032" -> {// 交通事故 - eventOptionsList.add(MarkerOptions().apply { - position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) - anchor(0.5f, 0.5f) - icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_shigu_nor)) - }) - } - - "10006" -> {// 施工 - eventOptionsList.add(MarkerOptions().apply { - position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) - anchor(0.5f, 0.5f) - icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_shigong_image)) - }) - } - - "10007" -> {// 拥堵 - eventOptionsList.add(MarkerOptions().apply { - position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) - anchor(0.5f, 0.5f) - icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_yongdu_nor)) - }) - } - - "10025" -> {// 静止事件 - eventOptionsList.add(MarkerOptions().apply { - position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) - anchor(0.5f, 0.5f) - icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_jingzhi_nor)) - }) - } - - else -> { - eventOptionsList.add(MarkerOptions().apply { - position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) - anchor(0.5f, 0.5f) - icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_jingzhi_nor)) - }) - } - } + filterEventWithType(eventBean, eventOptionsList) } } } + ipPointMap.clear() + if (roadEventList.size >= 3) { + val ipList = mutableListOf() + roadEventList[0].ip?.let { + ipPointMap[it] = + coordinateConverterWgsToGcj(roadEventList[0].lat, roadEventList[0].lon) + ipList.add(it) + } + roadEventList[(roadEventList.size - 1) / 2].ip?.let { + ipPointMap[it] = coordinateConverterWgsToGcj( + roadEventList[(roadEventList.size - 1) / 2].lat, + roadEventList[(roadEventList.size - 1) / 2].lon + ) + ipList.add(it) + } + roadEventList[roadEventList.size - 1].ip?.let { + ipPointMap[it] = coordinateConverterWgsToGcj( + roadEventList[roadEventList.size - 1].lat, + roadEventList[roadEventList.size - 1].lon + ) + ipList.add(it) + } + reqCrossLive(ipList) + } else { + retryGetCrossDevice() + } Log.d(TAG, "过滤掉的事件个数为:${eventList.size - eventOptionsList.size}") + // 绘制道路事件 drawMarkers(DRAW_ROAD_EVENT, eventOptionsList) } + private fun filterEventWithType( + eventBean: EventBean, + eventOptionsList: ArrayList + ) { + roadEventList.clear() + when (eventBean.poiType) { + "800003" -> {// 交通事故 + eventOptionsList.add(MarkerOptions().apply { + position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) + anchor(0.5f, 0.5f) + icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_shigu_nor)) + }) + roadEventList.add(eventBean) + } + + "800002" -> {// 施工 + eventOptionsList.add(MarkerOptions().apply { + position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) + anchor(0.5f, 0.5f) + icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_shigong_image)) + }) + roadEventList.add(eventBean) + } + + "800006" -> {// 拥堵 + eventOptionsList.add(MarkerOptions().apply { + position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) + anchor(0.5f, 0.5f) + icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_yongdu_nor)) + }) + } + + "800004" -> {// 静止事件 + eventOptionsList.add(MarkerOptions().apply { + position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) + anchor(0.5f, 0.5f) + icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_jingzhi_nor)) + }) + roadEventList.add(eventBean) + } + + else -> { + eventOptionsList.add(MarkerOptions().apply { + position(coordinateConverterWgsToGcj(eventBean.lat, eventBean.lon)) + anchor(0.5f, 0.5f) + icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_jingzhi_nor)) + }) + roadEventList.add(eventBean) + } + } + } + + private fun retryGetCrossDevice() { + val crossDeviceListTmp = deviceList + if (crossDeviceListTmp.isNullOrEmpty()) { + if (retryCount >= 5) return + retryCount++ + ThreadUtils.runOnUiThreadDelayed({ + retryGetCrossDevice() + }, 100) + } else { + var maxSize = 3 - roadEventList.size + if (maxSize <= 0) return + val ipList = mutableListOf() + roadEventList.forEach { + ipList.add(it.ip ?: "") + } + for (i in crossDeviceListTmp.indices) { + if (maxSize > 0 && !crossDeviceListTmp[i].deviceInfoList.isNullOrEmpty()) { + crossDeviceListTmp[i].deviceInfoList!![0].deviceIp?.let { + ipPointMap[it] = coordinateConverterWgsToGcj( + crossDeviceListTmp[i].deviceInfoList!![0].lat, + crossDeviceListTmp[i].deviceInfoList!![0].lon + ) + ipList.add(it) + maxSize-- + } + } + } + reqCrossLive(ipList) + } + } + + private fun reqCrossLive(ipList: MutableList) { + ndeRoadCameraNetWorkModel.batchRequestCrossLive(ipList, onSuccess = { + val liveOptionsList = ArrayList() + var markerOption: MarkerOptions + it.forEach { roadCamera -> + roadCamera.ip?.let { ip -> + markerOption = MarkerOptions() + markerOption.position(ipPointMap[ip]) + markerOption.anchor(0.5f, 0.5f) + markerOption.icon(BitmapDescriptorFactory.fromView(V2XMarkerView(context))) + liveOptionsList.add(markerOption) + } + } + // 绘制事件卡片 + drawMarkers(DRAW_LIVE_DETAIL, liveOptionsList) + Log.d(TAG, "Cross live result is:$it") + }, onError = { + Log.d(TAG, "Cross live error is:$it") + }) + } + private fun handleCrossDevices(crossDeviceList: List) { if (crossDeviceList.isEmpty()) return - val globalList = reqData val crossOptionsList = ArrayList() - + val globalList = reqData globalList?.forEachIndexed { index, globalPoint -> if (index >= 0 && index < globalList.size - 1) { crossDeviceList.forEach { - it.deviceInfoList?.forEach loop@ { deviceBean -> + it.deviceInfoList?.forEach loop@{ deviceBean -> if (LocationUtils.pointToLine( globalPoint.lon, globalPoint.lat, @@ -513,7 +565,12 @@ class TravelRealityView @JvmOverloads constructor( } crossOptionsList.add(MarkerOptions().apply { - position(coordinateConverterWgsToGcj(deviceBean.lat, deviceBean.lon)) + position( + coordinateConverterWgsToGcj( + deviceBean.lat, + deviceBean.lon + ) + ) anchor(0.5f, 0.5f) icon(BitmapDescriptorFactory.fromResource(R.drawable.mogo_quanxi_lukou)) }) @@ -521,6 +578,7 @@ class TravelRealityView @JvmOverloads constructor( } } } + // 绘制路口设备 drawMarkers(DRAW_CROSS_DEVICE, crossOptionsList) } @@ -546,73 +604,194 @@ class TravelRealityView @JvmOverloads constructor( * 处理智慧道路轨迹的数据 */ private fun handleRoadTrajectories(roadTrajectoryList: List?>?>?) { + if (roadTrajectoryList.isNullOrEmpty()) return val globalList = reqData - if (roadTrajectoryList.isNullOrEmpty() || globalList.isNullOrEmpty()) return val roadTrajectoryOptionsList = ArrayList() + val globalOptionList = ArrayList() + val globalIndexSet = HashSet() + 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, 52f).toFloat()) + options.isUseTexture = true + options.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound) + options.lineCapType(PolylineOptions.LineCapType.LineCapSquare) + options.customTexture = roadTrajectoryBitmap + latLngTmp = coordinateConverterWgsToGcj( + trajPointList[1], + trajPointList[0] + ) + options.add(latLngTmp) + boundsBuilder.include(latLngTmp) + } + roadTrajectoryOptionsList.add(options) + } + if (mLocation != null) { + boundsBuilder.include(LatLng(mLocation!!.latitude, mLocation!!.longitude)) + } - roadTrajectoryList.forEach { trajectoryList -> - var distanceTmp = 0.0 - var lastIndex = -1 - var polylineOptionTmp: PolylineOptions? = null - trajectoryList?.forEachIndexed { index, trajPointList -> - if (trajPointList.isNullOrEmpty()) return@forEachIndexed -// // 待绘制的所有智慧道路轨迹点 -// markerOptionsList2.add(MarkerOptions().also { markerOption -> -// markerOption.position(coordinateConverterWgsToGcj(trajPointList[1], trajPointList[0])) -// markerOption.anchor(0.5f, 0.5f) -// markerOption.icon(pointBitmap2) -// }) + 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) + } else { + roadTrajectoryList.forEach { trajectoryList -> + var distanceTmp: Double + var lastIndex = -1 + var polylineOptionTmp: PolylineOptions? = null - if (index >= 0 && index < trajectoryList.size - 1) { - if (trajPointList.isEmpty() || trajectoryList[index + 1].isNullOrEmpty() - ||trajPointList.size < 2 || trajectoryList[index + 1]!!.size < 2) return - // 遍历所有轨迹点到智慧轨迹线段上的距离 - globalList.forEach { globalPoint -> - distanceTmp = LocationUtils.pointToLine( - trajPointList[0], - trajPointList[1], - trajectoryList[index + 1]!![0], - trajectoryList[index + 1]!![1], - globalPoint.lon, - globalPoint.lat - ) - // 如果距离小于50m则认为在智慧道路内 - if (distanceTmp < 50) { - if (lastIndex < 0 || index - lastIndex > 1) { - // 绘制新的智慧路段轨迹 - polylineOptionTmp = PolylineOptions() - polylineOptionTmp?.let { optionTmp -> - optionTmp.width(AutoSizeUtils.dp2px(context, 52f).toFloat()) - optionTmp.isUseTexture = true - optionTmp.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound) - optionTmp.lineCapType(PolylineOptions.LineCapType.LineCapSquare) - optionTmp.customTexture = roadTrajectoryBitmap - optionTmp.add(coordinateConverterWgsToGcj(trajPointList[1], trajPointList[0])) - optionTmp.add(coordinateConverterWgsToGcj(trajectoryList[index + 1]!![1], - trajectoryList[index + 1]!![0])) - // 待绘制多段智慧道路的轨迹线 - roadTrajectoryOptionsList.add(optionTmp) + trajectoryList?.forEachIndexed { index, trajPointList -> + if (trajPointList.isNullOrEmpty()) return@forEachIndexed + // 待绘制的所有智慧道路轨迹点 +// markerOptionsList2.add(MarkerOptions().also { markerOption -> +// markerOption.position( +// coordinateConverterWgsToGcj( +// trajPointList[1], +// trajPointList[0] +// ) +// ) +// markerOption.anchor(0.5f, 0.5f) +// markerOption.icon(pointBitmap2) +// }) + + if (index >= 0 && index < trajectoryList.size - 1) { + if (trajPointList.isEmpty() || trajectoryList[index + 1].isNullOrEmpty() + || trajPointList.size < 2 || trajectoryList[index + 1]!!.size < 2 + ) return + // 遍历所有轨迹点到智慧轨迹线段上的距离 + globalList.forEachIndexed { i, globalPoint -> + distanceTmp = LocationUtils.pointToLine( + trajPointList[0], + trajPointList[1], + trajectoryList[index + 1]!![0], + trajectoryList[index + 1]!![1], + globalPoint.lon, + globalPoint.lat + ) + // 如果距离小于50m则认为在智慧道路内 + if (distanceTmp < 50) { + Log.d(TAG, "智慧道路内点索引为:$i") + globalIndexSet.add(i) + if (lastIndex < 0 || index - lastIndex > 1) { + // 绘制新的智慧路段轨迹 + polylineOptionTmp = PolylineOptions() + polylineOptionTmp?.let { optionTmp -> + buildPolylineOption(optionTmp, 52f, 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 } - 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 } } } } } + var lastIndex = -1 + var optionTmp: 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, 30f, roadTrajectoryColor) + }) + } else { + optionTmp?.add(coordinateConverterWgsToGcj(point.lat, point.lon)) + } + lastIndex = index + } } // mAMap?.addMarkers(markerOptionsList2, false) + // 绘制在智慧道路范围内的轨迹 + drawPolylineList(DRAW_GLOBAL_TRAJECTORY, globalOptionList) + // 绘制智慧道路范围 drawPolylineList(DRAW_ROAD_TRAJECTORY, roadTrajectoryOptionsList) } + private fun buildPolylineOption( + optionTmp: PolylineOptions, + width: Float, + descriptor: BitmapDescriptor + ) { + optionTmp.width(AutoSizeUtils.dp2px(context, width).toFloat()) + optionTmp.isUseTexture = true + optionTmp.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound) + optionTmp.lineCapType(PolylineOptions.LineCapType.LineCapSquare) + optionTmp.customTexture = descriptor + } + + private fun buildPolylineOptionWithColor( + optionTmp: PolylineOptions, + width: Float, + color: Int + ) { + optionTmp.width(AutoSizeUtils.dp2px(context, width).toFloat()) + optionTmp.isUseTexture = false + optionTmp.lineJoinType(PolylineOptions.LineJoinType.LineJoinRound) + optionTmp.lineCapType(PolylineOptions.LineCapType.LineCapSquare) + optionTmp.color(color) + } + + private fun drawCarMarker(location: MogoLocation) { + Message.obtain().apply { + what = DRAW_CAR_LOCATION + obj = location + nonFrequentHandler?.sendMessage(this) + } + } + + private fun drawEndMarker(options: MarkerOptions) { + Message.obtain().apply { + what = DRAW_END_MARKER + obj = options + nonFrequentHandler?.sendMessage(this) + } + } + private fun drawMarkers(type: Int, optionList: ArrayList) { Message.obtain().apply { what = type @@ -630,6 +809,7 @@ class TravelRealityView @JvmOverloads constructor( } private fun drawPolylineList(type: Int, polylineOptionsList: ArrayList) { + if (polylineOptionsList.isEmpty()) return Message.obtain().apply { what = type obj = polylineOptionsList @@ -637,6 +817,14 @@ class TravelRealityView @JvmOverloads constructor( } } + private fun moveMapCamera(cameraUpdate: CameraUpdate) { + Message.obtain().apply { + what = MOVE_MAP_CAMERA + obj = cameraUpdate + nonFrequentHandler?.sendMessage(this) + } + } + fun coordinateConverterWgsToGcj( lat: Double, lon: Double ): LatLng { @@ -647,9 +835,14 @@ class TravelRealityView @JvmOverloads constructor( return coordinateConverter.convert() } - override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) { - // TODO("绘制自车") - + override fun onChassisLocationGCJ02(gnssInfo: MogoLocation?) { + gnssInfo?.let { + mLocation = it + if (isMapLoaded) { + // 绘制自车 + drawCarMarker(it) + } + } } override fun onAutopilotRotting(globalPathResp: MessagePad.GlobalPathResp?) { @@ -659,8 +852,32 @@ class TravelRealityView @JvmOverloads constructor( } else { lastTime = System.currentTimeMillis() } - globalPathResp?.let { + globalPathResp?.let { globalPath -> + val pointList = ArrayList() + globalPath.wayPointsList.forEach { loc -> + pointList.add(Point(loc.longitude, loc.latitude)) + } + reqData = pointList + handleGlobalPath(pointList) + // 获取路口设备 + travelNetWorkModel.getCrossDevice(onSuccess = { + Log.d(TAG, "Cross device result is:$it") + deviceList = it + handleCrossDevices(it) + }, onError = { + Log.d(TAG, "Cross device error is:$it") + }) + // 获取道路事件 + travelNetWorkModel.getEventsWithTrajRequest(reqData!!, onSuccess = { + Log.d(TAG, "Events result is:$it") + handleRoadEvent(it) + }, onError = { + Log.d(TAG, "Events error is:$it") + }) + if (!isRoadTrackReq) { + handleRoadTrajectories(roadTrackList) + } } } @@ -668,65 +885,208 @@ class TravelRealityView @JvmOverloads constructor( @Suppress("UNCHECKED_CAST") override fun handleMessage(msg: Message) { super.handleMessage(msg) - when (msg.what) { - DRAW_POLY_LINE -> { - removeMessages(DRAW_POLY_LINE) - (msg.obj as PolylineOptions).apply { - realDrawGlobalPath(this) + try { + when (msg.what) { + DRAW_CAR_LOCATION -> { + removeMessages(DRAW_CAR_LOCATION) + (msg.obj as MogoLocation).apply { + realDrawCar(this) + } + } + + DRAW_POLY_LINE -> { + removeMessages(DRAW_POLY_LINE) + (msg.obj as PolylineOptions).apply { + realDrawGlobalPath(this) + } + } + + DRAW_ROAD_EVENT -> { + removeMessages(DRAW_ROAD_EVENT) + (msg.obj as ArrayList).apply { + realDrawEventMarkers(this) + } + } + + DRAW_CROSS_DEVICE -> { + removeMessages(DRAW_CROSS_DEVICE) + (msg.obj as ArrayList).apply { + realDrawCrossDeviceMarkers(this) + } + } + + DRAW_ROAD_RANGE -> { + removeMessages(DRAW_ROAD_RANGE) + (msg.obj as PolylineOptions).apply { + realDrawRoadRange(this) + } + } + + DRAW_ROAD_TRAJECTORY -> { + removeMessages(DRAW_ROAD_TRAJECTORY) + (msg.obj as ArrayList).apply { + realDrawRoadTrajectory(this) + } + } + + DRAW_GLOBAL_TRAJECTORY -> { + removeMessages(DRAW_GLOBAL_TRAJECTORY) + (msg.obj as ArrayList).apply { + realDrawGlobalTrajectory(this) + } + } + + MOVE_MAP_CAMERA -> { + mAMap?.moveCamera(msg.obj as CameraUpdate) + } + + DRAW_LIVE_DETAIL -> { + removeMessages(DRAW_LIVE_DETAIL) + (msg.obj as ArrayList).apply { +// realDrawLiveMarkers(this) + } + } + + DRAW_END_MARKER -> { + removeMessages(DRAW_END_MARKER) + realDrawEndMarker(msg.obj as MarkerOptions) } } + } catch (e: Exception) { + e.printStackTrace() + Log.e(TAG, "概览页面渲染异常为:${e.message}") + } + } + } - DRAW_ROAD_EVENT -> { - removeMessages(DRAW_ROAD_EVENT) - (msg.obj as ArrayList).apply { - realDrawEventMarkers(this) - } + private fun realDrawCar(location: MogoLocation) { + val latLng = LatLng(location.latitude, location.longitude) + val angle = (360 - location.heading).toFloat() + if (mCarMarker != null) { + mCarMarker!!.rotateAngle = angle + mCarMarker!!.position = latLng + } else { + val option = MarkerOptions() + .icon(BitmapDescriptorFactory.fromResource(if (carDrawable != -1) carDrawable else R.drawable.map_car_icon)) + .rotateAngle(360 - location.heading.toFloat()) + .position(LatLng(location.latitude, location.longitude)) + .anchor(0.5f, 0.5f) + mCarMarker = mAMap?.addMarker(option) + mCarMarker?.setToTop() + } + if (mCompassMarker != null) { + mCompassMarker!!.rotateAngle = angle + mCompassMarker!!.position = latLng + } else { + mCompassMarker = mAMap?.addMarker( + MarkerOptions() + .icon(BitmapDescriptorFactory.fromResource(if (compassDrawable != -1) compassDrawable else R.drawable.amap_custom_corner)) + .anchor(0.5f, 0.5f) + ) + } + } + + private fun realDrawGlobalPath(polylineOptions: PolylineOptions) { + if (globalPolyline == null) { + globalPolyline = mAMap?.addPolyline(polylineOptions) + } else { + globalPolyline!!.options = polylineOptions + } + } + + private fun realDrawEventMarkers(eventOptionList: ArrayList) { + eventMarkerList.forEach { + it.destroy() + } + eventMarkerList.clear() + mAMap?.let { + eventMarkerList.addAll(it.addMarkers(eventOptionList, false)) + } + Log.d(TAG, "计算到绘制事件耗时为:${System.currentTimeMillis() - testTime}") + } + + private fun realDrawCrossDeviceMarkers(eventMarkerList: ArrayList) { + deviceMarkerList.forEach { + it.destroy() + } + deviceMarkerList.clear() + mAMap?.let { + deviceMarkerList.addAll(it.addMarkers(eventMarkerList, false)) + } + } + + private fun realDrawGlobalTrajectory(polylineOptionsList: ArrayList) { + if (globalPolylineList.isNotEmpty() && globalPolylineList.size != polylineOptionsList.size) { + globalPolylineList.forEach { + it.remove() + } + globalPolylineList.clear() + mAMap?.let { aMap -> + polylineOptionsList.forEach { + globalPolylineList.add(aMap.addPolyline(it)) } - - DRAW_CROSS_DEVICE -> { - removeMessages(DRAW_CROSS_DEVICE) - (msg.obj as ArrayList).apply { - realDrawCrossDeviceMarkers(this) + } + } else { + mAMap?.let { aMap -> + if (globalPolylineList.isNotEmpty()) { + globalPolylineList.forEachIndexed { index, polyline -> + polyline.options = polylineOptionsList[index] } - } - - DRAW_ROAD_RANGE -> { - removeMessages(DRAW_ROAD_RANGE) - (msg.obj as PolylineOptions).apply { - realDrawRoadRange(this) - } - } - - DRAW_ROAD_TRAJECTORY -> { - removeMessages(DRAW_ROAD_TRAJECTORY) - (msg.obj as ArrayList).apply { - realDrawRoadTrajectory(this) + } else { + polylineOptionsList.forEach { + globalPolylineList.add(aMap.addPolyline(it)) } } } } } - private fun realDrawGlobalPath(polylineOptions: PolylineOptions) { - mAMap?.addPolyline(polylineOptions) + private fun realDrawRoadTrajectory(polylineOptionsList: ArrayList) { + if (trajectoryPolylineList.isNotEmpty() && trajectoryPolylineList.size != polylineOptionsList.size) { + trajectoryPolylineList.forEach { + it.remove() + } + trajectoryPolylineList.clear() + mAMap?.let { aMap -> + polylineOptionsList.forEach { + trajectoryPolylineList.add(aMap.addPolyline(it)) + } + } + } else { + mAMap?.let { aMap -> + if (trajectoryPolylineList.isNotEmpty()) { + trajectoryPolylineList.forEachIndexed { index, polyline -> + polyline.options = polylineOptionsList[index] + } + } else { + polylineOptionsList.forEach { + trajectoryPolylineList.add(aMap.addPolyline(it)) + } + } + } + } } - private fun realDrawEventMarkers(eventMarkerList: ArrayList) { - mAMap?.addMarkers(eventMarkerList, false) - Log.d(TAG, "计算到绘制事件耗时为:${System.currentTimeMillis() - testTime}") + private fun realDrawLiveMarkers(liveOptionList: ArrayList) { + liveMarkerList.forEach { + it.destroy() + } + liveMarkerList.clear() + mAMap?.let { + liveMarkerList.addAll(it.addMarkers(liveOptionList, false)) + } } - private fun realDrawCrossDeviceMarkers(eventMarkerList: ArrayList) { - mAMap?.addMarkers(eventMarkerList, false) + private fun realDrawEndMarker(options: MarkerOptions) { + mEndMarker?.destroy() + if (endPointDrawable != -1) { + mEndMarker = mAMap?.addMarker( + options + ) + } } private fun realDrawRoadRange(polylineOptions: PolylineOptions) { - mAMap?.addPolyline(polylineOptions) - } - - private fun realDrawRoadTrajectory(polylineOptionsList: ArrayList) { - polylineOptionsList.forEach { - mAMap?.addPolyline(it) - } +// mAMap?.addPolyline(polylineOptions) } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi/mogo_yongdu_nor.png b/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi/mogo_yongdu_nor.png deleted file mode 100644 index 4105161e23..0000000000 Binary files a/core/function-impl/mogo-core-function-map/src/main/res/drawable-xhdpi/mogo_yongdu_nor.png and /dev/null differ diff --git a/core/function-impl/mogo-core-function-map/src/main/res/values/attrs.xml b/core/function-impl/mogo-core-function-map/src/main/res/values/attrs.xml index 4030c0316e..2fa5f485e5 100644 --- a/core/function-impl/mogo-core-function-map/src/main/res/values/attrs.xml +++ b/core/function-impl/mogo-core-function-map/src/main/res/values/attrs.xml @@ -60,6 +60,8 @@ + + diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/road/RoadCameraLive.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/road/RoadCameraLive.kt index 36274400ce..2f2a67a554 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/road/RoadCameraLive.kt +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/road/RoadCameraLive.kt @@ -2,7 +2,7 @@ package com.mogo.eagle.core.data.road //路侧直播视频流返回数据 data class RoadCameraLive( - val ip:String, // ip - val liveUrl:String, // 直播地址 - val imageUrl:String // 首帧封面地址 + val ip:String?, // ip + val liveUrl:String?, // 直播地址 + val imageUrl:String? // 首帧封面地址 ) \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/telematic/CallerTelematicListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/telematic/CallerTelematicListenerManager.kt index 29f51e01be..0a8b681a24 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/telematic/CallerTelematicListenerManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/telematic/CallerTelematicListenerManager.kt @@ -24,6 +24,7 @@ object CallerTelematicListenerManager: CallerBase() { try { listener.onReceivedMsg(type, byteArray) } catch (e: Exception) { + e.printStackTrace() Log.e(TAG, "转发消息出现异常:${e.message}") } } @@ -36,6 +37,7 @@ object CallerTelematicListenerManager: CallerBase() { try { listener.onReceivedServerSn(sn) } catch (e: Exception) { + e.printStackTrace() Log.e(TAG, "转发司机屏SN出现异常:${e.message}") } } @@ -49,6 +51,7 @@ object CallerTelematicListenerManager: CallerBase() { try { listener.onDemoMode(isDemoMode) } catch (e: Exception) { + e.printStackTrace() Log.e(TAG, "转发美化模式出现异常:${e.message}") } } diff --git a/core/mogo-core-res/src/main/res/drawable-xhdpi/mogo_yongdu_nor.png b/core/mogo-core-res/src/main/res/drawable-xhdpi/mogo_yongdu_nor.png new file mode 100644 index 0000000000..9f5849ab67 Binary files /dev/null and b/core/mogo-core-res/src/main/res/drawable-xhdpi/mogo_yongdu_nor.png differ