[Opt]全览模式支持清除已走过的轨迹
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.mogo.eagle.core.function.view
|
package com.mogo.eagle.core.function.view
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
@@ -12,6 +13,7 @@ import android.view.View
|
|||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.MainThread
|
import androidx.annotation.MainThread
|
||||||
|
import androidx.core.graphics.drawable.toBitmap
|
||||||
import ch.hsr.geohash.GeoHash
|
import ch.hsr.geohash.GeoHash
|
||||||
import com.amap.api.maps.AMap
|
import com.amap.api.maps.AMap
|
||||||
import com.amap.api.maps.CameraUpdate
|
import com.amap.api.maps.CameraUpdate
|
||||||
@@ -66,6 +68,9 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
private var arrivedDrawable: Int = -1
|
private var arrivedDrawable: Int = -1
|
||||||
private var unArrivedDrawable: Int = -1
|
private var unArrivedDrawable: Int = -1
|
||||||
private var resetDrawable: Int = -1
|
private var resetDrawable: Int = -1
|
||||||
|
private var resetDrawableMarginRight: Int = -1
|
||||||
|
private var resetDrawableMarginBottom: Int = -1
|
||||||
|
private var isClearArrived: Boolean = false
|
||||||
|
|
||||||
private var mMapView: TextureMapView? = null
|
private var mMapView: TextureMapView? = null
|
||||||
private var mAMap: AMap? = null
|
private var mAMap: AMap? = null
|
||||||
@@ -92,6 +97,7 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
// 计算索引并设置对应的Bitmap
|
// 计算索引并设置对应的Bitmap
|
||||||
var arrivedBitmap: BitmapDescriptor? = null
|
var arrivedBitmap: BitmapDescriptor? = null
|
||||||
var unArrivedBitmap: BitmapDescriptor? = null
|
var unArrivedBitmap: BitmapDescriptor? = null
|
||||||
|
var transparentBitmap: BitmapDescriptor? = null
|
||||||
|
|
||||||
// 绘制轨迹线的集合
|
// 绘制轨迹线的集合
|
||||||
private val textureList: MutableList<BitmapDescriptor?> = ArrayList()
|
private val textureList: MutableList<BitmapDescriptor?> = ArrayList()
|
||||||
@@ -121,6 +127,15 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
unArrivedDrawable =
|
unArrivedDrawable =
|
||||||
typedArray.getResourceId(R.styleable.OverMapView_unArrivedDrawable, -1)
|
typedArray.getResourceId(R.styleable.OverMapView_unArrivedDrawable, -1)
|
||||||
resetDrawable = typedArray.getResourceId(R.styleable.OverMapView_resetDrawable, -1)
|
resetDrawable = typedArray.getResourceId(R.styleable.OverMapView_resetDrawable, -1)
|
||||||
|
resetDrawableMarginRight = typedArray.getResourceId(
|
||||||
|
R.styleable.OverMapView_resetDrawableMarginRight,
|
||||||
|
AutoSizeUtils.dp2px(context, 40f)
|
||||||
|
)
|
||||||
|
resetDrawableMarginBottom = typedArray.getResourceId(
|
||||||
|
R.styleable.OverMapView_resetDrawableMarginBottom,
|
||||||
|
AutoSizeUtils.dp2px(context, 40f)
|
||||||
|
)
|
||||||
|
isClearArrived = typedArray.getBoolean(R.styleable.OverMapView_isClearArrived, false)
|
||||||
typedArray.recycle()
|
typedArray.recycle()
|
||||||
initView(context)
|
initView(context)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -170,7 +185,12 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
* (anchorX,anchorY)为锚点坐标,各自取值范围为[0,1],默认值为(0.5,1)
|
* (anchorX,anchorY)为锚点坐标,各自取值范围为[0,1],默认值为(0.5,1)
|
||||||
*/
|
*/
|
||||||
@MainThread
|
@MainThread
|
||||||
fun drawSiteMarkers(siteLatLngs: List<LatLng>?, bitmap: Bitmap, anchorX: Float, anchorY: Float) {
|
fun drawSiteMarkers(
|
||||||
|
siteLatLngs: List<LatLng>?,
|
||||||
|
bitmap: Bitmap,
|
||||||
|
anchorX: Float,
|
||||||
|
anchorY: Float
|
||||||
|
) {
|
||||||
if (siteLatLngs.isNullOrEmpty()) return
|
if (siteLatLngs.isNullOrEmpty()) return
|
||||||
clearSiteMarkers()
|
clearSiteMarkers()
|
||||||
val markerOptionsList = ArrayList<MarkerOptions>()
|
val markerOptionsList = ArrayList<MarkerOptions>()
|
||||||
@@ -210,6 +230,7 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
mEndMarker?.isVisible = false
|
mEndMarker?.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UseCompatLoadingForDrawables")
|
||||||
private fun initView(context: Context) {
|
private fun initView(context: Context) {
|
||||||
mContext = context
|
mContext = context
|
||||||
val smpView = LayoutInflater.from(context).inflate(R.layout.module_overview_map_view, this)
|
val smpView = LayoutInflater.from(context).inflate(R.layout.module_overview_map_view, this)
|
||||||
@@ -221,12 +242,25 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
BitmapDescriptorFactory.fromResource(if (arrivedDrawable != -1) arrivedDrawable else R.drawable.taxi_map_arrow_arrived)
|
BitmapDescriptorFactory.fromResource(if (arrivedDrawable != -1) arrivedDrawable else R.drawable.taxi_map_arrow_arrived)
|
||||||
unArrivedBitmap =
|
unArrivedBitmap =
|
||||||
BitmapDescriptorFactory.fromResource(if (unArrivedDrawable != -1) unArrivedDrawable else R.drawable.taxi_map_arrow_un_arrive)
|
BitmapDescriptorFactory.fromResource(if (unArrivedDrawable != -1) unArrivedDrawable else R.drawable.taxi_map_arrow_un_arrive)
|
||||||
|
transparentBitmap = BitmapDescriptorFactory.fromBitmap(
|
||||||
|
resources.getDrawable(R.drawable.transparent_background, null)
|
||||||
|
.toBitmap(AutoSizeUtils.dp2px(context, 32f), AutoSizeUtils.dp2px(context, 230f))
|
||||||
|
)
|
||||||
CallerPlanningRottingListenerManager.addListener(TAG, this)
|
CallerPlanningRottingListenerManager.addListener(TAG, this)
|
||||||
initAMapView(context)
|
initAMapView(context)
|
||||||
// 注册定位监听
|
// 注册定位监听
|
||||||
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, this)
|
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, this)
|
||||||
//设置全览模式
|
//设置全览模式
|
||||||
overLayerView?.setOnClickListener { displayCustomOverView() }
|
overLayerView?.setOnClickListener { displayCustomOverView() }
|
||||||
|
overLayerView?.let {
|
||||||
|
it.background =
|
||||||
|
resources.getDrawable(if (resetDrawable != -1) resetDrawable else R.drawable.amap_reset)
|
||||||
|
val layoutParams = it.layoutParams
|
||||||
|
layoutParams as RelativeLayout.LayoutParams
|
||||||
|
layoutParams.rightMargin = resetDrawableMarginRight
|
||||||
|
layoutParams.bottomMargin = resetDrawableMarginBottom
|
||||||
|
it.layoutParams = layoutParams
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initAMapView(context: Context) {
|
private fun initAMapView(context: Context) {
|
||||||
@@ -511,7 +545,7 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
*/
|
*/
|
||||||
private fun displayCustomOverView() {
|
private fun displayCustomOverView() {
|
||||||
val linePointsLatLng = planningPoints
|
val linePointsLatLng = planningPoints
|
||||||
if (linePointsLatLng.size > 1) {
|
if (linePointsLatLng.size > 1 && mLocation != null) {
|
||||||
//圈定地图显示范围
|
//圈定地图显示范围
|
||||||
//存放经纬度
|
//存放经纬度
|
||||||
val boundsBuilder = LatLngBounds.Builder()
|
val boundsBuilder = LatLngBounds.Builder()
|
||||||
@@ -595,15 +629,15 @@ class OverMapView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
for (i in coordinates.indices) {
|
for (i in coordinates.indices) {
|
||||||
if (i <= locIndex) {
|
if (i <= locIndex) {
|
||||||
// 已走过的置灰
|
if (isClearArrived) {
|
||||||
arrivedBitmap?.let {
|
textureList.add(transparentBitmap)
|
||||||
textureList.add(it)
|
} else {
|
||||||
|
// 已走过的置灰
|
||||||
|
textureList.add(arrivedBitmap)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 未走过的纹理
|
// 未走过的纹理
|
||||||
unArrivedBitmap?.let {
|
textureList.add(unArrivedBitmap)
|
||||||
textureList.add(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
texIndexList.add(i)
|
texIndexList.add(i)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,5 +18,11 @@
|
|||||||
<attr name="unArrivedDrawable" format="reference" />
|
<attr name="unArrivedDrawable" format="reference" />
|
||||||
<!-- 重置位置图片 -->
|
<!-- 重置位置图片 -->
|
||||||
<attr name="resetDrawable" format="reference" />
|
<attr name="resetDrawable" format="reference" />
|
||||||
|
<!-- 重置位置图片右面margin -->
|
||||||
|
<attr name="resetDrawableMarginRight" format="dimension" />
|
||||||
|
<!-- 重置位置图片下面margin -->
|
||||||
|
<attr name="resetDrawableMarginBottom" format="dimension" />
|
||||||
|
<!-- 是否擦除已走过的路线 -->
|
||||||
|
<attr name="isClearArrived" format="boolean" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user