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

The following examples show how to use org.osmdroid.views.Projection#getOrientation() . 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: IconOverlay.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * Draw the icon.
 */
@Override
public void draw(Canvas canvas, Projection pj) {
    if (mIcon == null)
        return;
    if (mPosition == null)
        return;

    pj.toPixels(mPosition, mPositionPixels);
    int width = mIcon.getIntrinsicWidth();
    int height = mIcon.getIntrinsicHeight();
    Rect rect = new Rect(0, 0, width, height);
    rect.offset(-(int)(mAnchorU*width), -(int)(mAnchorV*height));
    mIcon.setBounds(rect);

    mIcon.setAlpha((int) (mAlpha * 255));

    float rotationOnScreen = (mFlat ? -mBearing : pj.getOrientation()-mBearing);
    drawAt(canvas, mIcon, mPositionPixels.x, mPositionPixels.y, false, rotationOnScreen);
}
 
Example 2
Source File: Marker.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override public void draw(Canvas canvas, Projection pj) {
	if (mIcon == null)
		return;
	if (!isEnabled())
		return;

	pj.toPixels(mPosition, mPositionPixels);

	float rotationOnScreen = (mFlat ? -mBearing : -pj.getOrientation()-mBearing);
	drawAt(canvas, mPositionPixels.x, mPositionPixels.y, rotationOnScreen);
	if (isInfoWindowShown()) {
		//showInfoWindow();
		mInfoWindow.draw();
	}
}
 
Example 3
Source File: ItemizedOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Draws an item located at the provided screen coordinates to the canvas.
 *
 * @param canvas
 *            what the item is drawn upon
 * @param item
 *            the item to be drawn
 * @param curScreenCoords
 * @param pProjection
 * @return true if the item was actually drawn
 */
protected boolean onDrawItem(final Canvas canvas, final Item item, final Point curScreenCoords,
		final Projection pProjection) {

	

	final int state = (mDrawFocusedItem && (mFocusedItem == item) ? OverlayItem.ITEM_STATE_FOCUSED_MASK
			: 0);
	final Drawable marker = (item.getMarker(state) == null) ? getDefaultMarker(state) : item
			.getMarker(state);
	final HotspotPlace hotspot = item.getMarkerHotspot();

	boundToHotspot(marker, hotspot);

	int x = mCurScreenCoords.x;
	int y = mCurScreenCoords.y;

	marker.copyBounds(mRect);
	mMarkerRect.set(mRect);
	mRect.offset(x, y);
	RectL.getBounds(mRect, x, y, pProjection.getOrientation(), mOrientedMarkerRect);
	final boolean displayed = Rect.intersects(mOrientedMarkerRect, canvas.getClipBounds());
	if (displayed) {
		if (pProjection.getOrientation() != 0) { // optimization: step 1/2
			canvas.save();
			canvas.rotate(-pProjection.getOrientation(), x, y);
		}
		marker.setBounds(mRect);
		marker.draw(canvas);
		if (pProjection.getOrientation() != 0) { // optimization: step 2/2
			canvas.restore();
		}
		marker.setBounds(mMarkerRect);
	}

	return displayed;
}