| | |
| | | /** |
| | | * 生成航线 KMZ 文件 |
| | | * |
| | | * @param fileName 文件名 |
| | | * @param kmlParams 参数对象 |
| | | * @return 本地文件路径 |
| | | */ |
| | | public static String buildKmz(String fileName, KmlParams kmlParams) { |
| | | KmlInfo kmlInfo = buildKml(kmlParams); |
| | | KmlInfo wpmlInfo = buildWpml(kmlParams); |
| | | return buildKmz(fileName, kmlInfo, wpmlInfo); |
| | | } |
| | | |
| | | /** |
| | | * 生成航线 KMZ 文件 |
| | | * |
| | | * @param fileName 文件名 |
| | | * @param kmlInfo kml 文件信息 |
| | | * @param wpmlInfo wpml 文件信息 |
| | | * @return 本地文件路径 |
| | | */ |
| | | public static String buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) { |
| | | public static String buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo, String kmzFilePath) { |
| | | XStream xStream = new XStream(new DomDriver()); |
| | | xStream.processAnnotations(KmlInfo.class); |
| | | xStream.addImplicitCollection(KmlActionGroup.class, "action"); |
| | |
| | | String kml = XML_HEADER + xStream.toXML(kmlInfo); |
| | | String wpml = XML_HEADER + xStream.toXML(wpmlInfo); |
| | | |
| | | try (FileOutputStream fileOutputStream = new FileOutputStream(LOCAL_KMZ_FILE_PATH + fileName + ".kmz"); |
| | | try (FileOutputStream fileOutputStream = new FileOutputStream(kmzFilePath + fileName + ".kmz"); |
| | | ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) { |
| | | zipOutputStream.setLevel(0); // 0 表示不压缩,存储方式 |
| | | |
| | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return LOCAL_KMZ_FILE_PATH + fileName + ".kmz"; |
| | | return kmzFilePath + fileName + ".kmz"; |
| | | } |
| | | |
| | | private static void buildZipFile(String name, ZipOutputStream zipOutputStream, String content) throws IOException { |
| | | public static void buildZipFile(String name, ZipOutputStream zipOutputStream, String content) throws IOException { |
| | | ZipEntry kmlEntry = new ZipEntry(name); |
| | | zipOutputStream.putNextEntry(kmlEntry); |
| | | // 将内容写入 ZIP 条目 |