diff --git a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt index 549c53ecf3..2887793cc9 100644 --- a/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt +++ b/core/function-impl/mogo-core-function-map/src/main/java/com/mogo/eagle/core/function/view/OverMapView.kt @@ -88,6 +88,8 @@ class OverMapView @JvmOverloads constructor( private var mContext: Context? = null private var mTilt = 0f private var overLayerView: TextView? = null + @Volatile + private var isMapLoaded = false // 全局路径规划中的GeoHash网格 private val pathMap: MutableMap?> = HashMap() @@ -114,6 +116,7 @@ class OverMapView @JvmOverloads constructor( // 绘制轨迹线的集合 private val textureList: MutableList = ArrayList() private val texIndexList: MutableList = ArrayList() + @Volatile private var mLocation: MogoLocation? = null private var isFirstLocation = true var mCustomMapStyleOptions: CustomMapStyleOptions? = null @@ -415,6 +418,7 @@ class OverMapView @JvmOverloads constructor( } mAMap?.setOnMapLoadedListener { Log.d(TAG, "---onMapLoaded---") + isMapLoaded = true if (mCustomMapStyleOptions != null) { // 加载自定义样式 mCustomMapStyleOptions!!.isEnable = true @@ -834,6 +838,7 @@ class OverMapView @JvmOverloads constructor( } private fun realDisplayOverView() { + Log.d(TAG, "realDisplayOverView被调用") val linePointsLatLng = allPoints if (linePointsLatLng != null && linePointsLatLng.size > 1 && mLocation != null) { //圈定地图显示范围 @@ -857,12 +862,14 @@ class OverMapView @JvmOverloads constructor( ) ) mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) + Log.d(TAG, "切换视角展示轨迹点和车!") } } else { - if (mCarMarker != null && mAMap != null) { + if (mLocation != null && mAMap != null) { //设置希望展示的地图缩放级别 + Log.d(TAG, "切换视角展示车,定位为:${mLocation!!.longitude},${mLocation!!.latitude}") val cameraPosition = CameraPosition.Builder() - .target(mCarMarker!!.position).tilt(mTilt).zoom(zoomLevel.toFloat()).build() + .target(LatLng(mLocation!!.latitude, mLocation!!.longitude)).tilt(mTilt).zoom(zoomLevel.toFloat()).build() mAMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) } } @@ -1060,7 +1067,8 @@ class OverMapView @JvmOverloads constructor( mLocation = it lonLatHeading = Triple(it.longitude, it.latitude, it.heading) drawCarMarker(it) - if (isFirstLocation) { + if (isFirstLocation && isMapLoaded) { + Log.d(TAG, "车辆首次获取定位") displayCustomOverView() isFirstLocation = false }