/** Called when the activity is first created. */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState, false); // Pass true here to actually contribute to OSM! mResourceProxy = new ResourceProxyImpl(getApplicationContext()); final RelativeLayout rl = new RelativeLayout(this); this.mOsmv = new MapView(this, 256); this.mOsmvController = this.mOsmv.getController(); rl.addView( this.mOsmv, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); /* Scale Bar Overlay */ { this.mScaleBarOverlay = new ScaleBarOverlay(this, mResourceProxy); this.mOsmv.getOverlays().add(mScaleBarOverlay); // Scale bar tries to draw as 1-inch, so to put it in the top center, set x offset to // half screen width, minus half an inch. this.mScaleBarOverlay.setScaleBarOffset( getResources().getDisplayMetrics().widthPixels / 2 - getResources().getDisplayMetrics().xdpi / 2, 10); } /* SingleLocation-Overlay */ { /* * Create a static Overlay showing a single location. (Gets updated in * onLocationChanged(Location loc)! */ this.mMyLocationOverlay = new SimpleLocationOverlay(this, mResourceProxy); this.mOsmv.getOverlays().add(mMyLocationOverlay); } /* ZoomControls */ { /* Create a ImageView with a zoomIn-Icon. */ final ImageView ivZoomIn = new ImageView(this); ivZoomIn.setImageResource(R.drawable.zoom_in); /* Create RelativeLayoutParams, that position it in the top right corner. */ final RelativeLayout.LayoutParams zoominParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); zoominParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); zoominParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); rl.addView(ivZoomIn, zoominParams); ivZoomIn.setOnClickListener( new OnClickListener() { @Override public void onClick(final View v) { SampleExtensive.this.mOsmvController.zoomIn(); } }); /* Create a ImageView with a zoomOut-Icon. */ final ImageView ivZoomOut = new ImageView(this); ivZoomOut.setImageResource(R.drawable.zoom_out); /* Create RelativeLayoutParams, that position it in the top left corner. */ final RelativeLayout.LayoutParams zoomoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); zoomoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); zoomoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); rl.addView(ivZoomOut, zoomoutParams); ivZoomOut.setOnClickListener( new OnClickListener() { @Override public void onClick(final View v) { SampleExtensive.this.mOsmvController.zoomOut(); } }); } /* MiniMap */ { mMiniMapOverlay = new MinimapOverlay(this, mOsmv.getTileRequestCompleteHandler()); this.mOsmv.getOverlays().add(mMiniMapOverlay); } // PathOverlay pathOverlay = new PathOverlay(Color.RED, this); // pathOverlay.addPoint(new GeoPoint(40.714623, -74.006605)); // pathOverlay.addPoint(new GeoPoint(38.8951118, -77.0363658)); // pathOverlay.addPoint(new GeoPoint(34.052186, -118.243932)); // pathOverlay.getPaint().setStrokeWidth(50.0f); // pathOverlay.setAlpha(100); // this.mOsmv.getOverlays().add(pathOverlay); this.setContentView(rl); }