diff --git a/docs/desktop.md b/docs/desktop.md index b5e5f1eed..2a9b72d2a 100644 --- a/docs/desktop.md +++ b/docs/desktop.md @@ -2,18 +2,19 @@ To run the desktop samples can use the Gradle `run` task. -e.g. for `vtm-playground` can change the [mainClassName](../vtm-playground/build.gradle) to run each sample and pass args: -```groovy -./gradlew :vtm-playground:run -Pargs=/path/to/map +For `vtm-playground` can change the main class in `build.gradle` and pass args: +``` +./gradlew :vtm-playground:run -Pargs=/path/to/theme,/path/to/hgt,/path/to/map1,/path/to/map2 ``` -To create a standalone executable jar, adapt the main class in [build gradle](../vtm-playground/build.gradle), then run: -```groovy +To create a standalone executable jar, change the main class in `build gradle` and run: +``` ./gradlew :vtm-playground:fatJar ``` The jar file can be found in `build/libs` folder. Depending on the main class, pass args on execution via command line: ``` -java -jar vtm-playground-master-SNAPSHOT-jar-with-dependencies.jar /path/to/map +java -jar vtm-playground-master-SNAPSHOT-jar-with-dependencies.jar /path/to/theme /path/to/hgt /path/to/map1 /path/to/map2 ``` +The theme file and SRTM hgt folder are optional arguments. To change the libGDX backend can replace the dependency: `vtm-desktop-lwjgl` or `vtm-desktop-lwjgl3`. diff --git a/vtm-playground/src/org/oscim/test/MapsforgePoi3DTest.java b/vtm-playground/src/org/oscim/test/MapsforgePoi3DTest.java index 0b52591ee..0947671bd 100644 --- a/vtm-playground/src/org/oscim/test/MapsforgePoi3DTest.java +++ b/vtm-playground/src/org/oscim/test/MapsforgePoi3DTest.java @@ -23,19 +23,23 @@ public class MapsforgePoi3DTest extends MapsforgeTest { - private MapsforgePoi3DTest(File demFolder, List mapFiles) { - super(demFolder, mapFiles, false, true); + private MapsforgePoi3DTest(File demFolder, List mapFiles, File themeFile) { + super(demFolder, mapFiles, false, true, themeFile); } /** * @param args command line args: expects the map files as multiple parameters - * with possible SRTM hgt folder as 1st argument. + * with possible theme file as 1st argument + * and possible SRTM hgt folder as 2nd argument. */ public static void main(String[] args) { GdxMapApp.init(); + File themeFile = getThemeFile(args); + if (themeFile != null) + args = Arrays.copyOfRange(args, 1, args.length); File demFolder = getDemFolder(args); if (demFolder != null) args = Arrays.copyOfRange(args, 1, args.length); - GdxMapApp.run(new MapsforgePoi3DTest(demFolder, getMapFiles(args))); + GdxMapApp.run(new MapsforgePoi3DTest(demFolder, getMapFiles(args), themeFile)); } } diff --git a/vtm-playground/src/org/oscim/test/MapsforgeS3DBTest.java b/vtm-playground/src/org/oscim/test/MapsforgeS3DBTest.java index 03fd15171..7830ff3e2 100644 --- a/vtm-playground/src/org/oscim/test/MapsforgeS3DBTest.java +++ b/vtm-playground/src/org/oscim/test/MapsforgeS3DBTest.java @@ -22,19 +22,23 @@ public class MapsforgeS3DBTest extends MapsforgeTest { - private MapsforgeS3DBTest(File demFolder, List mapFiles) { - super(demFolder, mapFiles, true, false); + private MapsforgeS3DBTest(File demFolder, List mapFiles, File themeFile) { + super(demFolder, mapFiles, true, false, themeFile); } /** * @param args command line args: expects the map files as multiple parameters - * with possible SRTM hgt folder as 1st argument. + * with possible theme file as 1st argument + * and possible SRTM hgt folder as 2nd argument. */ public static void main(String[] args) { GdxMapApp.init(); + File themeFile = getThemeFile(args); + if (themeFile != null) + args = Arrays.copyOfRange(args, 1, args.length); File demFolder = getDemFolder(args); if (demFolder != null) args = Arrays.copyOfRange(args, 1, args.length); - GdxMapApp.run(new MapsforgeS3DBTest(demFolder, getMapFiles(args))); + GdxMapApp.run(new MapsforgeS3DBTest(demFolder, getMapFiles(args), themeFile)); } } diff --git a/vtm-playground/src/org/oscim/test/MapsforgeStyleTest.java b/vtm-playground/src/org/oscim/test/MapsforgeStyleTest.java index 9b3413aa2..22f4c0852 100644 --- a/vtm-playground/src/org/oscim/test/MapsforgeStyleTest.java +++ b/vtm-playground/src/org/oscim/test/MapsforgeStyleTest.java @@ -28,8 +28,8 @@ public class MapsforgeStyleTest extends MapsforgeTest { - private MapsforgeStyleTest(File demFolder, List mapFiles) { - super(demFolder, mapFiles); + private MapsforgeStyleTest(File demFolder, List mapFiles, File themeFile) { + super(demFolder, mapFiles, themeFile); } @Override @@ -81,13 +81,17 @@ protected boolean onKeyDown(int keycode) { /** * @param args command line args: expects the map files as multiple parameters - * with possible SRTM hgt folder as 1st argument. + * with possible theme file as 1st argument + * and possible SRTM hgt folder as 2nd argument. */ public static void main(String[] args) { GdxMapApp.init(); + File themeFile = getThemeFile(args); + if (themeFile != null) + args = Arrays.copyOfRange(args, 1, args.length); File demFolder = getDemFolder(args); if (demFolder != null) args = Arrays.copyOfRange(args, 1, args.length); - GdxMapApp.run(new MapsforgeStyleTest(demFolder, getMapFiles(args))); + GdxMapApp.run(new MapsforgeStyleTest(demFolder, getMapFiles(args), themeFile)); } } diff --git a/vtm-playground/src/org/oscim/test/MapsforgeTest.java b/vtm-playground/src/org/oscim/test/MapsforgeTest.java index 0812a6447..38d5338b2 100644 --- a/vtm-playground/src/org/oscim/test/MapsforgeTest.java +++ b/vtm-playground/src/org/oscim/test/MapsforgeTest.java @@ -38,16 +38,14 @@ import org.oscim.renderer.ExtrusionRenderer; import org.oscim.renderer.GLViewport; import org.oscim.scalebar.*; +import org.oscim.theme.ExternalRenderTheme; import org.oscim.theme.internal.VtmThemes; import org.oscim.tiling.source.hills.HillshadingTileSource; import org.oscim.tiling.source.mapfile.MapFileTileSource; import org.oscim.tiling.source.mapfile.MultiMapFileTileSource; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.List; +import java.util.*; public class MapsforgeTest extends GdxMapApp { @@ -57,16 +55,18 @@ public class MapsforgeTest extends GdxMapApp { private final List mapFiles; private final boolean poi3d; private final boolean s3db; + private final File themeFile; - MapsforgeTest(File demFolder, List mapFiles) { - this(demFolder, mapFiles, false, false); + MapsforgeTest(File demFolder, List mapFiles, File themeFile) { + this(demFolder, mapFiles, false, false, themeFile); } - MapsforgeTest(File demFolder, List mapFiles, boolean s3db, boolean poi3d) { + MapsforgeTest(File demFolder, List mapFiles, boolean s3db, boolean poi3d, File themeFile) { this.demFolder = demFolder; this.mapFiles = mapFiles; this.s3db = s3db; this.poi3d = poi3d; + this.themeFile = themeFile; } @Override @@ -186,19 +186,35 @@ static List getMapFiles(String[] args) { return result; } + static File getThemeFile(String[] args) { + if (args.length == 0) { + throw new IllegalArgumentException("missing argument: "); + } + + File themeFile = new File(args[0]); + if (themeFile.exists() && themeFile.isFile() && themeFile.canRead() && themeFile.getName().toLowerCase(Locale.ROOT).endsWith(".xml")) { + return themeFile; + } + return null; + } + void loadTheme(final String styleId) { - mMap.setTheme(VtmThemes.MOTORIDER); + mMap.setTheme(themeFile != null ? new ExternalRenderTheme(themeFile.getAbsolutePath()) : VtmThemes.MOTORIDER); } /** * @param args command line args: expects the map files as multiple parameters - * with possible SRTM hgt folder as 1st argument. + * with possible theme file as 1st argument + * and possible SRTM hgt folder as 2nd argument. */ public static void main(String[] args) { GdxMapApp.init(); + File themeFile = getThemeFile(args); + if (themeFile != null) + args = Arrays.copyOfRange(args, 1, args.length); File demFolder = getDemFolder(args); if (demFolder != null) args = Arrays.copyOfRange(args, 1, args.length); - GdxMapApp.run(new MapsforgeTest(demFolder, getMapFiles(args))); + GdxMapApp.run(new MapsforgeTest(demFolder, getMapFiles(args), themeFile)); } }