use of com.baremaps.tile.TileStore in project baremaps by baremaps.
the class TilesetsResource method getTile.
@Override
public Response getTile(UUID tilesetId, String tileMatrixSetId, Integer tileMatrix, Integer tileRow, Integer tileCol) {
Tile tile = new Tile(tileCol, tileRow, tileMatrix);
TileStore tileStore = tileStores.get(tilesetId);
try {
return Response.ok(tileStore.read(tile)).header(CONTENT_ENCODING, "gzip").build();
} catch (TileStoreException e) {
return Response.serverError().build();
}
}
use of com.baremaps.tile.TileStore in project baremaps by baremaps.
the class EditorResources method getTile.
@GET
@javax.ws.rs.Path("/tiles/{z}/{x}/{y}.mvt")
public Response getTile(@PathParam("z") int z, @PathParam("x") int x, @PathParam("y") int y) {
try {
List<PostgresQuery> queries = asPostgresQuery(getTileset());
TileStore tileStore = new PostgresTileStore(dataSource, queries);
Tile tile = new Tile(x, y, z);
Blob blob = tileStore.read(tile);
if (blob != null) {
return Response.status(200).header(CONTENT_TYPE, blob.getContentType()).header(CONTENT_ENCODING, blob.getContentEncoding()).entity(blob.getInputStream()).build();
} else {
return Response.status(204).build();
}
} catch (Exception ex) {
logger.error("Tile error", ex);
return Response.status(404).build();
}
}
use of com.baremaps.tile.TileStore in project baremaps by baremaps.
the class View method call.
@Override
public Integer call() throws Exception {
ObjectMapper objectMapper = defaultObjectMapper();
BlobStore blobStore = options.blobStore();
TileJSON tileJSON = objectMapper.readValue(blobStore.get(this.tileset).getInputStream(), TileJSON.class);
CaffeineSpec caffeineSpec = CaffeineSpec.parse(cache);
DataSource datasource = PostgresUtils.datasource(database);
List<PostgresQuery> queries = asPostgresQuery(tileJSON);
TileStore tileStore = new PostgresTileStore(datasource, queries);
TileStore tileCache = new TileCache(tileStore, caffeineSpec);
// Configure the application
ResourceConfig application = new ResourceConfig().register(CorsFilter.class).register(ViewerResources.class).register(contextResolverFor(objectMapper)).register(new AbstractBinder() {
@Override
protected void configure() {
bind(tileset).to(URI.class).named("tileset");
bind(style).to(URI.class).named("style");
bind(blobStore).to(BlobStore.class);
bind(tileCache).to(TileStore.class);
}
});
BlockingStreamingHttpService httpService = new HttpJerseyRouterBuilder().buildBlockingStreaming(application);
ServerContext serverContext = HttpServers.forPort(port).listenBlockingStreamingAndAwait(httpService);
logger.info("Listening on {}", serverContext.listenAddress());
serverContext.awaitShutdown();
return 0;
}
use of com.baremaps.tile.TileStore in project baremaps by baremaps.
the class TileStoreTest method readWriteDeleteTile.
@Test
@Tag("integration")
void readWriteDeleteTile() throws Exception {
TileStore tileStore = createTileStore();
Tile tile = new Tile(1, 2, 3);
byte[] bytes = "tile_content".getBytes();
Blob blob = Blob.builder().withByteArray(bytes).build();
// Write data
tileStore.write(tile, blob);
// Read the data
try (InputStream inputStream = tileStore.read(tile).getInputStream()) {
assertArrayEquals(bytes, inputStream.readAllBytes());
}
// Delete the data
tileStore.delete(tile);
assertThrows(TileStoreException.class, () -> tileStore.read(tile));
}
use of com.baremaps.tile.TileStore in project baremaps by baremaps.
the class TilesetsResource method loadTileStore.
private TileStore loadTileStore(UUID tilesetId) {
TileJSON tileset = jdbi.withHandle(handle -> handle.createQuery("select tileset from tilesets where id = :id").bind("id", tilesetId).mapTo(TILESET).one());
List<PostgresQuery> queries = tileset.getVectorLayers().stream().flatMap(layer -> layer.getQueries().stream().map(query -> new PostgresQuery(layer.getId(), query.getMinzoom(), query.getMaxzoom(), query.getSql()))).collect(Collectors.toList());
return new PostgresTileStore(dataSource, queries);
}
Aggregations