|
|
@@ -59,10 +59,10 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
|
|
|
|
|
|
if (hasAnyAlarm(points, switches)) {
|
|
|
mapView?.refresh()
|
|
|
- mapView?.postDelayed(this, FRAME_INTERVAL) // 🔑 用 this 引用自己
|
|
|
} else {
|
|
|
mapView?.refresh()
|
|
|
}
|
|
|
+ mapView?.postDelayed(this, FRAME_INTERVAL) // 🔑 用 this 引用自己
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -79,9 +79,12 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
|
|
|
// 长按探测
|
|
|
private val longPressTimeoutMs: Long =
|
|
|
android.view.ViewConfiguration.getLongPressTimeout().toLong()
|
|
|
+
|
|
|
// 建议更宽容一些(x1.5):
|
|
|
private val touchSlop: Float =
|
|
|
- android.view.ViewConfiguration.get(mapView?.context ?: SIKCore.getApplication()).scaledTouchSlop * 1.5f
|
|
|
+ android.view.ViewConfiguration.get(
|
|
|
+ mapView?.context ?: SIKCore.getApplication()
|
|
|
+ ).scaledTouchSlop * 1.5f
|
|
|
private val touchSlopSq: Float = touchSlop * touchSlop
|
|
|
|
|
|
private var pendingLongPress = false
|
|
|
@@ -101,10 +104,15 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
|
|
|
val centerMapX = p.pos.x + switchSize / 2f
|
|
|
val centerMapY = p.pos.y + switchSize / 2f
|
|
|
|
|
|
- mapView?.animateCenterOnPoint(centerMapX, centerMapY, longPressCenterDurationMs, lastKnownZoom)
|
|
|
mapView?.postDelayed({
|
|
|
val screen = mapToScreen(centerMapX, centerMapY)
|
|
|
- onLongPressListener?.invoke(p, screen.x, screen.y, centerMapX, centerMapY)
|
|
|
+ onLongPressListener?.invoke(
|
|
|
+ p,
|
|
|
+ screen.x,
|
|
|
+ screen.y - switchSize / 2 - 4,
|
|
|
+ centerMapX,
|
|
|
+ centerMapY
|
|
|
+ )
|
|
|
}, longPressCenterDurationMs)
|
|
|
}
|
|
|
}
|
|
|
@@ -236,7 +244,7 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
|
|
|
if (pendingLongPress && !longPressTriggered) {
|
|
|
val dx = event.x - downScreenX
|
|
|
val dy = event.y - downScreenY
|
|
|
- if (dx*dx + dy*dy > touchSlopSq) {
|
|
|
+ if (dx * dx + dy * dy > touchSlopSq) {
|
|
|
pendingLongPress = false
|
|
|
mapView.removeCallbacks(longPressRunnable)
|
|
|
}
|
|
|
@@ -266,14 +274,24 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
|
|
|
// ① 只缩放:以当前屏幕中心为 pivot,把 scale 动到 targetScale
|
|
|
val curCenter = currentMapCenter()
|
|
|
if (curCenter != null) {
|
|
|
- mapView?.animateCenterOnPoint(curCenter.x, curCenter.y, clickZoomDurationMs, targetScale)
|
|
|
+ mapView?.animateCenterOnPoint(
|
|
|
+ curCenter.x,
|
|
|
+ curCenter.y,
|
|
|
+ clickZoomDurationMs,
|
|
|
+ targetScale
|
|
|
+ )
|
|
|
} else {
|
|
|
// 万一拿不到中心,就直接在下一步里统一做
|
|
|
}
|
|
|
|
|
|
// ② 再居中到目标点(保持 targetScale),确保最后居中
|
|
|
mapView?.postDelayed({
|
|
|
- mapView?.animateCenterOnPoint(targetMapX, targetMapY, clickCenterDurationMs, targetScale)
|
|
|
+ mapView?.animateCenterOnPoint(
|
|
|
+ targetMapX,
|
|
|
+ targetMapY,
|
|
|
+ clickCenterDurationMs,
|
|
|
+ targetScale
|
|
|
+ )
|
|
|
}, clickZoomDurationMs)
|
|
|
|
|
|
// ③ 动画完成后再 selectPoint(此时位置稳定)
|
|
|
@@ -316,7 +334,6 @@ class CustomSwitchStationLayer @JvmOverloads constructor(
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
override fun draw(
|
|
|
canvas: Canvas, currentMatrix: Matrix, currentZoom: Float, currentRotateDegrees: Float
|
|
|
) {
|