use of com.baremaps.tile.postgres.PostgresTileStore 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.postgres.PostgresTileStore 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.postgres.PostgresTileStore 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