package com.mogo.map import android.annotation.SuppressLint import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.i import com.mogo.map.overlay.line.Polyline import com.mogo.map.overlay.point.Point import com.mogo.map.overlay.proxy.line.IMapPolylineOverlay import com.mogo.map.overlay.proxy.point.IMapPointOverlay import com.mogo.map.overlay.wrapper.line.AMapPolylineWrapper import com.mogo.map.overlay.wrapper.point.AMapPointWrapper import com.mogo.map.uicontroller.IMogoMapUIController import com.mogo.map.utils.ObjectUtils import com.zhidaoauto.map.data.point.LonLatPoint import com.zhidaoauto.map.sdk.open.renders.marker.BatchMarkerOptions import com.zhidaoauto.map.sdk.open.renders.marker.Marker import com.zhidaoauto.map.sdk.open.renders.marker.MarkerOptions import com.zhidaoauto.map.sdk.open.renders.marker.MarkerSimpleData import com.zhidaoauto.map.sdk.open.renders.marker.OnMarkClickListener import com.zhidaoauto.map.sdk.open.view.MapAutoView import com.zhidaoauto.map.sdk.open.view.MapAutoViewHelper import mogo.telematics.pad.MessagePad.TrackedObject import mogo.yycp.api.proto.SocketDownData import java.util.function.BiConsumer /** * 代理自研AMap */ class AMapWrapper(map: MapAutoViewHelper?, mapView: MapAutoView, controller: IMogoMapUIController) : IMogoMap { companion object { private const val TAG = "AMapWrapper" } override val uiController: IMogoMapUIController private var mAMap: MapAutoViewHelper? private val mMapView: MapAutoView private var mUiSettings: IMogoUiSettings? = null override val uiSettings: IMogoUiSettings? get() { if (!checkAMap()) { return null } if (mUiSettings == null) { mUiSettings = AMapUiSettingsWrapper(mAMap) } return mUiSettings } override fun addPoint(options: Point.Options): IMapPointOverlay? { if (!checkAMap()) { return null } val markerOptions = ObjectUtils.fromMogo(options, mMapView) if (markerOptions == null) { e(TAG, "marker参数为空") return null } val delegate = mAMap!!.addMarker(markerOptions) ?: return null options.onClickHandler?.get()?.also { delegate.setOnMarkClickListener(object : OnMarkClickListener { override fun onMarkClick(marker: Marker) { it.invoke(marker.getId() ?: "") } }) } return AMapPointWrapper(options.id, delegate, mMapView) } override fun addAnimPoint(options: Point.Options) { if (!checkAMap()) { return } val markerOptions = MarkerOptions(options.id, mMapView.getMapController()).setGps(true) .position(LonLatPoint(options.longitude, options.latitude, options.rotate.toDouble())) val marker = Marker(markerOptions,mMapView.getMapController(), mMapView.getMapController()?.getMarkerCall() ) marker.setDisplayAnimEnable(true) marker.setAnimResource(options.animRes) marker.setAnimScale(options.animScale) } override fun addLine(options: Polyline.Options): IMapPolylineOverlay? { if (!checkAMap()) { return null } val polylineOptions = ObjectUtils.fromMogo(options, mMapView) if (polylineOptions == null) { e(TAG, "polyline参数为空") return null } if (options.isFilledIn) { val delegate = mAMap?.drawPolygon(polylineOptions) return AMapPolylineWrapper(options.id, delegate, mMapView) } else { val delegate = (if (polylineOptions.lineWidth > 0) mAMap?.drawThickLine(polylineOptions) else mAMap?.drawLine( polylineOptions )) ?: return null return AMapPolylineWrapper(options.id, delegate, mMapView) } } private val batchMarkerOptions = BatchMarkerOptions() @SuppressLint("NewApi") override fun updateBatchMarkerPosition(optionsArrayList: HashMap?) { if (!checkAMap()) { return } if (optionsArrayList == null || optionsArrayList.size == 0) { return } val markerOptionsArrayList = ArrayList() optionsArrayList.forEach(BiConsumer { s: String?, trackedObject: TrackedObject? -> val markerOptions = ObjectUtils.fromTrafficData(trackedObject) if (markerOptions != null) { markerOptionsArrayList.add(markerOptions) } }) if (markerOptionsArrayList.size == 0) { return } val time = markerOptionsArrayList[0].time batchMarkerOptions.list = markerOptionsArrayList batchMarkerOptions.delayStrategy = false batchMarkerOptions.ruleAngle = 8.0f batchMarkerOptions.controlIcon = 1 batchMarkerOptions.satelliteTime = time batchMarkerOptions.deleteRule = 0 if (mMapView.getMarkerController() != null) { mMapView.getMarkerController()!!.updateBatchMarkerPositon(batchMarkerOptions) } } var aiBatchMarkerOptions = BatchMarkerOptions() init { i(TAG, "autoop--AMapWrapper: init$this") mAMap = map mMapView = mapView uiController = controller } @SuppressLint("NewApi") override fun updateBatchAiMarkerPosition(optionsArrayList: HashMap?) { if (!checkAMap()) { return } if (optionsArrayList == null || optionsArrayList.size == 0) { return } val markerOptionsArrayList = ArrayList() optionsArrayList.forEach(BiConsumer { s: String?, trackedObject: SocketDownData.CloudRoadDataProto? -> val markerOptions = ObjectUtils.fromAiData(trackedObject) if (markerOptions != null) { markerOptionsArrayList.add(markerOptions) } }) if (markerOptionsArrayList.size == 0) { return } val time = markerOptionsArrayList[0].time // 最后一个参数,是否管理锚点的删除 aiBatchMarkerOptions.list = markerOptionsArrayList aiBatchMarkerOptions.delayStrategy = false aiBatchMarkerOptions.ruleAngle = 8.0f aiBatchMarkerOptions.controlIcon = 1 aiBatchMarkerOptions.satelliteTime = time aiBatchMarkerOptions.deleteRule = 0 if (mMapView.getMarkerController() != null) { mMapView.getMarkerController()!!.updateBatchMarkerPositon(aiBatchMarkerOptions) } } override fun addPreVehicleModel(type: Int, modelRes: Int): String? { try { if (mMapView.getMarkerController() != null) { return mMapView.getMarkerController()!!.addPreVehicleModel(type, modelRes) } } catch (e: Exception) { e.printStackTrace() } return null } override fun removeMarker(uuidString: String?) { try { if (mMapView.getMarkerController() != null) { mMapView.getMarkerController()!!.removeMarker(uuidString!!) } } catch (e: Exception) { e.printStackTrace() } } private fun checkAMap(): Boolean { mAMap = mMapView.getMapAutoViewHelper() if (mAMap == null) { e(TAG, "自研map实例为空,请检查") return false } return true } }