From 314c2df66b89de503738f3c1cd7dbce81ef436c3 Mon Sep 17 00:00:00 2001 From: Emux Date: Sun, 26 Jun 2016 11:32:00 +0300 Subject: [PATCH] Samples: map file as command-line argument in MapsforgeTest, #32 --- .../src/org/oscim/test/MapsforgeTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vtm-playground/src/org/oscim/test/MapsforgeTest.java b/vtm-playground/src/org/oscim/test/MapsforgeTest.java index 468592e1..5efa76c6 100644 --- a/vtm-playground/src/org/oscim/test/MapsforgeTest.java +++ b/vtm-playground/src/org/oscim/test/MapsforgeTest.java @@ -27,12 +27,16 @@ import org.oscim.theme.VtmThemes; import org.oscim.tiling.source.mapfile.MapFileTileSource; import org.oscim.tiling.source.mapfile.MapInfo; +import java.io.File; + public class MapsforgeTest extends GdxMap { + private static File mapFile; + @Override public void createLayers() { MapFileTileSource tileSource = new MapFileTileSource(); - tileSource.setMapFile(System.getProperty("user.home") + "/Downloads/berlin.map"); + tileSource.setMapFile(mapFile.getAbsolutePath()); tileSource.setPreferredLanguage("en"); VectorTileLayer l = mMap.setBaseMap(tileSource); @@ -47,7 +51,25 @@ public class MapsforgeTest extends GdxMap { mMap.setMapPosition(pos); } + private static File getMapFile(String[] args) { + if (args.length == 0) { + throw new IllegalArgumentException("missing argument: "); + } + + File file = new File(args[0]); + if (!file.exists()) { + throw new IllegalArgumentException("file does not exist: " + file); + } else if (!file.isFile()) { + throw new IllegalArgumentException("not a file: " + file); + } else if (!file.canRead()) { + throw new IllegalArgumentException("cannot read file: " + file); + } + return file; + } + public static void main(String[] args) { + mapFile = getMapFile(args); + GdxMapApp.init(); GdxMapApp.run(new MapsforgeTest(), null, 400); }