use of com.baremaps.tile.Tile 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.Tile 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.Tile 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.Tile in project baremaps by baremaps.
the class PostgresTileStoreTest method differentConditions2.
@Test
void differentConditions2() {
List<PostgresQuery> queries = Arrays.asList(new PostgresQuery("a", 0, 20, "SELECT id, tags, geom FROM table WHERE condition = 1"), new PostgresQuery("b", 0, 20, "SELECT id, tags, geom FROM table WHERE condition = 2"));
PostgresTileStore tileStore = new PostgresTileStore(null, queries);
String query = tileStore.withQuery(new Tile(0, 0, 10));
assertEquals("with ha14cb45b as (select * from table where ((condition = 1) OR (condition = 2)) and st_intersects(geom, st_tileenvelope(10, 0, 0))) select st_asmvt(target, 'a', 4096, 'geom', 'id') from (select id as id, (tags || jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b where condition = 1) as target union all select st_asmvt(target, 'b', 4096, 'geom', 'id') from (select id as id, (tags || jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b where condition = 2) as target", query);
}
use of com.baremaps.tile.Tile in project baremaps by baremaps.
the class PostgresTileStoreTest method differentConditions1.
@Test
void differentConditions1() {
List<PostgresQuery> queries = Arrays.asList(new PostgresQuery("a", 0, 20, "SELECT id, tags, geom FROM table"), new PostgresQuery("b", 0, 20, "SELECT id, tags, geom FROM table WHERE condition = 1"));
PostgresTileStore tileStore = new PostgresTileStore(null, queries);
String query = tileStore.withQuery(new Tile(0, 0, 10));
assertEquals("with ha14cb45b as (select * from table where ((true) OR (condition = 1)) and st_intersects(geom, st_tileenvelope(10, 0, 0))) select st_asmvt(target, 'a', 4096, 'geom', 'id') from (select id as id, (tags || jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b ) as target union all select st_asmvt(target, 'b', 4096, 'geom', 'id') from (select id as id, (tags || jsonb_build_object('geometry', lower(replace(st_geometrytype(geom), 'ST_', '')))) as tags, st_asmvtgeom(geom, st_tileenvelope(10, 0, 0), 4096, 256, true) as geom from ha14cb45b where condition = 1) as target", query);
}
Aggregations