[3.4.0-map-sdk] code tyle
This commit is contained in:
178
libraries/mogo-map/src/main/java/com/mogo/map/AMapWrapper.kt
Normal file
178
libraries/mogo-map/src/main/java/com/mogo/map/AMapWrapper.kt
Normal file
@@ -0,0 +1,178 @@
|
||||
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.sdk.open.marker.BatchMarkerOptions
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerSimpleData
|
||||
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
|
||||
return AMapPointWrapper(options.id, delegate, mMapView)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
val delegate =
|
||||
(if (polylineOptions.lineWidth > 0) mAMap!!.drawThickLine(polylineOptions) else mAMap!!.drawLine(
|
||||
polylineOptions
|
||||
))
|
||||
?: return null
|
||||
return AMapPolylineWrapper(options.id, delegate, mMapView)
|
||||
}
|
||||
|
||||
var batchMarkerOptions = BatchMarkerOptions()
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun updateBatchMarkerPosition(optionsArrayList: HashMap<String, TrackedObject>?) {
|
||||
if (!checkAMap()) {
|
||||
return
|
||||
}
|
||||
if (optionsArrayList == null || optionsArrayList.size == 0) {
|
||||
return
|
||||
}
|
||||
val markerOptionsArrayList = ArrayList<MarkerSimpleData>()
|
||||
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<String, SocketDownData.CloudRoadDataProto>?) {
|
||||
if (!checkAMap()) {
|
||||
return
|
||||
}
|
||||
if (optionsArrayList == null || optionsArrayList.size == 0) {
|
||||
return
|
||||
}
|
||||
val markerOptionsArrayList = ArrayList<MarkerSimpleData>()
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user