[Opt]全览地图支持可配置的自定义属性
This commit is contained in:
@@ -8,6 +8,7 @@ import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import ch.hsr.geohash.GeoHash
|
||||
@@ -16,7 +17,6 @@ import com.amap.api.maps.CameraUpdate
|
||||
import com.amap.api.maps.CameraUpdateFactory
|
||||
import com.amap.api.maps.TextureMapView
|
||||
import com.amap.api.maps.model.*
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.data.map.Infrastructure
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
import com.mogo.eagle.core.data.v2x.V2XEvent
|
||||
@@ -38,7 +38,6 @@ import com.mogo.eagle.core.function.smp.MarkerDrawerManager.planningPoints
|
||||
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.startLoopCalCarLocation
|
||||
import com.mogo.eagle.core.function.smp.MarkerDrawerManager.updateRoutePoints
|
||||
import com.mogo.eagle.core.function.smp.V2XMarkerView
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils.isTaxi
|
||||
import com.mogo.eagle.core.utilcode.mogo.MapAssetStyleUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
@@ -54,6 +53,18 @@ class OverMapView @JvmOverloads constructor(
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : RelativeLayout(context, attrs, defStyleAttr), IMoGoChassisLocationGCJ02Listener {
|
||||
|
||||
// =============自定义属性相关=============
|
||||
private var mapStylePath: String? = null
|
||||
private var mapStyleExtraPath: String? = null
|
||||
private var carDrawable: Int = -1
|
||||
private var compassDrawable: Int = -1
|
||||
private var startPointDrawable: Int = -1
|
||||
private var endPointDrawable: Int = -1
|
||||
private var arrivedDrawable: Int = -1
|
||||
private var unArrivedDrawable: Int = -1
|
||||
private var resetDrawable: Int = -1
|
||||
|
||||
private var mMapView: TextureMapView? = null
|
||||
private var mAMap: AMap? = null
|
||||
private val zoomLevel = 15
|
||||
@@ -94,6 +105,20 @@ class OverMapView @JvmOverloads constructor(
|
||||
|
||||
init {
|
||||
try {
|
||||
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.OverMapView)
|
||||
mapStylePath = typedArray.getString(R.styleable.OverMapView_mapStylePath)
|
||||
mapStyleExtraPath = typedArray.getString(R.styleable.OverMapView_mapStyleExtraPath)
|
||||
carDrawable = typedArray.getResourceId(R.styleable.OverMapView_carDrawable, -1)
|
||||
compassDrawable = typedArray.getResourceId(R.styleable.OverMapView_compassDrawable, -1)
|
||||
startPointDrawable =
|
||||
typedArray.getResourceId(R.styleable.OverMapView_startPointDrawable, -1)
|
||||
endPointDrawable =
|
||||
typedArray.getResourceId(R.styleable.OverMapView_endPointDrawable, -1)
|
||||
arrivedDrawable = typedArray.getResourceId(R.styleable.OverMapView_arrivedDrawable, -1)
|
||||
unArrivedDrawable =
|
||||
typedArray.getResourceId(R.styleable.OverMapView_unArrivedDrawable, -1)
|
||||
resetDrawable = typedArray.getResourceId(R.styleable.OverMapView_resetDrawable, -1)
|
||||
typedArray.recycle()
|
||||
initView(context)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
@@ -129,21 +154,18 @@ class OverMapView @JvmOverloads constructor(
|
||||
}
|
||||
// =================必须通知高德地图生命周期的变化=================
|
||||
|
||||
fun hideResetView() {
|
||||
overLayerView?.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun initView(context: Context) {
|
||||
mContext = context
|
||||
val smpView = LayoutInflater.from(context).inflate(R.layout.module_overview_map_view, this)
|
||||
mMapView = smpView.findViewById(R.id.aMapView)
|
||||
overLayerView = findViewById(R.id.overLayer)
|
||||
if (isTaxi(FunctionBuildConfig.appIdentityMode)) {
|
||||
overLayerView?.background = resources.getDrawable(R.drawable.amap_reset)
|
||||
arrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.taxi_map_arrow_arrived)
|
||||
unArrivedBitmap =
|
||||
BitmapDescriptorFactory.fromResource(R.drawable.taxi_map_arrow_un_arrive)
|
||||
} else {
|
||||
overLayerView?.background = resources.getDrawable(R.drawable.amap_reset_bus)
|
||||
arrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.arrow_arrived_img)
|
||||
unArrivedBitmap = BitmapDescriptorFactory.fromResource(R.drawable.amap_bus_smooth_route)
|
||||
}
|
||||
overLayerView?.background = resources.getDrawable(if (resetDrawable != -1) resetDrawable else R.drawable.amap_reset)
|
||||
arrivedBitmap = BitmapDescriptorFactory.fromResource(if (arrivedDrawable != -1) arrivedDrawable else R.drawable.taxi_map_arrow_arrived)
|
||||
unArrivedBitmap = BitmapDescriptorFactory.fromResource(if (unArrivedDrawable != -1) unArrivedDrawable else R.drawable.taxi_map_arrow_un_arrive)
|
||||
CallerPlanningRottingListenerManager.addListener(TAG, moGoAutopilotPlanningListener)
|
||||
initAMapView(context)
|
||||
// 注册定位监听
|
||||
@@ -157,19 +179,12 @@ class OverMapView @JvmOverloads constructor(
|
||||
mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel.toFloat())
|
||||
mAMap = mMapView!!.map
|
||||
mCustomMapStyleOptions = CustomMapStyleOptions()
|
||||
if (isTaxi(FunctionBuildConfig.appIdentityMode)) {
|
||||
|
||||
if (!mapStylePath.isNullOrEmpty() && !mapStyleExtraPath.isNullOrEmpty()) {
|
||||
mCustomMapStyleOptions!!.styleData =
|
||||
MapAssetStyleUtils.getAssetsStyle(getContext(), "over_view_style.data")
|
||||
MapAssetStyleUtils.getAssetsStyle(getContext(), mapStylePath)
|
||||
mCustomMapStyleOptions!!.styleExtraData =
|
||||
MapAssetStyleUtils.getAssetsExtraStyle(getContext(), "over_view_style_extra.data")
|
||||
} else {
|
||||
mCustomMapStyleOptions!!.styleData =
|
||||
MapAssetStyleUtils.getAssetsStyle(getContext(), "over_view_style_bus.data")
|
||||
mCustomMapStyleOptions!!.styleExtraData =
|
||||
MapAssetStyleUtils.getAssetsExtraStyle(
|
||||
getContext(),
|
||||
"over_view_style_extra_bus.data"
|
||||
)
|
||||
MapAssetStyleUtils.getAssetsExtraStyle(getContext(), mapStyleExtraPath)
|
||||
}
|
||||
mAMap?.setOnMapLoadedListener {
|
||||
Log.d(TAG, "---onMapLoaded---")
|
||||
@@ -227,36 +242,23 @@ class OverMapView @JvmOverloads constructor(
|
||||
* 自定义导航View和路况状态
|
||||
*/
|
||||
private fun customOptions() {
|
||||
if (isTaxi(FunctionBuildConfig.appIdentityMode)) {
|
||||
mCarMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_car_icon))
|
||||
.anchor(0.5f, 0.5f)
|
||||
)
|
||||
mCompassMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.amap_custom_corner))
|
||||
.anchor(0.5f, 0.5f)
|
||||
)
|
||||
} else {
|
||||
mCarMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_bus_icon))
|
||||
.anchor(0.5f, 0.5f)
|
||||
)
|
||||
mCompassMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.amap_bus_corner))
|
||||
.anchor(0.5f, 0.5f)
|
||||
)
|
||||
}
|
||||
mCarMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(if (carDrawable != -1) carDrawable else R.drawable.map_car_icon))
|
||||
.anchor(0.5f, 0.5f)
|
||||
)
|
||||
mCompassMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(if (compassDrawable != -1) compassDrawable else R.drawable.amap_custom_corner))
|
||||
.anchor(0.5f, 0.5f)
|
||||
)
|
||||
mStartMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_dir_start))
|
||||
.icon(BitmapDescriptorFactory.fromResource(if (startPointDrawable != -1) startPointDrawable else R.drawable.module_small_map_view_dir_start))
|
||||
)
|
||||
mEndMarker = mAMap!!.addMarker(
|
||||
MarkerOptions()
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_dir_end))
|
||||
.icon(BitmapDescriptorFactory.fromResource(if (endPointDrawable != -1) endPointDrawable else R.drawable.module_small_map_view_dir_end))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -558,10 +560,14 @@ class OverMapView @JvmOverloads constructor(
|
||||
for (i in coordinates.indices) {
|
||||
if (i <= locIndex) {
|
||||
// 已走过的置灰
|
||||
textureList.add(arrivedBitmap)
|
||||
arrivedBitmap?.let {
|
||||
textureList.add(it)
|
||||
}
|
||||
} else {
|
||||
// 未走过的纹理
|
||||
textureList.add(unArrivedBitmap)
|
||||
unArrivedBitmap?.let {
|
||||
textureList.add(it)
|
||||
}
|
||||
}
|
||||
texIndexList.add(i)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="OverMapView">
|
||||
<!-- 地图样式asset目录下的路径 -->
|
||||
<attr name="mapStylePath" format="string" />
|
||||
<attr name="mapStyleExtraPath" format="string" />
|
||||
<!-- 自车模型图片 -->
|
||||
<attr name="carDrawable" format="reference" />
|
||||
<!-- 罗盘图片 -->
|
||||
<attr name="compassDrawable" format="reference" />
|
||||
<!-- 起点图片 -->
|
||||
<attr name="startPointDrawable" format="reference" />
|
||||
<!-- 终点图片 -->
|
||||
<attr name="endPointDrawable" format="reference" />
|
||||
<!-- 已走过路线的图片 -->
|
||||
<attr name="arrivedDrawable" format="reference" />
|
||||
<!-- 未走过路线的图片 -->
|
||||
<attr name="unArrivedDrawable" format="reference" />
|
||||
<!-- 重置位置图片 -->
|
||||
<attr name="resetDrawable" format="reference" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user