模型库、矢量文件
This commit is contained in:
@ -10,7 +10,9 @@ import com.graphhopper.config.Profile;
|
||||
import com.graphhopper.util.shapes.GHPoint;
|
||||
import com.yj.earth.annotation.CheckAuth;
|
||||
import com.yj.earth.business.domain.FileInfo;
|
||||
import com.yj.earth.business.domain.WebSource;
|
||||
import com.yj.earth.business.service.FileInfoService;
|
||||
import com.yj.earth.business.service.WebSourceService;
|
||||
import com.yj.earth.common.config.GraphHopperProperties;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
import com.yj.earth.model.Point;
|
||||
@ -40,6 +42,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@RestController
|
||||
@RequestMapping("/graphhopper")
|
||||
public class GraphHopperController {
|
||||
@Resource
|
||||
private WebSourceService webSourceService;
|
||||
@Resource
|
||||
private FileInfoService fileInfoService;
|
||||
@Resource
|
||||
@ -61,6 +65,15 @@ public class GraphHopperController {
|
||||
return ApiResponse.success(fileInfoService.list(queryWrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取地图列表(网页版)")
|
||||
@CheckAuth
|
||||
@GetMapping("/web/list")
|
||||
public ApiResponse webList() {
|
||||
LambdaQueryWrapper<WebSource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(WebSource::getType, "pbf");
|
||||
return ApiResponse.success(webSourceService.list(queryWrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "加载地图数据")
|
||||
@PostMapping("/loadMap")
|
||||
@CheckAuth
|
||||
@ -120,6 +133,57 @@ public class GraphHopperController {
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@Operation(summary = "加载地图数据(网页版)")
|
||||
@PostMapping("/web/loadMap")
|
||||
@CheckAuth
|
||||
public ApiResponse webLoadMap(@Parameter(description = "文件路径") @RequestParam String path) {
|
||||
File osmFile = new File(path);
|
||||
if (!osmFile.exists()) {
|
||||
return ApiResponse.failure("地图文件不存在: " + path);
|
||||
}
|
||||
if (!osmFile.isFile() || !osmFile.getName().endsWith(".pbf")) {
|
||||
return ApiResponse.failure("仅支持有效的.pbf格式OSM文件");
|
||||
}
|
||||
// 防止并发加载
|
||||
if (isLoading.get()) {
|
||||
return ApiResponse.failure("地图正在加载中、请稍后查询状态");
|
||||
}
|
||||
|
||||
// 标记加载状态
|
||||
isLoading.set(true);
|
||||
isLoaded.set(false);
|
||||
|
||||
// 异步执行: 删除旧数据 → 创建新实例 → 加载新地图
|
||||
new Thread(() -> {
|
||||
GraphHopper newHopper = null;
|
||||
try {
|
||||
// 关键步骤1: 彻底删除旧地图数据目录
|
||||
deleteOldGraphDir();
|
||||
// 关键步骤2: 创建全新的GraphHopper实例
|
||||
newHopper = createNewGraphHopperInstance(path);
|
||||
// 关键步骤3: 加载新地图
|
||||
newHopper.importOrLoad();
|
||||
// 关键步骤4: 加载成功 → 替换当前实例 + 更新状态
|
||||
currentHopper = newHopper;
|
||||
isLoaded.set(true);
|
||||
log.info("地图加载成功");
|
||||
} catch (Exception e) {
|
||||
// 加载失败 → 清理新实例资源
|
||||
if (newHopper != null) {
|
||||
newHopper.close();
|
||||
}
|
||||
isLoaded.set(false);
|
||||
e.printStackTrace();
|
||||
log.error("地图加载失败: " + e.getMessage());
|
||||
|
||||
} finally {
|
||||
// 无论成功/失败、释放加载锁
|
||||
isLoading.set(false);
|
||||
}
|
||||
}).start();
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@Operation(summary = "路径规划")
|
||||
@PostMapping("/route")
|
||||
@CheckAuth
|
||||
|
||||
Reference in New Issue
Block a user