From 7d9bf35f45f36537a76a0c0c64b688258ef32afd Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Sat, 7 Jun 2025 17:20:37 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E6=8F=90=E4=BA=A4=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=83=A8=E9=97=A8=E5=8C=BA=E5=9F=9F=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E2=91=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SysDepartBoundaryServiceImpl.java | 2 +- .../dromara/system/utils/KmzParserUtil.java | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java b/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java index 9bf2751..15bd7b1 100644 --- a/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java +++ b/dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java @@ -116,7 +116,7 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl currentCoordinates, List placemarks) { + if (currentPlacemark != null && !currentCoordinates.isEmpty()) { + for (String coords : currentCoordinates) { + Placemark newPlacemark = new Placemark(); + newPlacemark.setName(currentPlacemark.getName()); + newPlacemark.setAttributes(new HashMap<>(currentPlacemark.getAttributes())); + newPlacemark.setCoordinates(coords); + placemarks.add(newPlacemark); + } + } + } + /** * 解析KML文件内容 * @@ -120,6 +139,7 @@ public class KmzParserUtil { Placemark currentPlacemark = null; boolean inDescription = false; StringBuilder descriptionContent = new StringBuilder(); + List currentCoordinates = new ArrayList<>(); // 添加调试日志 System.out.println("开始解析KML内容,总行数: " + lines.length); @@ -128,10 +148,10 @@ public class KmzParserUtil { line = line.trim(); if (line.startsWith("")) { - if (currentPlacemark != null) { - placemarks.add(currentPlacemark); - } + // 处理当前Placemark的所有坐标 + processCurrentPlacemarkCoordinates(currentPlacemark, currentCoordinates, placemarks); currentPlacemark = new Placemark(); + currentCoordinates = new ArrayList<>(); System.out.println("发现新的Placemark"); } else if (line.startsWith("")) { if (currentPlacemark != null) { @@ -155,15 +175,14 @@ public class KmzParserUtil { } else if (line.startsWith("")) { if (currentPlacemark != null) { String coords = line.replace("", "").replace("", "").trim(); - currentPlacemark.setCoordinates(coords); + currentCoordinates.add(coords); System.out.println("解析到坐标: " + coords); } } } - if (currentPlacemark != null) { - placemarks.add(currentPlacemark); - } + // 处理最后一个Placemark + processCurrentPlacemarkCoordinates(currentPlacemark, currentCoordinates, placemarks); // 打印解析结果 System.out.println("解析完成,共找到 " + placemarks.size() + " 个地标");