张世豪
4 天以前 dc9dce0555beb85d1262893fd5d56747d6a83855
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package zhuye;
 
import java.awt.*;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
 
/**
 * 测量模式 - 在地图上点击测量距离
 */
public class celiangmoshi {
    private static boolean active = false;
    private static final List<Point2D.Double> measurementPoints = new ArrayList<>();
    
    private celiangmoshi() {
    }
    
    /**
     * 启动测量模式
     */
    public static void start() {
        active = true;
        measurementPoints.clear();
    }
    
    /**
     * 停止测量模式
     */
    public static void stop() {
        active = false;
        measurementPoints.clear();
    }
    
    /**
     * 检查是否处于测量模式
     */
    public static boolean isActive() {
        return active;
    }
    
    /**
     * 添加测量点
     */
    public static void addPoint(Point2D.Double point) {
        if (active && point != null) {
            measurementPoints.add(new Point2D.Double(point.x, point.y));
        }
    }
    
    /**
     * 获取所有测量点
     */
    public static List<Point2D.Double> getPoints() {
        return new ArrayList<>(measurementPoints);
    }
    
    /**
     * 计算两点之间的距离(米)
     */
    public static double calculateDistance(Point2D.Double p1, Point2D.Double p2) {
        if (p1 == null || p2 == null) {
            return 0.0;
        }
        double dx = p2.x - p1.x;
        double dy = p2.y - p1.y;
        return Math.sqrt(dx * dx + dy * dy);
    }
    
    /**
     * 格式化距离显示(保留2位小数,单位米)
     */
    public static String formatDistance(double distance) {
        return String.format(Locale.US, "%.2fm", distance);
    }
    
    /**
     * 清除所有测量点
     */
    public static void clear() {
        measurementPoints.clear();
    }
}