Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a first experiment with 3d tiles #569

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .run/tdtiles-create.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="tdtiles-create" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="workflow execute --file workflow.json" />
<option name="WORKING_DIRECTORY" value="examples/tdtiles" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
11 changes: 11 additions & 0 deletions .run/tdtiles-dev.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="tdtiles-dev" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="tdtiles serve --database jdbc:postgresql://localhost:5432/baremaps?user=baremaps&amp;password=baremaps --log-level DEBUG" />
<option name="WORKING_DIRECTORY" value="examples/tdtiles" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
11 changes: 11 additions & 0 deletions .run/tdtiles-serve.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="tdtiles-serve" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="tdtiles serve --database jdbc:postgresql://localhost:5432/baremaps?user=baremaps&amp;password=baremaps" />
<option name="WORKING_DIRECTORY" value="examples/tdtiles" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.baremaps.cli.geocoder.Geocoder;
import org.apache.baremaps.cli.iploc.IpLoc;
import org.apache.baremaps.cli.map.Map;
import org.apache.baremaps.cli.tdtiles.TdTiles;
import org.apache.baremaps.cli.workflow.Workflow;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
Expand All @@ -38,7 +39,7 @@

@Command(name = "baremaps", description = "A toolkit for producing vector tiles.",
versionProvider = VersionProvider.class, subcommands = {Workflow.class, Database.class,
Map.class, Geocoder.class, IpLoc.class},
Map.class, TdTiles.class, Geocoder.class, IpLoc.class},
sortOptions = false)
public class Baremaps implements Callable<Integer> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.baremaps.cli.tdtiles;



import static org.apache.baremaps.utils.ObjectMapperUtils.objectMapper;

import com.linecorp.armeria.common.HttpHeaderNames;
import com.linecorp.armeria.common.HttpMethod;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.annotation.JacksonResponseConverterFunction;
import com.linecorp.armeria.server.cors.CorsService;
import com.linecorp.armeria.server.file.FileService;
import com.linecorp.armeria.server.file.HttpFile;
import java.util.concurrent.Callable;
import org.apache.baremaps.cli.Options;
import org.apache.baremaps.server.TdTilesResources;
import org.apache.baremaps.utils.PostgresUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Option;

@Command(name = "serve", description = "Start a 3d tile server.")
public class Serve implements Callable<Integer> {

private static final Logger logger = LoggerFactory.getLogger(Serve.class);

@Mixin
private Options options;

@Option(names = {"--database"}, paramLabel = "DATABASE",
description = "The JDBC url of Postgres.", required = true)
private String database;

@Option(names = {"--host"}, paramLabel = "HOST", description = "The host of the server.")
private String host = "localhost";

@Option(names = {"--port"}, paramLabel = "PORT", description = "The port of the server.")
private int port = 9000;

@Override
public Integer call() throws Exception {
var objectMapper = objectMapper();
var datasource = PostgresUtils.createDataSource(database);

var serverBuilder = Server.builder();
serverBuilder.http(port);

var jsonResponseConverter = new JacksonResponseConverterFunction(objectMapper);
serverBuilder.annotatedService(new TdTilesResources(datasource), jsonResponseConverter);

var index = HttpFile.of(ClassLoader.getSystemClassLoader(), "/tdtiles/index.html");
serverBuilder.service("/", index.asService());
serverBuilder.serviceUnder("/", FileService.of(ClassLoader.getSystemClassLoader(), "/tdtiles"));

serverBuilder.decorator(CorsService.builderForAnyOrigin()
.allowRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE,
HttpMethod.OPTIONS, HttpMethod.HEAD)
.allowRequestHeaders(HttpHeaderNames.ORIGIN, HttpHeaderNames.CONTENT_TYPE,
HttpHeaderNames.ACCEPT, HttpHeaderNames.AUTHORIZATION)
.allowCredentials()
.exposeHeaders(HttpHeaderNames.LOCATION)
.newDecorator());

serverBuilder.disableServerHeader();
serverBuilder.disableDateHeader();

var server = serverBuilder.build();

var startFuture = server.start();
startFuture.join();

var shutdownFuture = server.closeOnJvmShutdown();
shutdownFuture.join();

return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.baremaps.cli.tdtiles;



import picocli.CommandLine;
import picocli.CommandLine.Command;

@Command(name = "tdtiles", description = "3d Tiles commands.", subcommands = {Serve.class},
sortOptions = false)
public class TdTiles implements Runnable {

@Override
public void run() {
CommandLine.usage(this, System.out);
}
}
9 changes: 9 additions & 0 deletions baremaps-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ limitations under the License.
<groupId>de.bytefish</groupId>
<artifactId>pgbulkinsert</artifactId>
</dependency>
<dependency>
<groupId>de.javagl</groupId>
<artifactId>jgltf-model</artifactId>
</dependency>
<dependency>
<groupId>de.javagl</groupId>
<artifactId>jgltf-model-builder</artifactId>
<version>${version.lib.jgltf}</version>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
Expand Down
Loading