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

The following examples show how to use org.osmdroid.views.Projection#getZoomLevel() . 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: MinimapOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean setViewPort(final Canvas pCanvas, final Projection pProjection) {
	final double zoomLevel = pProjection.getZoomLevel() - getZoomDifference();
	if (zoomLevel < mTileProvider.getMinimumZoomLevel()) {
		return false;
	}

	final int left = pCanvas.getWidth() - getPadding() - getWidth();
	final int top = pCanvas.getHeight() - getPadding() - getHeight();
	setCanvasRect(new Rect(left, top, left + getWidth(), top + getHeight()));
	setProjection(pProjection.getOffspring(zoomLevel, getCanvasRect()));
	getProjection().getMercatorViewPort(mViewPort);
	return true;
}
 
Example 2
Source File: OsmPath.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Call this method at the beginning of every draw() call.
 */
public void onDrawCycle(Projection proj) {
	if (mLastZoomLevel != proj.getZoomLevel()) {
		proj.toPixels(sReferenceGeoPoint, mReferencePoint);
		mLastZoomLevel = proj.getZoomLevel();
	}
	int x = mReferencePoint.x;
	int y = mReferencePoint.y;
	proj.toPixels(sReferenceGeoPoint, mReferencePoint);
	int deltaX = mReferencePoint.x - x;
	int deltaY = mReferencePoint.y - y;

	offset(deltaX, deltaY);
}
 
Example 3
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);
}