Samples Desktop: remember map position #32

This commit is contained in:
Emux 2018-03-22 10:04:35 +02:00
parent fed0996f6f
commit 0137d9ff1f
No known key found for this signature in database
GPG Key ID: 89C6921D7AF2BDD0
8 changed files with 134 additions and 7 deletions

View File

@ -0,0 +1,52 @@
/*
* Copyright 2018 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 java.util.prefs.Preferences;
public final class MapPreferences {
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_SCALE = "scale";
private static Preferences INSTANCE;
private MapPreferences() {
}
private static Preferences getInstance() {
if (INSTANCE == null)
INSTANCE = Preferences.userRoot().node("vtm-playground");
return INSTANCE;
}
public static MapPosition getMapPosition() {
double latitude = getInstance().getDouble(KEY_LATITUDE, Double.NaN);
double longitude = getInstance().getDouble(KEY_LONGITUDE, Double.NaN);
double scale = getInstance().getDouble(KEY_SCALE, Double.NaN);
if (Double.isNaN(latitude) || Double.isNaN(longitude) || Double.isNaN(scale))
return null;
return new MapPosition(latitude, longitude, scale);
}
public static void saveMapPosition(MapPosition mapPosition) {
getInstance().putDouble(KEY_LATITUDE, mapPosition.getLatitude());
getInstance().putDouble(KEY_LONGITUDE, mapPosition.getLongitude());
getInstance().putDouble(KEY_SCALE, mapPosition.getScale());
}
}

View File

@ -77,12 +77,21 @@ public class MapsforgeTest extends GdxMapApp {
renderer.setOffset(5, 0);
mMap.layers().add(mapScaleBarLayer);
MapPosition pos = MapPreferences.getMapPosition();
MapInfo info = tileSource.getMapInfo();
MapPosition pos = new MapPosition();
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
if (pos == null || !info.boundingBox.contains(pos.getGeoPoint())) {
pos = new MapPosition();
pos.setByBoundingBox(info.boundingBox, Tile.SIZE * 4, Tile.SIZE * 4);
}
mMap.setMapPosition(pos);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
static File getMapFile(String[] args) {
if (args.length == 0) {
throw new IllegalArgumentException("missing argument: <mapFile>");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 devemux86
* Copyright 2017-2018 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
@ -14,6 +14,7 @@
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -56,6 +57,16 @@ public class MapzenGeojsonTest extends GdxMapApp {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapPosition pos = MapPreferences.getMapPosition();
if (pos != null)
mMap.setMapPosition(pos);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
public static void main(String[] args) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 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
@ -14,6 +14,7 @@
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -56,6 +57,16 @@ public class MapzenMvtTest extends GdxMapApp {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapPosition pos = MapPreferences.getMapPosition();
if (pos != null)
mMap.setMapPosition(pos);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
public static void main(String[] args) {

View File

@ -14,6 +14,7 @@
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -56,6 +57,16 @@ public class NextzenGeojsonTest extends GdxMapApp {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapPosition pos = MapPreferences.getMapPosition();
if (pos != null)
mMap.setMapPosition(pos);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
public static void main(String[] args) {

View File

@ -14,6 +14,7 @@
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -56,6 +57,16 @@ public class NextzenMvtTest extends GdxMapApp {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapPosition pos = MapPreferences.getMapPosition();
if (pos != null)
mMap.setMapPosition(pos);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
public static void main(String[] args) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 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
@ -14,6 +14,7 @@
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@ -56,6 +57,16 @@ public class OpenMapTilesMvtTest extends GdxMapApp {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
MapPosition pos = MapPreferences.getMapPosition();
if (pos != null)
mMap.setMapPosition(pos);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
public static void main(String[] args) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -16,6 +16,7 @@
*/
package org.oscim.test;
import org.oscim.core.MapPosition;
import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.GroupLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
@ -63,7 +64,17 @@ public class SimpleMapTest extends GdxMapApp {
map.layers().add(mapScaleBarLayer);
map.setTheme(VtmThemes.DEFAULT);
map.setMapPosition(53.075, 8.808, 1 << 17);
MapPosition pos = MapPreferences.getMapPosition();
if (pos != null)
map.setMapPosition(pos);
else
map.setMapPosition(53.075, 8.808, 1 << 17);
}
@Override
public void dispose() {
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}
public static void main(String[] args) {