From 13d032241e1a2938a8be4f64c9171e1240e9ea1e Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 18:50:42 +0800
Subject: [PATCH] 新增了边界管理页面和首页边界虚线功能
---
src/zhuye/Coordinate.java | 172 ++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 110 insertions(+), 62 deletions(-)
diff --git a/src/zhuye/Coordinate.java b/src/zhuye/Coordinate.java
index 9fa4fc8..af2c5b3 100644
--- a/src/zhuye/Coordinate.java
+++ b/src/zhuye/Coordinate.java
@@ -82,73 +82,121 @@
* 瑙f瀽GNGGA鏁版嵁杩斿洖Coordinate瀵硅薄鍒楄〃锛堝寮虹増锛屽寘鍚珮绋嬫暟鎹級
*/
public static void parseGNGGAToCoordinateList(String gnggaData) {
- if(isStartSaveGngga) {
- String[] records = gnggaData.split("\\$GNGGA");
+ if (!isStartSaveGngga || gnggaData == null || gnggaData.isEmpty()) {
+ return;
+ }
+ // 澶勭悊瀹屾暣鐨凣NGGA鏁版嵁锛堝彲鑳藉寘鍚�$GNGGA鍓嶇紑锛�
+ String cleaned = gnggaData.trim();
+ if (cleaned.startsWith("$GNGGA")) {
+ // 濡傛灉鏁版嵁浠�$GNGGA寮�澶达紝鐩存帴瑙f瀽
+ String record = cleaned.substring("$GNGGA".length());
+ Coordinate coord = parseSingleGnggaRecord(record, false);
+ if (coord != null) {
+ coordinates.add(coord);
+ }
+ } else {
+ // 澶勭悊鍙兘鍖呭惈澶氫釜$GNGGA璁板綍鐨勬儏鍐�
+ String[] records = cleaned.split("\\$GNGGA");
for (String record : records) {
- try {
- String trimmedRecord = record.trim();
- if (trimmedRecord.isEmpty()) continue;
-
- if (!trimmedRecord.startsWith(",")) {
- trimmedRecord = "," + trimmedRecord;
- }
-
- String[] fields = trimmedRecord.split(",");
- if (fields.length < 10) { // 妫�鏌ュ瓧娈垫暟閲忥紝闇�瑕佸寘鍚珮绋嬪瓧娈�
- continue;
- }
-
- String deviceId = fields.length > 15 ? sanitizeDeviceId(fields[15]) : null;
- if (!isDeviceAccepted(deviceId)) {
- continue;
- }
-
- // 妫�鏌ュ畾浣嶈川閲�
- String fixQualityStr = fields[6];
- if (fixQualityStr.isEmpty()) continue;
-
- int fixQuality;
- try {
- fixQuality = Integer.parseInt(fixQualityStr);
- } catch (NumberFormatException e) {
- continue;
- }
-
- if (fixQuality != 4) continue;
-
- // 鎻愬彇鍧愭爣鏁版嵁
- String latitudeStr = fields[2];
- String latDirection = fields[3];
- String longitudeStr = fields[4];
- String lonDirection = fields[5];
-
- // 鎻愬彇娴锋嫈楂樺害锛堢10涓瓧娈碉紝绱㈠紩9锛�
- double elevation = 0.0;
- try {
- String elevationStr = fields[9];
- if (elevationStr != null && !elevationStr.isEmpty()) {
- elevation = Double.parseDouble(elevationStr);
- }
- } catch (NumberFormatException e) {
- // 楂樼▼瑙f瀽澶辫触锛屼娇鐢ㄩ粯璁ゅ��0
- System.err.println("楂樼▼瑙f瀽澶辫触锛屼娇鐢ㄩ粯璁ゅ��0: " + fields[9]);
- }
-
- if (latitudeStr.isEmpty() || longitudeStr.isEmpty() ||
- latDirection.isEmpty() || lonDirection.isEmpty()) {
- continue;
- }
-
- // 鍒涘缓Coordinate瀵硅薄骞舵坊鍔犲埌鍒楄〃锛堝寘鍚珮绋嬫暟鎹級
- Coordinate coord = new Coordinate(latitudeStr, latDirection, longitudeStr, lonDirection, elevation);
+ if (record == null || record.trim().isEmpty()) {
+ continue; // 璺宠繃绌哄瓧绗︿覆锛坰plit浜х敓鐨勭涓�涓厓绱犲彲鑳芥槸绌虹殑锛�
+ }
+ Coordinate coord = parseSingleGnggaRecord(record, false);
+ if (coord != null) {
coordinates.add(coord);
-
- } catch (Exception e) {
- System.err.println("瑙f瀽GNGGA璁板綍澶辫触: " + record);
}
}
- }
+ }
+ }
+
+ /**
+ * 涓插彛瀹炴椂鏁版嵁鐩存帴瑙f瀽鍏ュ彛銆�
+ */
+ public static Coordinate dellchuankougngga(String gnggaData) {
+ if (!isStartSaveGngga || gnggaData == null) {
+ return null;
+ }
+
+ String cleaned = gnggaData.trim();
+ if (cleaned.isEmpty()) {
+ return null;
+ }
+
+ int markerIndex = cleaned.indexOf("$GNGGA");
+ String record = markerIndex >= 0
+ ? cleaned.substring(markerIndex + "$GNGGA".length())
+ : cleaned;
+
+ Coordinate coordinate = parseSingleGnggaRecord(record, true);
+ if (coordinate != null) {
+ coordinates.add(coordinate);
+ }
+ return coordinate;
+ }
+
+ private static Coordinate parseSingleGnggaRecord(String record, boolean skipDeviceFilter) {
+ try {
+ String trimmedRecord = record == null ? "" : record.trim();
+ if (trimmedRecord.isEmpty()) {
+ return null;
+ }
+
+ if (!trimmedRecord.startsWith(",")) {
+ trimmedRecord = "," + trimmedRecord;
+ }
+
+ String[] fields = trimmedRecord.split(",");
+ if (fields.length < 10) {
+ return null;
+ }
+
+ String deviceId = fields.length > 15 ? sanitizeDeviceId(fields[15]) : null;
+ if (!skipDeviceFilter && !isDeviceAccepted(deviceId)) {
+ return null;
+ }
+
+ String fixQualityStr = fields[6];
+ if (fixQualityStr.isEmpty()) {
+ return null;
+ }
+
+ int fixQuality;
+ try {
+ fixQuality = Integer.parseInt(fixQualityStr);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+
+ if (fixQuality != 4) {
+ return null;
+ }
+
+ String latitudeStr = fields[2];
+ String latDirection = fields[3];
+ String longitudeStr = fields[4];
+ String lonDirection = fields[5];
+
+ if (latitudeStr.isEmpty() || longitudeStr.isEmpty() ||
+ latDirection.isEmpty() || lonDirection.isEmpty()) {
+ return null;
+ }
+
+ double elevation = 0.0;
+ try {
+ String elevationStr = fields[9];
+ if (elevationStr != null && !elevationStr.isEmpty()) {
+ elevation = Double.parseDouble(elevationStr);
+ }
+ } catch (NumberFormatException e) {
+ System.err.println("楂樼▼瑙f瀽澶辫触锛屼娇鐢ㄩ粯璁ゅ��0: " + fields[9]);
+ }
+
+ return new Coordinate(latitudeStr, latDirection, longitudeStr, lonDirection, elevation);
+ } catch (Exception e) {
+ System.err.println("瑙f瀽GNGGA璁板綍澶辫触: " + record);
+ return null;
+ }
}
private static boolean isDeviceAccepted(String deviceId) {
--
Gitblit v1.10.0