Samples improvements

This commit is contained in:
Emux 2019-12-10 13:18:40 +02:00
parent 701ac43746
commit f7acfd9017
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
5 changed files with 51 additions and 121 deletions

View File

@ -1,84 +0,0 @@
/*
* Copyright 2016-2017 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.theme.VtmThemes;
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.List;
public class MapsforgeMultiTest extends GdxMapApp {
private final List<File> mapFiles;
private MapsforgeMultiTest(List<File> mapFiles) {
this.mapFiles = mapFiles;
}
@Override
public void createLayers() {
MultiMapFileTileSource tileSource = new MultiMapFileTileSource();
for (File mapFile : mapFiles) {
MapFileTileSource mapFileTileSource = new MapFileTileSource();
mapFileTileSource.setMapFile(mapFile.getAbsolutePath());
tileSource.add(mapFileTileSource);
}
//tileSource.setPreferredLanguage("en");
VectorTileLayer l = mMap.setBaseMap(tileSource);
mMap.setTheme(VtmThemes.DEFAULT);
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapPosition pos = new MapPosition();
pos.setByBoundingBox(tileSource.getBoundingBox(), Tile.SIZE * 4, Tile.SIZE * 4);
mMap.setMapPosition(pos);
}
private static List<File> getMapFiles(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("missing argument: <mapFile>");
}
List<File> result = new ArrayList<>();
for (String arg : args) {
File mapFile = new File(arg);
if (!mapFile.exists()) {
throw new IllegalArgumentException("file does not exist: " + mapFile);
} else if (!mapFile.isFile()) {
throw new IllegalArgumentException("not a file: " + mapFile);
} else if (!mapFile.canRead()) {
throw new IllegalArgumentException("cannot read file: " + mapFile);
}
result.add(mapFile);
}
return result;
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapsforgeMultiTest(getMapFiles(args)));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018 devemux86
* Copyright 2018-2019 devemux86
* Copyright 2018 Gustl22
*
* This program is free software: you can redistribute it and/or modify it under the
@ -18,15 +18,16 @@ package org.oscim.test;
import org.oscim.gdx.GdxMapApp;
import java.io.File;
import java.util.List;
public class MapsforgePoi3DTest extends MapsforgeTest {
private MapsforgePoi3DTest(File mapFile) {
super(mapFile, false, true);
private MapsforgePoi3DTest(List<File> mapFiles) {
super(mapFiles, false, true);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapsforgePoi3DTest(getMapFile(args)));
GdxMapApp.run(new MapsforgePoi3DTest(getMapFiles(args)));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018 devemux86
* Copyright 2018-2019 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -17,15 +17,16 @@ package org.oscim.test;
import org.oscim.gdx.GdxMapApp;
import java.io.File;
import java.util.List;
public class MapsforgeS3DBTest extends MapsforgeTest {
private MapsforgeS3DBTest(File mapFile) {
super(mapFile, true, false);
private MapsforgeS3DBTest(List<File> mapFiles) {
super(mapFiles, true, false);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapsforgeS3DBTest(getMapFile(args)));
GdxMapApp.run(new MapsforgeS3DBTest(getMapFiles(args)));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 devemux86
* Copyright 2016-2019 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -22,16 +22,17 @@ import org.oscim.theme.XmlRenderThemeStyleLayer;
import org.oscim.theme.XmlRenderThemeStyleMenu;
import java.io.File;
import java.util.List;
import java.util.Set;
public class MapsforgeStyleTest extends MapsforgeTest {
private MapsforgeStyleTest(File mapFile) {
super(mapFile);
private MapsforgeStyleTest(List<File> mapFiles) {
super(mapFiles);
}
@Override
protected void loadTheme(final String styleId) {
void loadTheme(final String styleId) {
mMap.setTheme(new StreamRenderTheme("", getClass().getResourceAsStream("/assets/vtm/stylemenu.xml"), new XmlRenderThemeMenuCallback() {
@Override
public Set<String> getCategories(XmlRenderThemeStyleMenu renderThemeStyleMenu) {
@ -79,6 +80,6 @@ public class MapsforgeStyleTest extends MapsforgeTest {
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapsforgeStyleTest(getMapFile(args)));
GdxMapApp.run(new MapsforgeStyleTest(getMapFiles(args)));
}
}

View File

@ -17,6 +17,7 @@
*/
package org.oscim.test;
import org.oscim.core.BoundingBox;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.event.Event;
@ -33,33 +34,39 @@ import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.*;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.mapfile.MapFileTileSource;
import org.oscim.tiling.source.mapfile.MapInfo;
import org.oscim.tiling.source.mapfile.MultiMapFileTileSource;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class MapsforgeTest extends GdxMapApp {
private static final boolean SHADOWS = false;
private File mapFile;
private boolean poi3d;
private boolean s3db;
private final List<File> mapFiles;
private final boolean poi3d;
private final boolean s3db;
MapsforgeTest(File mapFile) {
this(mapFile, false, false);
MapsforgeTest(List<File> mapFiles) {
this(mapFiles, false, false);
}
MapsforgeTest(File mapFile, boolean s3db, boolean poi3d) {
this.mapFile = mapFile;
MapsforgeTest(List<File> mapFiles, boolean s3db, boolean poi3d) {
this.mapFiles = mapFiles;
this.s3db = s3db;
this.poi3d = poi3d;
}
@Override
public void createLayers() {
MapFileTileSource tileSource = new MapFileTileSource();
tileSource.setMapFile(mapFile.getAbsolutePath());
MultiMapFileTileSource tileSource = new MultiMapFileTileSource();
for (File mapFile : mapFiles) {
MapFileTileSource mapFileTileSource = new MapFileTileSource();
mapFileTileSource.setMapFile(mapFile.getAbsolutePath());
tileSource.add(mapFileTileSource);
}
//tileSource.setPreferredLanguage("en");
VectorTileLayer l = mMap.setBaseMap(tileSource);
@ -86,10 +93,10 @@ public class MapsforgeTest extends GdxMapApp {
mMap.layers().add(mapScaleBarLayer);
MapPosition pos = MapPreferences.getMapPosition();
MapInfo info = tileSource.getMapInfo();
if (pos == null || !info.boundingBox.contains(pos.getGeoPoint())) {
BoundingBox bbox = tileSource.getBoundingBox();
if (pos == null || !bbox.contains(pos.getGeoPoint())) {
pos = new MapPosition();
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
pos.setByBoundingBox(bbox, Tile.SIZE * 4, Tile.SIZE * 4);
}
mMap.setMapPosition(pos);
@ -123,28 +130,32 @@ public class MapsforgeTest extends GdxMapApp {
super.dispose();
}
static File getMapFile(String[] args) {
static List<File> getMapFiles(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("missing argument: <mapFile>");
}
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);
List<File> result = new ArrayList<>();
for (String arg : args) {
File mapFile = new File(arg);
if (!mapFile.exists()) {
throw new IllegalArgumentException("file does not exist: " + mapFile);
} else if (!mapFile.isFile()) {
throw new IllegalArgumentException("not a file: " + mapFile);
} else if (!mapFile.canRead()) {
throw new IllegalArgumentException("cannot read file: " + mapFile);
}
result.add(mapFile);
}
return file;
return result;
}
protected void loadTheme(final String styleId) {
void loadTheme(final String styleId) {
mMap.setTheme(VtmThemes.DEFAULT);
}
public static void main(String[] args) {
GdxMapApp.init();
GdxMapApp.run(new MapsforgeTest(getMapFile(args)));
GdxMapApp.run(new MapsforgeTest(getMapFiles(args)));
}
}