Search in sources :

Example 1 with PostgresTileStore

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();
    }
}
Also used : TileStore(com.baremaps.tile.TileStore) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Blob(com.baremaps.blob.Blob) Conversions.asPostgresQuery(com.baremaps.server.ogcapi.Conversions.asPostgresQuery) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Tile(com.baremaps.tile.Tile) BlobStoreException(com.baremaps.blob.BlobStoreException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) GET(javax.ws.rs.GET)

Example 2 with PostgresTileStore

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;
}
Also used : CorsFilter(com.baremaps.server.common.CorsFilter) TileStore(com.baremaps.tile.TileStore) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Conversions.asPostgresQuery(com.baremaps.server.ogcapi.Conversions.asPostgresQuery) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) CaffeineSpec(com.github.benmanes.caffeine.cache.CaffeineSpec) DataSource(javax.sql.DataSource) HttpJerseyRouterBuilder(io.servicetalk.http.router.jersey.HttpJerseyRouterBuilder) BlockingStreamingHttpService(io.servicetalk.http.api.BlockingStreamingHttpService) ServerContext(io.servicetalk.transport.api.ServerContext) TileJSON(com.baremaps.model.TileJSON) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) TileCache(com.baremaps.tile.TileCache) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BlobStore(com.baremaps.blob.BlobStore)

Example 3 with PostgresTileStore

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);
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) Logger(org.slf4j.Logger) TileJSON(com.baremaps.model.TileJSON) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) LoggerFactory(org.slf4j.LoggerFactory) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TileStoreException(com.baremaps.tile.TileStoreException) Json(org.jdbi.v3.json.Json) Inject(javax.inject.Inject) TilesetsApi(com.baremaps.api.TilesetsApi) List(java.util.List) CONTENT_ENCODING(com.google.common.net.HttpHeaders.CONTENT_ENCODING) Response(javax.ws.rs.core.Response) Tile(com.baremaps.tile.Tile) DataSource(javax.sql.DataSource) TileStore(com.baremaps.tile.TileStore) URI(java.net.URI) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) TileJSON(com.baremaps.model.TileJSON) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore)

Aggregations

TileStore (com.baremaps.tile.TileStore)3 PostgresQuery (com.baremaps.tile.postgres.PostgresQuery)3 PostgresTileStore (com.baremaps.tile.postgres.PostgresTileStore)3 TileJSON (com.baremaps.model.TileJSON)2 Conversions.asPostgresQuery (com.baremaps.server.ogcapi.Conversions.asPostgresQuery)2 Tile (com.baremaps.tile.Tile)2 DataSource (javax.sql.DataSource)2 TilesetsApi (com.baremaps.api.TilesetsApi)1 Blob (com.baremaps.blob.Blob)1 BlobStore (com.baremaps.blob.BlobStore)1 BlobStoreException (com.baremaps.blob.BlobStoreException)1 CorsFilter (com.baremaps.server.common.CorsFilter)1 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)1 TileCache (com.baremaps.tile.TileCache)1 TileStoreException (com.baremaps.tile.TileStoreException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 CaffeineSpec (com.github.benmanes.caffeine.cache.CaffeineSpec)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1