Created
May 9, 2013 05:32
-
-
Save moagrius/5545745 to your computer and use it in GitHub Desktop.
Resizable MapView (centers to container)
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
package com.qozix.mapviewdemo; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.ViewGroup.LayoutParams; | |
import android.widget.RelativeLayout; | |
import com.qozix.mapview.MapView; | |
import com.qozix.mapview.MapView.MapEventListenerImplementation; | |
public class MainActivity extends Activity { | |
private RelativeLayout relativeLayout; | |
private MapView mapView; | |
@Override | |
public void onCreate( Bundle savedInstanceState ) { | |
super.onCreate( savedInstanceState ); | |
relativeLayout = new RelativeLayout( this ); | |
setContentView( relativeLayout ); | |
mapView = new MapView( this ); | |
mapView.setScaleLimits( 0.1, 1.0 ); | |
mapView.setScaleToFit( false ); | |
mapView.addMapEventListener( listener ); | |
mapView.addZoomLevel( 1159, 951, "tiles/125_%col%_%row%.png", "downsamples/map.png" ); | |
mapView.addZoomLevel( 2318, 1902, "tiles/250_%col%_%row%.png", "downsamples/map.png" ); | |
mapView.addZoomLevel( 4635, 3803, "tiles/500_%col%_%row%.png", "downsamples/map.png" ); | |
mapView.addZoomLevel( 9269, 7606, "tiles/1000_%col%_%row%.png", "downsamples/map.png" ); | |
mapView.registerGeolocator( 42.379676, -71.094919, 42.346550, -71.040280); | |
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT ); | |
lp.addRule( RelativeLayout.CENTER_IN_PARENT ); | |
relativeLayout.addView( mapView, lp ); | |
} | |
private MapEventListenerImplementation listener = new MapEventListenerImplementation(){ | |
@Override | |
public void onScaleChanged( double scale ){ | |
int containingWidth = relativeLayout.getWidth(); | |
int containingHeight = relativeLayout.getHeight(); | |
int mapWidth = mapView.getScaledWidth(); | |
int mapHeight = mapView.getScaledHeight(); | |
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mapView.getLayoutParams(); | |
if( mapWidth < containingWidth ) { | |
lp.width = mapWidth; | |
} else { | |
lp.width = LayoutParams.MATCH_PARENT; | |
} | |
if( mapHeight < containingHeight ) { | |
lp.height = mapHeight; | |
} else { | |
lp.height = LayoutParams.MATCH_PARENT; | |
} | |
mapView.setLayoutParams(lp); | |
} | |
}; | |
@Override | |
public void onPause(){ | |
super.onPause(); | |
mapView.clear(); | |
} | |
@Override | |
public void onResume(){ | |
super.onResume(); | |
mapView.requestRender(); | |
} | |
@Override | |
public void onDestroy(){ | |
super.onDestroy(); | |
mapView.destroy(); | |
mapView = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment