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();
|
}
|
}
|