import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
+import org.simantics.district.maps.server.prefs.MapsServerPreferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
private SystemProcess process;
private Path serverRoot;
- private int port;
private AtomicBoolean running = new AtomicBoolean(false);
- TileserverMapnik(Path serverRoot, int port) {
+ TileserverMapnik(Path serverRoot) {
this.serverRoot = serverRoot.normalize();
- this.port = port;
- }
-
- public void setPort(int port) {
- this.port = port;
}
public boolean isRunning() throws IOException, InterruptedException {
return;
StartedProcess startedProcess = new ProcessExecutor().directory(serverRoot.resolve("tileserver-mapnik").toFile()).destroyOnExit().environment(getEnv())
- .command(NodeJS.executable().toString(), getTessera().toString(), "-c", getConfigJson().toString())
+ .command(NodeJS.executable().toString(), getTessera().toString(), "-c", getConfigJson().toString(), "-p", Integer.toString(MapsServerPreferences.defaultPort()))
.redirectOutput(Slf4jStream.ofCaller().asDebug()).start();
Process nativeProcess = startedProcess.getProcess();
}
public List<String> availableMBTiles() throws IOException {
- Path data = serverRoot.resolve("data").toAbsolutePath();
+ Path data = getDataDirectory();
List<String> result = new ArrayList<>();
try (Stream<Path> paths = Files.walk(data)) {
paths.forEach(p -> {
private void checkConfigJson() throws JsonParseException, JsonMappingException, IOException {
Path configJson = getConfigJson();
Map<String, Object> config = new HashMap<>();
- Path tm2 = serverRoot.resolve("tm2").toAbsolutePath();
+ Path tm2 = getStyleDirectory();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tm2)) {
stream.forEach(p -> {
Path projectYaml = p.resolve("project.yml");
mapper.writerWithDefaultPrettyPrinter().writeValue(Files.newOutputStream(configJson, StandardOpenOption.TRUNCATE_EXISTING), config);
}
+ public Path getStyleDirectory() {
+ return serverRoot.resolve("tm2");
+ }
+
+ public Path getDataDirectory() {
+ return serverRoot.resolve("data");
+ }
+
+ public Path getCurrentTiles() {
+ return getDataDirectory().resolve(MapsServerPreferences.currentMBTiles());
+ }
+
public void checkTm2Styles() {
- Path tm2 = serverRoot.resolve("tm2").toAbsolutePath();
+ Path tm2 = getStyleDirectory();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tm2)) {
stream.forEach(p -> {
Path projectYaml = p.resolve("project.yml");
try (InputStream input = Files.newInputStream(projectYaml, StandardOpenOption.READ)) {
data = yaml.loadAs(input, Map.class);
- Path tiles = serverRoot.relativize(serverRoot.resolve("data").resolve("helsinki_finland.mbtiles"));//.toAbsolutePath().toString().replace("\\", "/");
-
+ Path tiles = serverRoot.relativize(getCurrentTiles());
String tmStyle = "mbtiles://../" + tiles.toString();
data.put("source", tmStyle);
public List<String> listStyles() throws IOException {
List<String> results = new ArrayList<>();
- Path tm2 = serverRoot.resolve("tm2").toAbsolutePath();
+ Path tm2 = getStyleDirectory();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tm2)) {
stream.forEach(p -> {
results.add(p.getFileName().toString());