2020import org .mapsforge .core .model .Point ;
2121import org .mapsforge .core .util .LatLongUtils ;
2222import org .mapsforge .map .awt .graphics .AwtGraphicFactory ;
23- import org .mapsforge .map .awt .util .JavaPreferences ;
2423import org .mapsforge .map .awt .view .MapView ;
2524import org .mapsforge .map .datastore .MapDataStore ;
2625import org .mapsforge .map .datastore .MultiMapDataStore ;
3534import org .mapsforge .map .layer .download .tilesource .OpenStreetMapMapnik ;
3635import org .mapsforge .map .layer .download .tilesource .TileSource ;
3736import org .mapsforge .map .layer .renderer .TileRendererLayer ;
38- import org .mapsforge .map .model .IMapViewPosition ;
37+ import org .mapsforge .map .model .MapViewPosition ;
3938import org .mapsforge .map .model .Model ;
40- import org .mapsforge .map .model .common .PreferencesFacade ;
4139import org .mapsforge .map .reader .MapFile ;
42- import org .mapsforge .map .rendertheme .InternalRenderTheme ;
40+ import org .mapsforge .map .rendertheme .internal . MapsforgeThemes ;
4341
4442public final class MapsforgeSimpleViewer {
4543 private static final GraphicFactory GRAPHIC_FACTORY = AwtGraphicFactory .INSTANCE ;
@@ -48,15 +46,18 @@ public final class MapsforgeSimpleViewer {
4846
4947 private static final String MESSAGE = "Are you sure you want to exit the application?" ;
5048 private static final String TITLE = "Confirm close" ;
51-
49+ private static final String LATITUDE = "latitude" ;
50+ private static final String LONGITUDE = "longitude" ;
51+ private static final String ZOOM_LEVEL = "zoomLevel" ;
52+
5253 public static void main ( String [] args ) {
5354 File mapFile = new File (
54- "/home/hydrologis/data/mapsforge /italy.map" );
55+ "/home/hydrologis/Documents/smash/maps /italy.map" );
5556 List <File > mapFiles = Arrays .asList (mapFile );
5657 final MapView mapView = createMapView ();
5758 final BoundingBox boundingBox = addLayers (mapView , mapFiles );
5859
59- final PreferencesFacade preferencesFacade = new JavaPreferences (Preferences .userNodeForPackage (MapsforgeSimpleViewer .class ));
60+ final JavaPreferences preferences = new JavaPreferences (Preferences .userNodeForPackage (MapsforgeSimpleViewer .class ));
6061
6162 final JFrame frame = new JFrame ();
6263 frame .setTitle ("Mapsforge Simple Viewer" );
@@ -70,7 +71,10 @@ public static void main( String[] args ) {
7071 public void windowClosing ( WindowEvent e ) {
7172 int result = JOptionPane .showConfirmDialog (frame , MESSAGE , TITLE , JOptionPane .YES_NO_OPTION );
7273 if (result == JOptionPane .YES_OPTION ) {
73- mapView .getModel ().save (preferencesFacade );
74+ final MapViewPosition mapViewPosition = mapView .getModel ().mapViewPosition ;
75+ preferences .putDouble (LATITUDE , mapViewPosition .getCenter ().latitude );
76+ preferences .putDouble (LONGITUDE , mapViewPosition .getCenter ().longitude );
77+ preferences .putByte (ZOOM_LEVEL , mapViewPosition .getZoomLevel ());
7478 mapView .destroyAll ();
7579 AwtGraphicFactory .clearResourceMemoryCache ();
7680 frame .setDefaultCloseOperation (WindowConstants .EXIT_ON_CLOSE );
@@ -80,11 +84,14 @@ public void windowClosing( WindowEvent e ) {
8084 @ Override
8185 public void windowOpened ( WindowEvent e ) {
8286 final Model model = mapView .getModel ();
83- model .init (preferencesFacade );
87+ double latitude = preferences .getDouble (LATITUDE , 0 );
88+ double longitude = preferences .getDouble (LONGITUDE , 0 );
89+ byte zoomLevel = preferences .getByte (ZOOM_LEVEL , (byte ) 0 );
90+ mapView .getModel ().mapViewPosition .setMapPosition (new MapPosition (new LatLong (latitude , longitude ), zoomLevel ));
8491 if (model .mapViewPosition .getZoomLevel () == 0 || !boundingBox .contains (model .mapViewPosition .getCenter ())) {
85- byte zoomLevel = LatLongUtils .zoomForBounds (model .mapViewDimension .getDimension (), boundingBox ,
92+ byte zoomForBounds = LatLongUtils .zoomForBounds (model .mapViewDimension .getDimension (), boundingBox ,
8693 model .displayModel .getTileSize ());
87- model .mapViewPosition .setMapPosition (new MapPosition (boundingBox .getCenterPoint (), zoomLevel ));
94+ model .mapViewPosition .setMapPosition (new MapPosition (boundingBox .getCenterPoint (), zoomForBounds ));
8895 }
8996 }
9097 });
@@ -146,7 +153,7 @@ private static MapView createMapView() {
146153 }
147154
148155 @ SuppressWarnings ("unused" )
149- private static TileDownloadLayer createTileDownloadLayer ( TileCache tileCache , IMapViewPosition mapViewPosition ,
156+ private static TileDownloadLayer createTileDownloadLayer ( TileCache tileCache , MapViewPosition mapViewPosition ,
150157 TileSource tileSource ) {
151158 return new TileDownloadLayer (tileCache , mapViewPosition , tileSource , GRAPHIC_FACTORY ){
152159 @ Override
@@ -158,7 +165,7 @@ public boolean onTap( LatLong tapLatLong, Point layerXY, Point tapXY ) {
158165 }
159166
160167 private static TileRendererLayer createTileRendererLayer ( TileCache tileCache , MapDataStore mapDataStore ,
161- IMapViewPosition mapViewPosition ) {
168+ MapViewPosition mapViewPosition ) {
162169 TileRendererLayer tileRendererLayer = new TileRendererLayer (tileCache , mapDataStore , mapViewPosition , false , true , false ,
163170 GRAPHIC_FACTORY ){
164171 @ Override
@@ -167,7 +174,7 @@ public boolean onTap( LatLong tapLatLong, Point layerXY, Point tapXY ) {
167174 return true ;
168175 }
169176 };
170- tileRendererLayer .setXmlRenderTheme (InternalRenderTheme .DEFAULT );
177+ tileRendererLayer .setXmlRenderTheme (MapsforgeThemes .DEFAULT );
171178 return tileRendererLayer ;
172179 }
173180
0 commit comments