Last active
August 29, 2015 14:09
-
-
Save AAverin/989eef83077a6b0972f9 to your computer and use it in GitHub Desktop.
OpenScienceMap ExtendedMapView. Uses my custom preferences cache wrapper, just use your own implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExtendedMapView extends MapView { | |
private BaseContext baseContext; | |
public ExtendedMapView(Context context) { | |
super(context); | |
baseContext = (BaseContext) context.getApplicationContext(); | |
restorePosition(); | |
} | |
public ExtendedMapView(Context context, AttributeSet attributeSet) { | |
super(context, attributeSet); | |
baseContext = (BaseContext) context.getApplicationContext(); | |
restorePosition(); | |
} | |
private void restorePosition() { | |
baseContext.mapsCache.restore(); | |
if (baseContext.mapsCache.mapScale != 1 || | |
baseContext.mapsCache.latitude != 0 || | |
baseContext.mapsCache.longitude != 0) { | |
MapPosition mapPosition = new MapPosition(); | |
mapPosition.setPosition(baseContext.mapsCache.latitude / 1E6, baseContext.mapsCache.longitude / 1E6); | |
mapPosition.setScale(baseContext.mapsCache.mapScale); | |
mMap.setMapPosition(mapPosition); | |
} | |
} | |
public void onPause() { | |
MapPosition mapPosition = new MapPosition(); | |
mMap.viewport().getMapPosition(mapPosition); | |
GeoPoint geoPoint = mapPosition.getGeoPoint(); | |
baseContext.mapsCache.latitude = geoPoint.latitudeE6; | |
baseContext.mapsCache.longitude = geoPoint.longitudeE6; | |
baseContext.mapsCache.mapScale = (float) mapPosition.scale; | |
baseContext.mapsCache.save(); | |
mMap.pause(true); | |
} | |
public void onResume() { | |
mMap.pause(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment