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 bcb0963f92..bae436e83e 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 @@ -11,6 +11,7 @@ import android.view.MotionEvent import android.view.View import android.widget.RelativeLayout import android.widget.TextView +import androidx.annotation.MainThread import ch.hsr.geohash.GeoHash import com.amap.api.maps.AMap import com.amap.api.maps.CameraUpdate @@ -99,6 +100,7 @@ class OverMapView @JvmOverloads constructor( private var isFirstLocation = true var mCustomMapStyleOptions: CustomMapStyleOptions? = null var currMarkerList: ArrayList? = null + var siteMarkerList: ArrayList? = null companion object { const val TAG = "OverMapView" @@ -155,12 +157,43 @@ class OverMapView @JvmOverloads constructor( } // =================必须通知高德地图生命周期的变化================= + /** + * 隐藏右下角的重置View + */ fun hideResetView() { overLayerView?.visibility = View.GONE } - fun showSiteMarkers() { + /** + * siteLatLngs: 高德坐标集合 + * bitmap: Marker对应的图片 + * (anchorX,anchorY)为锚点坐标,各自取值范围为[0,1],默认值为(0.5,1) + */ + @MainThread + fun drawSiteMarkers(siteLatLngs: List?, bitmap: Bitmap, anchorX: Float, anchorY: Float) { + if (siteLatLngs.isNullOrEmpty()) return + clearSiteMarkers() + val markerOptionsList = ArrayList() + for (latLng in siteLatLngs) { + val markerOption = MarkerOptions() + markerOption.position(latLng) + markerOption.anchor(anchorX, anchorY) + markerOption.icon( + BitmapDescriptorFactory.fromBitmap(bitmap) + ) + markerOptionsList.add(markerOption) + } + siteMarkerList = mAMap!!.addMarkers(markerOptionsList, false) + } + @MainThread + fun clearSiteMarkers() { + if (siteMarkerList != null) { + for (marker in siteMarkerList!!) { + marker.destroy() + } + siteMarkerList = null + } } private fun initView(context: Context) { @@ -168,9 +201,12 @@ class OverMapView @JvmOverloads constructor( val smpView = LayoutInflater.from(context).inflate(R.layout.module_overview_map_view, this) mMapView = smpView.findViewById(R.id.aMapView) overLayerView = findViewById(R.id.overLayer) - 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) + 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, this) initAMapView(context) // 注册定位监听 @@ -357,7 +393,7 @@ class OverMapView @JvmOverloads constructor( return bitmap } - fun clearV2XMarkers() { + private fun clearV2XMarkers() { if (currMarkerList != null) { for (marker in currMarkerList!!) { marker.destroy()