Skip to content

Commit af6c511

Browse files
author
liushaofeng
committed
增加release mbtiles接口(10秒内有效)
1 parent 1cfa4e5 commit af6c511

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/main/java/io/github/qmjy/mapserver/MapServerDataCenter.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.github.qmjy.mapserver;
1818

1919
import com.graphhopper.GraphHopper;
20+
import com.zaxxer.hikari.HikariDataSource;
2021
import io.github.qmjy.mapserver.model.AdministrativeDivisionTmp;
2122
import io.github.qmjy.mapserver.model.FontsFileModel;
2223
import io.github.qmjy.mapserver.model.TilesFileModel;
@@ -32,6 +33,7 @@
3233
import org.springframework.stereotype.Component;
3334
import org.springframework.util.StringUtils;
3435

36+
import javax.sql.DataSource;
3537
import java.io.File;
3638
import java.io.FileInputStream;
3739
import java.io.IOException;
@@ -262,6 +264,19 @@ public Optional<JdbcTemplate> getDataSource(String fileName) {
262264
}
263265
}
264266

267+
public void releaseDataSource(String fileName) {
268+
if (StringUtils.hasLength(fileName) && tilesMap.containsKey(fileName)) {
269+
TilesFileModel remove = tilesMap.remove(fileName);
270+
JdbcTemplate jdbcTemplate = remove.getJdbcTemplate();
271+
//执行检查点操作,将所有WAL内容写入主数据库文件
272+
jdbcTemplate.execute("PRAGMA wal_checkpoint(FULL)");
273+
DataSource dataSource = jdbcTemplate.getDataSource();
274+
if (dataSource instanceof HikariDataSource hikariDataSource) {
275+
hikariDataSource.close();
276+
}
277+
}
278+
}
279+
265280
/**
266281
* 返回瓦片文件对象
267282
*

src/main/java/io/github/qmjy/mapserver/controller/MapServerTilesetsRestController.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ private Optional<byte[]> getPbfBytes(String tileset, int z, int x, int y) {
343343
}
344344
}
345345

346+
/**
347+
* 释放万片资源
348+
*
349+
* @param tileset 待释放的瓦片资源
350+
* @return 释放结果
351+
*/
352+
@DeleteMapping(value = "/{tileset}", produces = MediaType.APPLICATION_JSON_VALUE)
353+
@ResponseBody
354+
@Operation(summary = "释放mbtiles文件", description = "释放mbtiles文件。")
355+
public ResponseEntity<Object> release(@Parameter(description = "待释放的瓦片数据源或文件夹名字,例如:admin.mbtiles。") @PathVariable("tileset") String tileset) {
356+
mapServerDataCenter.releaseDataSource(tileset);
357+
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body("Success");
358+
}
359+
346360

347361
/**
348362
* 获取指定底图数据的元数据

0 commit comments

Comments
 (0)