| | |
| | | /** |
| | | * 生成航线 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 条目 |
| | |
| | | } |
| | | zipOutputStream.closeEntry(); // 关闭条目 |
| | | } |
| | | |
| | | |
| | | public static KmlInfo buildKml(KmlParams kmlParams) { |
| | | KmlInfo kmlInfo = new KmlInfo(); |
| | |
| | | public static KmlDocument buildKmlDocument(String fileType, KmlParams kmlParams) { |
| | | KmlDocument kmlDocument = new KmlDocument(); |
| | | if (StringUtils.equals(fileType, FileTypeConstants.KML)) { |
| | | kmlDocument.setAuthor("Cleaner"); |
| | | kmlDocument.setAuthor("Ard-Creator"); |
| | | kmlDocument.setCreateTime(String.valueOf(DateUtil.current())); |
| | | kmlDocument.setUpdateTime(String.valueOf(DateUtil.current())); |
| | | } |
| | |
| | | |
| | | public static KmlMissionConfig buildKmlMissionConfig(KmlParams kmlParams) { |
| | | KmlMissionConfig kmlMissionConfig = new KmlMissionConfig(); |
| | | kmlMissionConfig.setFlyToWayLineMode(FlyToWaylineModeEnums.SAFELY.getValue()); |
| | | if (kmlParams.getFlyToWaylineMode() != null){ |
| | | kmlMissionConfig.setFlyToWayLineMode(kmlParams.getFlyToWaylineMode()); |
| | | }else { |
| | | kmlMissionConfig.setFlyToWayLineMode(FlyToWaylineModeEnums.SAFELY.getValue()); |
| | | } |
| | | kmlMissionConfig.setFinishAction(kmlParams.getFinishAction()); |
| | | if (StringUtils.isNotBlank(kmlParams.getExitOnRcLostAction())) { |
| | | kmlMissionConfig.setExitOnRCLost(ExitOnRCLostEnums.EXECUTE_LOST_ACTION.getValue()); |
| | |
| | | kmlMissionConfig.setExitOnRCLost(ExitOnRCLostEnums.GO_CONTINUE.getValue()); |
| | | } |
| | | kmlMissionConfig.setTakeOffSecurityHeight("20"); |
| | | kmlMissionConfig.setGlobalTransitionalSpeed("15"); |
| | | if (kmlParams.getGlobalTransitionalSpeed() != null){ |
| | | kmlMissionConfig.setGlobalTransitionalSpeed(String.valueOf(kmlParams.getGlobalTransitionalSpeed())); |
| | | }else { |
| | | kmlMissionConfig.setGlobalTransitionalSpeed("15"); |
| | | } |
| | | kmlMissionConfig.setGlobalRTHHeight("100"); |
| | | kmlMissionConfig.setTakeOffRefPoint(kmlParams.getTakeOffRefPoint()); |
| | | kmlMissionConfig.setDroneInfo(buildKmlDroneInfo(kmlParams.getDroneType(), kmlParams.getSubDroneType())); |
| | |
| | | kmlPayloadInfo.setPayloadEnumValue(String.valueOf(payloadType)); |
| | | kmlPayloadInfo.setPayloadPositionIndex(String.valueOf(payloadPosition)); |
| | | return kmlPayloadInfo; |
| | | |
| | | } |
| | | |
| | | |
| | | public static KmlFolder buildKmlFolder(String fileType, KmlParams kmlParams) { |
| | | KmlFolder kmlFolder = new KmlFolder(); |
| | |
| | | return kmlFolder; |
| | | } |
| | | |
| | | |
| | | public static KmlWayLineCoordinateSysParam buildKmlWayLineCoordinateSysParam(String templateType) { |
| | | KmlWayLineCoordinateSysParam kmlWayLineCoordinateSysParam = new KmlWayLineCoordinateSysParam(); |
| | | kmlWayLineCoordinateSysParam.setCoordinateMode("WGS84"); |
| | |
| | | // 0: 不上色 1: 真彩上色 |
| | | kmlPayloadParam.setModelColoringEnable("1"); |
| | | kmlPayloadParam.setImageFormat(kmlParams.getImageFormat()); |
| | | |
| | | return kmlPayloadParam; |
| | | } |
| | | |
| | |
| | | } |
| | | kmlGlobalWaypointHeadingParam.setWaypointHeadingPathMode(WaypointHeadingPathModeEnums.FOLLOW_BAD_ARC.getValue()); |
| | | return kmlGlobalWaypointHeadingParam; |
| | | |
| | | } |
| | | |
| | | public static KmlPlacemark buildKmlPlacemark(RoutePointInfo routePointInfo, KmlParams kmlParams, String fileType) { |
| | |
| | | kmlPlacemark.setIsRisky("0"); |
| | | kmlPlacemark.setKmlPoint(buildKmlPoint(String.valueOf(routePointInfo.getLongitude()), String.valueOf(routePointInfo.getLatitude()))); |
| | | kmlPlacemark.setIndex(String.valueOf(routePointInfo.getRoutePointIndex())); |
| | | |
| | | handleHeight(routePointInfo, kmlParams, fileType, kmlPlacemark); |
| | | handleSpeed(routePointInfo, kmlParams, fileType, kmlPlacemark); |
| | | handleWaypointHeadingParam(routePointInfo, kmlParams, fileType, kmlPlacemark); |
| | |
| | | private static KmlPolygon buildKmlPolygon(List<CoordinatePointReq> coordinatePointReqList) { |
| | | KmlPolygon kmlPolygon = new KmlPolygon(); |
| | | KmlLinearRing kmlLinearRing = new KmlLinearRing(); |
| | | |
| | | String coordinates = coordinatePointReqList.stream().map(point -> point.getLongitude() + "," + point.getLatitude() + "," + point.getHeight()) |
| | | .collect(Collectors.joining(", ")); |
| | | kmlLinearRing.setCoordinates(StringUtils.join(coordinates, " ")); |
| | |
| | | kmlPlacemark.setWaypointHeadingParam(buildKmlWaypointHeadingParam(globalWaypointHeading.getWaypointHeadingMode(), globalWaypointHeading.getWaypointHeadingAngle(), globalWaypointHeading.getWaypointPoiPoint())); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private static void handleSpeed(RoutePointInfo routePointInfo, KmlParams kmlParams, String fileType, KmlPlacemark kmlPlacemark) { |
| | | if (ObjectUtil.isNotEmpty(routePointInfo.getSpeed())) { |
| | |
| | | kmlActionGroup.setActionGroupEndIndex(String.valueOf(ObjectUtil.isNotNull(routePointInfo.getEndIntervalRouteIndex()) ? |
| | | routePointInfo.getEndIntervalRouteIndex() : routePointInfo.getRoutePointIndex())); |
| | | kmlActionGroup.setActionGroupMode(ActionGroupModeEnums.SEQUENCE.getValue()); |
| | | |
| | | String actionTriggerType = ActionTriggerTypeEnums.REACH_POINT.getValue(); |
| | | Double actionTriggerParam = 0.0; |
| | | if (ObjectUtil.isNotNull(routePointInfo.getTimeInterval())) { |
| | |
| | | actionTriggerType = ActionTriggerTypeEnums.MULTIPLE_DISTANCE.getValue(); |
| | | actionTriggerParam = routePointInfo.getDistanceInterval(); |
| | | } |
| | | |
| | | kmlActionGroup.setActionTrigger(buildKmlActionTrigger(actionTriggerType, actionTriggerParam)); |
| | | List<KmlAction> kmlActionList = new ArrayList<>(); |
| | | for (PointActionReq pointActionReq : routePointInfo.getActions()) { |
| | |
| | | } else if (ObjectUtil.isNotNull(pointActionReq.getStopRecord()) && pointActionReq.getStopRecord()) { |
| | | kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.STOP_RECORD.getValue(), pointActionReq, kmlParams)); |
| | | } |
| | | |
| | | } |
| | | kmlActionGroup.setAction(kmlActionList); |
| | | return kmlActionGroup; |