Search in sources :

Example 1 with TileJSON

use of com.baremaps.model.TileJSON in project baremaps by baremaps.

the class Init method call.

@Override
public Integer call() throws BlobStoreException, IOException {
    BlobStore blobStore = options.blobStore();
    ObjectMapper mapper = defaultObjectMapper();
    if (style != null) {
        MbStyle styleObject = new MbStyle();
        styleObject.setName("Baremaps");
        MbStyleSources sources = new MbStyleSources();
        sources.setType("vector");
        sources.setUrl("http://localhost:9000/tiles.json");
        styleObject.setSources(Map.of("baremaps", sources));
        blobStore.put(style, Blob.builder().withByteArray(mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(styleObject)).build());
        logger.info("Style initialized: {}", style);
    }
    if (tileset != null) {
        TileJSON tilesetObject = new TileJSON();
        tilesetObject.setTilejson("2.2.0");
        tilesetObject.setName("Baremaps");
        tilesetObject.setTiles(Arrays.asList("http://localhost:9000/tiles.json"));
        blobStore.put(tileset, Blob.builder().withByteArray(mapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(tilesetObject)).build());
        logger.info("Tileset initialized: {}", tileset);
    }
    return 0;
}
Also used : MbStyleSources(com.baremaps.model.MbStyleSources) TileJSON(com.baremaps.model.TileJSON) BlobStore(com.baremaps.blob.BlobStore) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MbStyle(com.baremaps.model.MbStyle)

Example 2 with TileJSON

use of com.baremaps.model.TileJSON 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 TileJSON

use of com.baremaps.model.TileJSON 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)

Example 4 with TileJSON

use of com.baremaps.model.TileJSON in project baremaps by baremaps.

the class TilesetsResourceIntegrationTest method test.

@Test
public void test() {
    // List the tilesets
    List<UUID> ids = target().path("/tilesets").request().get(new GenericType<>() {
    });
    assertEquals(0, ids.size());
    // Create a new tileset with the service
    TileJSON tileSet = new TileJSON();
    tileSet.setName("test");
    target().path("/tilesets").request(MediaType.APPLICATION_JSON).post(Entity.json(tileSet));
    // List the tilesets
    ids = target().path("/tilesets").request().get(new GenericType<>() {
    });
    assertEquals(1, ids.size());
    // Get the tileset
    UUID id = ids.get(0);
    tileSet = target().path("/tilesets/" + id).request().get(TileJSON.class);
    assertEquals("test", tileSet.getName());
    // Delete the tileset
    target().path("/tilesets/" + ids.get(0)).request().delete();
    // List the tilesets
    ids = target().path("/tilesets").request().get(new GenericType<>() {
    });
    assertEquals(0, ids.size());
}
Also used : GenericType(javax.ws.rs.core.GenericType) TileJSON(com.baremaps.model.TileJSON) UUID(java.util.UUID) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 5 with TileJSON

use of com.baremaps.model.TileJSON in project baremaps by baremaps.

the class Export method call.

@Override
public Integer call() throws TileStoreException, BlobStoreException, IOException {
    ObjectMapper mapper = defaultObjectMapper();
    DataSource datasource = PostgresUtils.datasource(database);
    BlobStore blobStore = options.blobStore();
    TileJSON source = mapper.readValue(blobStore.get(this.tileset).getInputStream(), TileJSON.class);
    TileStore tileSource = sourceTileStore(source, datasource);
    TileStore tileTarget = targetTileStore(source, blobStore);
    Stream<Tile> stream;
    if (tiles == null) {
        Envelope envelope = new Envelope(source.getBounds().get(0), source.getBounds().get(2), source.getBounds().get(1), source.getBounds().get(3));
        long count = Tile.count(envelope, source.getMinzoom(), source.getMaxzoom());
        stream = StreamUtils.stream(Tile.iterator(envelope, source.getMinzoom(), source.getMaxzoom())).peek(new StreamProgress<>(count, 5000));
    } else {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(blobStore.get(tiles).getInputStream()))) {
            stream = reader.lines().flatMap(line -> {
                String[] array = line.split(",");
                int x = Integer.parseInt(array[0]);
                int y = Integer.parseInt(array[1]);
                int z = Integer.parseInt(array[2]);
                Tile tile = new Tile(x, y, z);
                return StreamUtils.stream(Tile.iterator(tile.envelope(), source.getMinzoom(), source.getMaxzoom()));
            });
        }
    }
    logger.info("Exporting tiles");
    StreamUtils.batch(stream, 10).filter(new TileBatchPredicate(batchArraySize, batchArrayIndex)).forEach(new TileChannel(tileSource, tileTarget));
    logger.info("Done");
    return 0;
}
Also used : DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) MBTiles(com.baremaps.tile.mbtiles.MBTiles) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Conversions.asPostgresQuery(com.baremaps.server.ogcapi.Conversions.asPostgresQuery) TileBatchPredicate(com.baremaps.tile.TileBatchPredicate) BigDecimal(java.math.BigDecimal) TileChannel(com.baremaps.tile.TileChannel) Map(java.util.Map) DataSource(javax.sql.DataSource) TileStore(com.baremaps.tile.TileStore) URI(java.net.URI) Command(picocli.CommandLine.Command) SQLiteDataSource(org.sqlite.SQLiteDataSource) PostgresUtils(com.baremaps.postgres.jdbc.PostgresUtils) BlobStoreException(com.baremaps.blob.BlobStoreException) Query(com.baremaps.model.Query) PostgresQuery(com.baremaps.tile.postgres.PostgresQuery) Logger(org.slf4j.Logger) TileJSON(com.baremaps.model.TileJSON) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) Mixin(picocli.CommandLine.Mixin) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) TileBlobStore(com.baremaps.tile.TileBlobStore) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) TileStoreException(com.baremaps.tile.TileStoreException) List(java.util.List) Option(picocli.CommandLine.Option) Stream(java.util.stream.Stream) Tile(com.baremaps.tile.Tile) StreamUtils(com.baremaps.stream.StreamUtils) BlobStore(com.baremaps.blob.BlobStore) StreamProgress(com.baremaps.osm.progress.StreamProgress) BufferedReader(java.io.BufferedReader) Envelope(org.locationtech.jts.geom.Envelope) TileStore(com.baremaps.tile.TileStore) PostgresTileStore(com.baremaps.tile.postgres.PostgresTileStore) InputStreamReader(java.io.InputStreamReader) Tile(com.baremaps.tile.Tile) Envelope(org.locationtech.jts.geom.Envelope) StreamProgress(com.baremaps.osm.progress.StreamProgress) DataSource(javax.sql.DataSource) SQLiteDataSource(org.sqlite.SQLiteDataSource) TileChannel(com.baremaps.tile.TileChannel) TileJSON(com.baremaps.model.TileJSON) BufferedReader(java.io.BufferedReader) TileBatchPredicate(com.baremaps.tile.TileBatchPredicate) DefaultObjectMapper.defaultObjectMapper(com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TileBlobStore(com.baremaps.tile.TileBlobStore) BlobStore(com.baremaps.blob.BlobStore)

Aggregations

TileJSON (com.baremaps.model.TileJSON)5 BlobStore (com.baremaps.blob.BlobStore)3 DefaultObjectMapper.defaultObjectMapper (com.baremaps.server.common.DefaultObjectMapper.defaultObjectMapper)3 TileStore (com.baremaps.tile.TileStore)3 PostgresQuery (com.baremaps.tile.postgres.PostgresQuery)3 PostgresTileStore (com.baremaps.tile.postgres.PostgresTileStore)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataSource (javax.sql.DataSource)3 Conversions.asPostgresQuery (com.baremaps.server.ogcapi.Conversions.asPostgresQuery)2 Tile (com.baremaps.tile.Tile)2 TileStoreException (com.baremaps.tile.TileStoreException)2 URI (java.net.URI)2 List (java.util.List)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 TilesetsApi (com.baremaps.api.TilesetsApi)1 BlobStoreException (com.baremaps.blob.BlobStoreException)1 MbStyle (com.baremaps.model.MbStyle)1