浏览代码

修改首页地图点击显示逻辑

Frankensteinly 6 月之前
父节点
当前提交
743d60d0c2

+ 15 - 3
app/src/main/java/com/grkj/iscs/view/fragment/WorkshopFragment.kt

@@ -126,7 +126,7 @@ class WorkshopFragment(val changePage: (PageChangeBO) -> Unit) :
                         mBinding?.rvStatistics?.adapter?.notifyDataSetChanged()
 
                         Executor.repeatOnMain({
-                            val isAllBitmapLoaded = mPointList.all { it.ticketList.all { it.bitmap != null } }
+                            val isAllBitmapLoaded = mPointList.all { it.ticketList.take(4).all { it.bitmap != null } }
                             if (isAllBitmapLoaded) {
                                 mBinding?.mapview?.refresh()
                             }
@@ -149,8 +149,8 @@ class WorkshopFragment(val changePage: (PageChangeBO) -> Unit) :
                 }
                 markLayer = CustomMarkLayer(mBinding?.mapview, mPointList)
                 markLayer?.setMarkIsClickListener(object : CustomMarkLayer.MarkIsClickListener {
-                    override fun markIsClick(index: Int, btnIndex: Int) {
-//                        ToastUtils.tip(mPointList[index].name + " is selected, btnIndex is " + btnIndex)
+                    override fun markIsClick(index: Int, btnIndex: Int, isClickIcon: Boolean) {
+//                        ToastUtils.tip(mPointList[index].name + " is selected, btnIndex is " + btnIndex + ", isClickIcon is " + isClickIcon)
                         if (btnIndex == -1) {
                             changePage(
                                 PageChangeBO(
@@ -160,6 +160,18 @@ class WorkshopFragment(val changePage: (PageChangeBO) -> Unit) :
                                 )
                             )
                         } else {
+                            if (isClickIcon && (mPointList[index].ticketList.size <= 3 || (mPointList[index].ticketList.size > 3 && btnIndex < 2))) {
+                                changePage(
+                                    PageChangeBO(
+                                        2,
+                                        mPointList[index].workstationId,
+                                        mPointList[index].ticketList[btnIndex].ticketId,
+                                        mPointList[index].ticketList[btnIndex].machineryId,
+                                        mPointList[index].name
+                                    )
+                                )
+                                return
+                            }
                             TicketListDialog(requireContext()) { selectIdx ->
                                 changePage(
                                     PageChangeBO(

+ 37 - 23
app/src/main/java/com/grkj/iscs/view/widget/CustomMarkLayer.kt

@@ -1,14 +1,11 @@
 package com.grkj.iscs.view.widget
 
-import android.graphics.Bitmap
-import android.graphics.BitmapFactory
 import android.graphics.Canvas
 import android.graphics.Color
 import android.graphics.Matrix
 import android.graphics.Paint
 import android.util.Pair
 import android.view.MotionEvent
-import com.grkj.iscs.R
 import com.grkj.iscs.view.fragment.WorkshopFragment.CustomPoint
 import com.onlylemi.mapview.library.MapView
 import com.onlylemi.mapview.library.layer.MapBaseLayer
@@ -28,6 +25,8 @@ class CustomMarkLayer @JvmOverloads constructor(
     private var btnIndex: Int
     private var currentZoom = 0f
     private var currentDegree = 0f
+    private var mBitmapSize = 60    // 默认图标大小
+    private var isClickIcon: Boolean = false
 
     init {
         num = -1
@@ -47,7 +46,7 @@ class CustomMarkLayer @JvmOverloads constructor(
             val goal = mapView.convertMapXYToScreenXY(event.x, event.y)
 
             for (i in pointList.indices) {
-                val list = pointList[i].ticketList
+                val list = pointList[i].ticketList.take(3)
                 var continueOuterLoop = false // 双循环跳出标志变量
 
                 // 计算文字点击
@@ -62,6 +61,7 @@ class CustomMarkLayer @JvmOverloads constructor(
                     num = i
                     btnIndex = -1
                     isClickMark = true
+                    isClickIcon = false
                     break
                 }
 
@@ -69,20 +69,20 @@ class CustomMarkLayer @JvmOverloads constructor(
                 for (j in list.indices) {
                     val ticketX = if (list.size % 2 == 0) { // 偶数个
                         if (j + 1 <= list.size / 2) {
-                            pointList[i].pos.x - list[j].bitmap!!.width * (list.size / 2 - j - 0.5f) / currentZoom
+                            pointList[i].pos.x - mBitmapSize * (list.size / 2 - j - 0.5f) / currentZoom
                         } else {
-                            pointList[i].pos.x + list[j].bitmap!!.width * (j - list.size / 2 + 0.5f) / currentZoom
+                            pointList[i].pos.x + mBitmapSize * (j - list.size / 2 + 0.5f) / currentZoom
                         }
                     } else {    // 奇数个
                         if (j + 1 <= list.size / 2) {
-                            pointList[i].pos.x - list[j].bitmap!!.width * (list.size / 2 - j) / currentZoom
+                            pointList[i].pos.x - mBitmapSize * (list.size / 2 - j) / currentZoom
                         } else {
-                            pointList[i].pos.x + list[j].bitmap!!.width * (j - list.size / 2) / currentZoom
+                            pointList[i].pos.x + mBitmapSize * (j - list.size / 2) / currentZoom
                         }
                     }
                     val rotatedPoint = rotatePoint(
                         ticketX,
-                        pointList[i].pos.y - list[j].bitmap!!.height / currentZoom,
+                        pointList[i].pos.y - mBitmapSize / currentZoom,
                         pointList[i].pos.x,
                         pointList[i].pos.y,
                         currentDegree
@@ -94,12 +94,26 @@ class CustomMarkLayer @JvmOverloads constructor(
                         rotatedPoint.second
                     )
 
-                    if (distance <= list[j].bitmap!!.width / 2 / currentZoom) {
+                    if (distance <= mBitmapSize / 2 / currentZoom) {
                         num = i
                         btnIndex = j
                         isClickMark = true
                         continueOuterLoop = true
+                        isClickIcon = true
                         break
+                    } else {
+                        val idxDistance = MapMath.getDistanceBetweenTwoPoints(
+                            goal[0], goal[1],
+                            rotatedPoint.first,
+                            rotatedPoint.second - mBitmapSize / currentZoom
+                        )
+                        if (idxDistance <= mBitmapSize / 2 / currentZoom) {
+                            num = i
+                            btnIndex = j
+                            isClickMark = true
+                            continueOuterLoop = true
+                            isClickIcon = false
+                        }
                     }
                 }
 
@@ -112,7 +126,7 @@ class CustomMarkLayer @JvmOverloads constructor(
             }
 
             if (listener != null && isClickMark) {
-                listener!!.markIsClick(num, btnIndex)
+                listener!!.markIsClick(num, btnIndex, isClickIcon)
                 mapView.refresh()
             }
         }
@@ -165,18 +179,18 @@ class CustomMarkLayer @JvmOverloads constructor(
                         for (j in list.indices) {
                             val ticketX = if (list.size % 2 == 0) { // 偶数个
                                 if (j + 1 <= list.size / 2) {
-                                    goal[0] - list[j].bitmap!!.width * (list.size / 2 - j)
+                                    goal[0] - mBitmapSize * (list.size / 2 - j)
                                 } else {
-                                    goal[0] + list[j].bitmap!!.width * (j - list.size / 2)
+                                    goal[0] + mBitmapSize * (j - list.size / 2)
                                 }
                             } else {    // 奇数个
                                 if (j + 1 <= list.size / 2) {
-                                    goal[0] - list[j].bitmap!!.width * (list.size / 2 - j + 0.5f)
+                                    goal[0] - mBitmapSize * (list.size / 2 - j + 0.5f)
                                 } else {
-                                    goal[0] + list[j].bitmap!!.width * (j - list.size / 2 - 0.5f)
+                                    goal[0] + mBitmapSize * (j - list.size / 2 - 0.5f)
                                 }
                             }
-                            val ticketY = goal[1] - list[j].bitmap!!.height / 2 * 3
+                            val ticketY = goal[1] - mBitmapSize / 2 * 3
 
                             // 绘制图标
                             canvas.drawBitmap(
@@ -190,10 +204,10 @@ class CustomMarkLayer @JvmOverloads constructor(
                             val numberText = if (point.ticketList.size > 3 && j == list.size - 1) "${j + 1}+" else (j + 1).toString()
                             val numberWidth = paint.measureText(numberText)
                             val numberHeight = paint.fontMetrics.descent - paint.fontMetrics.ascent
-                            val numberRectLeft = ticketX + list[j].bitmap!!.width / 2 - radiusMark / 4.0f * 3
-                            val numberRectTop = ticketY - list[j].bitmap!!.height / 2 - radiusMark / 4.0f * 3
-                            val numberRectRight = ticketX + list[j].bitmap!!.width / 2 + radiusMark / 4.0f * 3
-                            val numberRectBottom = ticketY - list[j].bitmap!!.height / 2 + radiusMark / 4.0f * 3
+                            val numberRectLeft = ticketX + mBitmapSize / 2 - radiusMark / 4.0f * 3
+                            val numberRectTop = ticketY - mBitmapSize / 2 - radiusMark / 4.0f * 3
+                            val numberRectRight = ticketX + mBitmapSize / 2 + radiusMark / 4.0f * 3
+                            val numberRectBottom = ticketY - mBitmapSize / 2 + radiusMark / 4.0f * 3
 
                             // 绘制序号背景
                             paint.color = Color.parseColor("#00AAFF")
@@ -211,8 +225,8 @@ class CustomMarkLayer @JvmOverloads constructor(
                             paint.color = Color.WHITE
                             canvas.drawText(
                                 numberText,
-                                ticketX + list[j].bitmap!!.width / 2 - numberWidth / 2,
-                                ticketY - list[j].bitmap!!.height / 2 + radiusMark / 3.0f,
+                                ticketX + mBitmapSize / 2 - numberWidth / 2,
+                                ticketY - mBitmapSize / 2 + radiusMark / 3.0f,
                                 paint
                             )
                         }
@@ -244,6 +258,6 @@ class CustomMarkLayer @JvmOverloads constructor(
     }
 
     interface MarkIsClickListener {
-        fun markIsClick(index: Int, btnIndex: Int)
+        fun markIsClick(index: Int, btnIndex: Int, isClickIcon: Boolean)
     }
 }