Java Code Examples for org.osmdroid.views.Projection#restore()

The following examples show how to use org.osmdroid.views.Projection#restore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyrightOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * @since 6.1.0
 */
@Override
public void draw(final Canvas canvas, final Projection pProjection) {
    if (mCopyrightNotice == null || mCopyrightNotice.length() == 0)
        return;

    int width = canvas.getWidth();
    int height = canvas.getHeight();

    float x = 0;
    float y = 0;

    if (alignRight) {
        x = width - xOffset;
        paint.setTextAlign(Paint.Align.RIGHT);
    } else {
        x = xOffset;
        paint.setTextAlign(Paint.Align.LEFT);
    }

    if (alignBottom)
        y = height - yOffset;
    else
        y = paint.getTextSize() + yOffset;

    // Draw the text
    pProjection.save(canvas, false, false);
    canvas.drawText(mCopyrightNotice, x, y, paint);
    pProjection.restore(canvas, false);
}
 
Example 2
Source File: CompassOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
protected void drawCompass(final Canvas canvas, final float bearing, final Rect screenRect) {
    final Projection proj = mMapView.getProjection();

    float centerX;
    float centerY;
    if (mInCenter) {
        final Rect rect = proj.getScreenRect();
        centerX = rect.exactCenterX();
        centerY = rect.exactCenterY();
    } else {
        centerX = mCompassCenterX * mScale;
        centerY = mCompassCenterY * mScale;
    }

    mCompassMatrix.setTranslate(-mCompassFrameCenterX, -mCompassFrameCenterY);
    mCompassMatrix.postTranslate(centerX, centerY);

    proj.save(canvas, false, true);
    canvas.concat(mCompassMatrix);
    canvas.drawBitmap(mCompassFrameBitmap, 0, 0, sSmoothPaint);
    proj.restore(canvas, true);

    mCompassMatrix.setRotate(-bearing, mCompassRoseCenterX, mCompassRoseCenterY);
    mCompassMatrix.postTranslate(-mCompassRoseCenterX, -mCompassRoseCenterY);
    mCompassMatrix.postTranslate(centerX, centerY);

    proj.save(canvas, false, true);
    canvas.concat(mCompassMatrix);
    canvas.drawBitmap(mCompassRoseBitmap, 0, 0, sSmoothPaint);
    proj.restore(canvas, true);
}
 
Example 3
Source File: MinimapOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas c, Projection pProjection) {
	if (!setViewPort(c, pProjection)) {
		return;
	}

	// Draw a solid background where the minimap will be drawn with a 2 pixel inset
	pProjection.save(c, false, true);
	c.drawRect(
			getCanvasRect().left - 2, getCanvasRect().top - 2,
			getCanvasRect().right + 2, getCanvasRect().bottom + 2, mPaint);

	super.drawTiles(c, getProjection(), getProjection().getZoomLevel(), mViewPort);
	pProjection.restore(c, true);
}
 
Example 4
Source File: ScaleBarOverlay.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Canvas c, Projection projection) {

	final double zoomLevel = projection.getZoomLevel();

	if (zoomLevel < minZoom) {
		return;
	}
	final Rect rect = projection.getIntrinsicScreenRect();
	int _screenWidth = rect.width();
	int _screenHeight = rect.height();
	boolean screenSizeChanged = _screenHeight!=screenHeight || _screenWidth != screenWidth;
	screenHeight = _screenHeight;
	screenWidth = _screenWidth;
	final IGeoPoint center = projection.fromPixels(screenWidth / 2, screenHeight / 2, null);
	if (zoomLevel != lastZoomLevel || center.getLatitude() != lastLatitude || screenSizeChanged) {
		lastZoomLevel = zoomLevel;
		lastLatitude = center.getLatitude();
		rebuildBarPath(projection);
	}

	int offsetX = xOffset;
	int offsetY = yOffset;
	if (alignBottom) offsetY *=-1;
	if (alignRight ) offsetX *=-1;
	if (centred && latitudeBar)
		offsetX += -latitudeBarRect.width() / 2;
	if (centred && longitudeBar)
		offsetY += -longitudeBarRect.height() / 2;

	projection.save(c, false, true);
	c.translate(offsetX, offsetY);

	if (latitudeBar && bgPaint != null)
		c.drawRect(latitudeBarRect, bgPaint);
	if (longitudeBar && bgPaint != null) {
		// Don't draw on top of latitude background...
		int offsetTop = latitudeBar ? latitudeBarRect.height() : 0;
		c.drawRect(longitudeBarRect.left, longitudeBarRect.top + offsetTop,
				longitudeBarRect.right, longitudeBarRect.bottom, bgPaint);
	}
	c.drawPath(barPath, barPaint);
	if (latitudeBar) {
		drawLatitudeText(c, projection);
	}
	if (longitudeBar) {
		drawLongitudeText(c, projection);
	}
	projection.restore(c, true);
}