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() + " 个地标");