Prechádzať zdrojové kódy

refactor(地图) :
- 如果在画的话就不处理

周文健 5 mesiacov pred
rodič
commit
487268c0fe

+ 3 - 0
app/src/main/java/com/grkj/iscs/view/fragment/StepFragment.kt

@@ -325,6 +325,9 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
 
                                     // 全部点都加载完后,设置给 layer 并绘制
                                     if (mStationList.size == itMapInfo.pointList.size) {
+                                        if (stationLayer?.inDraw == true) {
+                                            return@loadBitmapFromUrl
+                                        }
                                         mBinding?.mapview?.loadMap(mapBmp)
                                     }
                                 }

+ 3 - 0
app/src/main/java/com/grkj/iscs/view/fragment/SwitchStatusFragment.kt

@@ -109,6 +109,9 @@ class SwitchStatusFragment :
 
                     // 全部点都加载完后,设置给 layer 并绘制
                     if (mStationList.size == itMapInfo.pointList.count { it.x != null && it.y != null }) {
+                        if (stationLayer?.inDraw == true) {
+                            return@loadBitmapFromUrl
+                        }
                         mBinding?.mapview?.loadMap(mapBmp)
                     }
                 }

+ 8 - 2
app/src/main/java/com/grkj/iscs/view/widget/CustomStationLayer.kt

@@ -22,7 +22,7 @@ import kotlin.math.sin
 class CustomStationLayer @JvmOverloads constructor(
     mapView: MapView?, private var pointList: List<IsolationPoint> = mutableListOf()
 ) : MapBaseLayer(mapView) {
-
+    var inDraw: Boolean = false
     private var listener: MarkIsClickListener? = null
     private var radiusMark = 0f
     private lateinit var paint: Paint
@@ -68,6 +68,10 @@ class CustomStationLayer @JvmOverloads constructor(
     override fun draw(
         canvas: Canvas, currentMatrix: Matrix, currentZoom: Float, currentRotateDegrees: Float
     ) {
+        if (inDraw) {
+            return
+        }
+        inDraw = true
         this.currentZoom = currentZoom
         currentDegree = 360 - currentRotateDegrees
 
@@ -77,7 +81,8 @@ class CustomStationLayer @JvmOverloads constructor(
         // 把 mapView 本身的缩放/平移/旋转一次性 concat 到 Canvas
         canvas.concat(currentMatrix)
         val switchData = ModBusController.getSwitchData()
-        pointList.forEach { point ->
+        val tempPointList = pointList.toList()
+        tempPointList.forEach { point ->
             val switchStatus = switchData
                 .find { it.idx == point.pointSerialNumber?.toInt() }?.enabled
             // point.pos.x/y 已经是「图内像素坐标」
@@ -129,6 +134,7 @@ class CustomStationLayer @JvmOverloads constructor(
         }
 
         canvas.restore()
+        inDraw = false
     }
 
     private fun rotatePoint(

+ 9 - 1
app/src/main/java/com/grkj/iscs/view/widget/CustomSwitchStationLayer.kt

@@ -22,6 +22,8 @@ import kotlin.math.sin
 class CustomSwitchStationLayer @JvmOverloads constructor(
     mapView: MapView?, private var pointList: List<IsolationPoint> = mutableListOf()
 ) : MapBaseLayer(mapView) {
+    var inDraw = false
+
     // 呼吸灯周期(毫秒)
     private val breathePeriod = 1200f
     private val FRAME_INTERVAL = 32L   // 约 30fps
@@ -99,6 +101,10 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
     override fun draw(
         canvas: Canvas, currentMatrix: Matrix, currentZoom: Float, currentRotateDegrees: Float
     ) {
+        if (inDraw) {
+            return
+        }
+        inDraw = true
         this.currentZoom = currentZoom
         currentDegree = 360 - currentRotateDegrees
 
@@ -108,7 +114,8 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
         // 把 mapView 本身的缩放/平移/旋转一次性 concat 到 Canvas
         canvas.concat(currentMatrix)
         val switchData = ModBusController.getSwitchData()
-        pointList.forEach { point ->
+        val tempPointList = pointList.toList()
+        tempPointList.forEach { point ->
             val switchStatus = switchData
                 .find { it.idx == point.pointSerialNumber?.toInt() }?.enabled
             // point.pos.x/y 已经是「图内像素坐标」
@@ -187,6 +194,7 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
         }
 
         canvas.restore()
+        inDraw = false
     }
 
     private fun rotatePoint(