Skip to content

Instantly share code, notes, and snippets.

@AAverin
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AAverin/989eef83077a6b0972f9 to your computer and use it in GitHub Desktop.
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
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