Java Code Examples for org.osmdroid.views.MapView

The following are top voted examples for showing how to use org.osmdroid.views.MapView. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: osmdroid   File: SampleOsmPath.java View source code 6 votes vote down vote up
@Override
protected void draw(Canvas c, MapView osmv, boolean shadow) {
	if (shadow)
		return;

	final Projection proj = osmv.getProjection();

	if (mPath == null || mLastZoomLevel != proj.getZoomLevel())
		mPath = createPath();

	mLastZoomLevel = proj.getZoomLevel();

	// This allows us to properly position the path without having to rebuild it on every
	// draw cycle
	mPath.onDrawCycle(proj);

	c.drawPath(mPath, sPaint);
}
 
Example 2
Project: osmdroid   File: SampleWithTilesOverlayAndCustomTileSource.java View source code 6 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Setup base map
	final RelativeLayout rl = new RelativeLayout(this);

	final MapView osmv = new MapView(this);
	rl.addView(osmv, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
			LayoutParams.FILL_PARENT));
	osmv.setBuiltInZoomControls(true);

	// zoom to the netherlands
	osmv.getController().setZoom(7);
	osmv.getController().setCenter(new GeoPoint(51500000, 5400000));

	// Add tiles layer with custom tile source
	final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
	final ITileSource tileSource = new XYTileSource("FietsRegionaal",  3, 18, 256, ".png",
			new String[] { "http://overlay.openstreetmap.nl/openfietskaart-rcn/" });
	tileProvider.setTileSource(tileSource);
	final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, this.getBaseContext());
	tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
	osmv.getOverlays().add(tilesOverlay);

	this.setContentView(rl);
}
 
Example 3
Project: invio   File: WayOverlayTest.java View source code 6 votes vote down vote up
@Before
public void setup() {
    activity = mock(Activity.class);
    when(activity.getResources()).thenReturn(Robolectric.application.getResources());

    point = new NicGeoPointImpl();
    projection = mock(MapView.Projection.class);
    when(projection.fromPixels(anyInt(), anyInt())).thenReturn(point);

    mapView = mock(MapView.class);
    when(mapView.getProjection()).thenReturn(projection);

    snapper = mock(SimpleWaySnap.class);

}
 
Example 4
Project: osmdroid   File: MyLocationOverlay.java View source code 6 votes vote down vote up
public MyLocationOverlay(final Context ctx, final MapView mapView,
		final ResourceProxy pResourceProxy) {
	super(pResourceProxy);
	mMapView = mapView;
	mLocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
	mSensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
	final WindowManager windowManager = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
	mDisplay = windowManager.getDefaultDisplay();

	mMapController = mapView.getController();
	mCirclePaint.setARGB(0, 100, 100, 255);
	mCirclePaint.setAntiAlias(true);

	PERSON_ICON = mResourceProxy.getBitmap(ResourceProxy.bitmap.person);
	DIRECTION_ARROW = mResourceProxy.getBitmap(ResourceProxy.bitmap.direction_arrow);

	DIRECTION_ARROW_CENTER_X = DIRECTION_ARROW.getWidth() / 2 - 0.5f;
	DIRECTION_ARROW_CENTER_Y = DIRECTION_ARROW.getHeight() / 2 - 0.5f;

	// Calculate position of person icon's feet, scaled to screen density
	PERSON_HOTSPOT = new PointF(24.0f * mScale + 0.5f, 39.0f * mScale + 0.5f);

	createCompassFramePicture();
	createCompassRosePicture();

	COMPASS_FRAME_CENTER_X = mCompassFrame.getWidth() / 2 - 0.5f;
	COMPASS_FRAME_CENTER_Y = mCompassFrame.getHeight() / 2 - 0.5f;
	COMPASS_ROSE_CENTER_X = mCompassRose.getWidth() / 2 - 0.5f;
	COMPASS_ROSE_CENTER_Y = mCompassRose.getHeight() / 2 - 0.5f;
}
 
Example 5
Project: osmdroid   File: TilesOverlay.java View source code 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem pItem, final int pMenuIdOffset,
		final MapView pMapView) {

	final int menuId = pItem.getItemId() - pMenuIdOffset;
	if ((menuId >= MENU_TILE_SOURCE_STARTING_ID)
			&& (menuId < MENU_TILE_SOURCE_STARTING_ID
					+ TileSourceFactory.getTileSources().size())) {
		pMapView.setTileSource(TileSourceFactory.getTileSources().get(
				menuId - MENU_TILE_SOURCE_STARTING_ID));
		return true;
	} else if (menuId == MENU_OFFLINE) {
		final boolean useDataConnection = !pMapView.useDataConnection();
		pMapView.setUseDataConnection(useDataConnection);
		return true;
	} else {
		return false;
	}
}
 
Example 6
Project: AndroFotoFinder   File: GuestureOverlay.java View source code 6 votes vote down vote up
@Override public boolean 	onDoubleTapEvent(MotionEvent ev, MapView mapView) {
    if (this.isEnabled()) {
        switch (ev.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                // startRecordClipboard();
                this.mStart = new Point((int) ev.getX(), (int) ev.getY());
                this.mEnd = new Point();
                this.mPaint = new Paint();
                this.mPaint.setColor(colorDragTo);
                this.mPaint.setStrokeWidth(3);
                setEndPoint("onDoubleTapEvent-ACTION_DOWN", ev, mapView);
                break;
            case MotionEvent.ACTION_MOVE:
                if (setEndPoint("onDoubleTapEvent-ACTION_MOVE", ev, mapView)) {
                    mapView.invalidate();

                    return true; // i have handled it
                }
                break;
            case MotionEvent.ACTION_UP: {
                boolean visible = setEndPoint("onDoubleTapEvent-ACTION_UP", ev, mapView);
                zoom(mapView, visible);
                // this.mStart = null;
                // this.mRect = null;
                // this.mPaint = null;
                // this.mRectVisible = false;
                this.mRectVisible = false;
                return true; // processed
            }
        }
    }
    return super.onDoubleTapEvent(ev, mapView); // false: not handled yet
}
 
Example 7
Project: Yet-Another-Opening-Hours-App   File: YaohaMapActivity.java View source code 5 votes vote down vote up
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);
        mapview = (MapView) findViewById(R.id.mapview);
        mapview.setBuiltInZoomControls(true);
        mapview.setMultiTouchControls(true);
        mapController = (MapController) this.mapview.getController();
        
        // just save the search term
        // we may later add a method to actually look in maps after it
        Intent intent = getIntent();
        CharSequence text = intent.getCharSequenceExtra("org.yaoha.YaohaMapActivity.SearchText");
        search_term = text.toString();
        Log.i(YaohaMapActivity.class.getSimpleName(), "Search field input was: " + text);
        
        no = new NodesOverlay(getResources().getDrawable(R.drawable.dontknow), new org.osmdroid.DefaultResourceProxyImpl(mapview.getContext()), this, mapview, OsmNodeDbHelper.getInstance(), search_term);
        
        mapview.getOverlays().add(no);
        mapview.setMapListener(mapListener = new YaohaMapListener(this, no));

        mprefs = getPreferences(MODE_PRIVATE);
        default_shared_prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
        assert(mprefs != default_shared_prefs);
        int zoom = -1;//Integer.parseInt(default_shared_prefs.getString("zoomlevel", "-1"));
        zoom = mprefs.getInt("zoomlevel", zoom);
        //Toast.makeText(this, "Set zoom to " + zoom +"m!", Toast.LENGTH_LONG).show();
        //mapController.setZoom(prefs.getInt("zoomlevel", 15));

        // hardcoded default is braunschweig
        int longitude = mprefs.getInt("longitude", braunschweig.getLongitudeE6());
        int latitude = mprefs.getInt("latitude", braunschweig.getLatitudeE6());
        GeoPoint myPosition = new GeoPoint(latitude, longitude);
        
        // get saved values
        if (savedInstanceState != null) {
            savedInstanceState.getInt("zoomlevel", zoom);
            myPosition.setLatitudeE6(savedInstanceState.getInt("latitude", myPosition.getLatitudeE6()));
            myPosition.setLongitudeE6(savedInstanceState.getInt("longitude", myPosition.getLongitudeE6()));
        }
        
     // Acquire a reference to the system Location Manager
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        Location loc = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        
        if (loc != null) {
            myPosition = new GeoPoint(loc);
            Log.i(YaohaMapActivity.class.getSimpleName(), "last known location is " + myPosition);
        }
        else {
            Log.i(YaohaMapActivity.class.getSimpleName(), "no last known location " + myPosition);
        }

        mapController.setZoom(zoom);
        mapController.setCenter(myPosition);
        setNodes();
     // Register the listener with the Location Manager to receive location updates
//        locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 300, 200, this);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 300000, 200, this);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 300000, 200, this);
        

        mOverlay = new MyLocationNewOverlay(this, mapview); //TODO
        mapview.getOverlays().add(mOverlay);
        mapview.postInvalidate();
        mOverlay.enableMyLocation();
        
        BoundingBoxE6 bb = mapview.getBoundingBox();
        int west = mprefs.getInt("west", bb.getLonWestE6()-1000);
        int east = mprefs.getInt("east", bb.getLonEastE6()+1000);
        int north = mprefs.getInt("north", bb.getLatNorthE6()+1000);
        int south = mprefs.getInt("south", bb.getLatSouthE6()-1000);
        mapListener.update(new BoundingBoxE6(north, east, south, west));
    }