当前位置: 首页>>代码示例>>Java>>正文


Java Projection.toPixelsFromProjected方法代码示例

本文整理汇总了Java中org.osmdroid.views.Projection.toPixelsFromProjected方法的典型用法代码示例。如果您正苦于以下问题:Java Projection.toPixelsFromProjected方法的具体用法?Java Projection.toPixelsFromProjected怎么用?Java Projection.toPixelsFromProjected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.osmdroid.views.Projection的用法示例。


在下文中一共展示了Projection.toPixelsFromProjected方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSnapToItem

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
@Override
    public boolean onSnapToItem(final int x, final int y, final Point snapPoint,
                                final IMapView mapView) {
        if (this.mLocation != null) {
            Projection pj = mMapView.getProjection();
            pj.toPixelsFromProjected(mMapCoordsProjected, mMapCoordsTranslated);
            snapPoint.x = mMapCoordsTranslated.x;
            snapPoint.y = mMapCoordsTranslated.y;
            final double xDiff = x - mMapCoordsTranslated.x;
            final double yDiff = y - mMapCoordsTranslated.y;
            boolean snap = xDiff * xDiff + yDiff * yDiff < 64;
//            if (DEBUGMODE) {
//                logger.debug("snap=" + snap);
//            }
            return snap;
        } else {
            return false;
        }
    }
 
开发者ID:Arman92,项目名称:Mapsforge-OsmDroid-GraphHopper,代码行数:20,代码来源:MyLocationNewOverlay.java

示例2: isCloseTo

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
/** Detection is done is screen coordinates. 
 * @param point
 * @param tolerance in pixels
 * @return true if the Polyline is close enough to the point. 
 */
public boolean isCloseTo(GeoPoint point, double tolerance, MapView mapView) {
	final Projection pj = mapView.getProjection();
	precomputePoints(pj);
	Point p = pj.toPixels(point, null);
	int i = 0;
	boolean found = false;
	while (i < mPointsPrecomputed - 1 && !found) {
		Point projectedPoint1 = mPoints.get(i);
		if (i == 0){
			pj.toPixelsFromProjected(projectedPoint1, mTempPoint1);
		} else {
			//reuse last b:
			mTempPoint1.set(mTempPoint2.x, mTempPoint2.y);
		}
		Point projectedPoint2 = mPoints.get(i+1);
		pj.toPixelsFromProjected(projectedPoint2, mTempPoint2);
		found = (linePointDist(mTempPoint1, mTempPoint2, p, true) <= tolerance);
		//TODO: if found, compute and return the point ON the line. 
		i++;
	}
	return found;
}
 
开发者ID:jeffallen,项目名称:MarshrutMe,代码行数:28,代码来源:Polyline.java

示例3: hitTest

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
public boolean hitTest(final MotionEvent event, final MapView mapView){
        final Projection pj = mapView.getProjection();
        pj.toPixelsFromProjected(mMapCoordsProjected, mPositionPixels);

        final Rect screenRect = pj.getIntrinsicScreenRect();
        int x = -mPositionPixels.x + screenRect.left + (int) event.getX();
        int y = -mPositionPixels.y + screenRect.top + (int) event.getY();
        boolean hit = mIcon.getBounds().contains(x, y);
        return hit;
//        return true;
    }
 
开发者ID:Arman92,项目名称:Mapsforge-OsmDroid-GraphHopper,代码行数:12,代码来源:MyLocationNewOverlay.java

示例4: getMyLocationDrawingBounds

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
protected Rect getMyLocationDrawingBounds(int zoomLevel, Location lastFix, Rect reuse) {
    if (reuse == null)
        reuse = new Rect();

    final Projection pj = mMapView.getProjection();
    pj.toPixelsFromProjected(mMapCoordsProjected, mMapCoordsTranslated);

    // Start with the bitmap bounds
    if (lastFix.hasBearing()) {
        // Get a square bounding box around the object, and expand by the length of the diagonal
        // so as to allow for extra space for rotating
        int widestEdge = (int) Math.ceil(Math.max(mDirectionArrowBitmap.getWidth(),
                mDirectionArrowBitmap.getHeight()) * Math.sqrt(2));
        reuse.set(mMapCoordsTranslated.x, mMapCoordsTranslated.y, mMapCoordsTranslated.x
                + widestEdge, mMapCoordsTranslated.y + widestEdge);
        reuse.offset(-widestEdge / 2, -widestEdge / 2);
    } else {
        reuse.set(mMapCoordsTranslated.x, mMapCoordsTranslated.y, mMapCoordsTranslated.x
                + mIconBitmap.getWidth(), mMapCoordsTranslated.y + mIconBitmap.getHeight());
        reuse.offset((int) (-mPersonHotspot.x + 0.5f), (int) (-mPersonHotspot.y + 0.5f));
    }

    // Add in the accuracy circle if enabled
    if (mDrawAccuracyEnabled) {
        final int radius = (int) java.lang.Math.ceil(lastFix.getAccuracy()
                / (float) TileSystem.GroundResolution(lastFix.getLatitude(), zoomLevel));
        reuse.union(mMapCoordsTranslated.x - radius, mMapCoordsTranslated.y - radius,
                mMapCoordsTranslated.x + radius, mMapCoordsTranslated.y + radius);
        final int strokeWidth = (int) java.lang.Math.ceil(mCirclePaint.getStrokeWidth() == 0 ? 1
                : mCirclePaint.getStrokeWidth());
        reuse.inset(-strokeWidth, -strokeWidth);
    }

    return reuse;
}
 
开发者ID:Arman92,项目名称:Mapsforge-OsmDroid-GraphHopper,代码行数:36,代码来源:MyLocationNewOverlay.java

示例5: drawMyLocation

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
protected void drawMyLocation(final Canvas canvas, final MapView mapView, final Location lastFix) {
//        LocationUpdateService.staticLog("ARMAN", "draw mylocation");
        mPosition.setLatitudeE6((int)(lastFix.getLatitude() * 1000000));
        mPosition.setLongitudeE6((int) (lastFix.getLongitude() * 1000000));

        super.setPosition(mPosition);

        final Projection pj = mapView.getProjection();
        pj.toPixelsFromProjected(mMapCoordsProjected, mMapCoordsTranslated);

        pj.toPixelsFromProjected(mMapCoordsProjected, 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);

        if (mDrawAccuracyEnabled) {
            final float radius = lastFix.getAccuracy()
                    / (float) TileSystem.GroundResolution(lastFix.getLatitude(),
                    mapView.getZoomLevel());

            mCirclePaint.setAlpha(50);
            mCirclePaint.setStyle(Style.FILL);
            canvas.drawCircle(mMapCoordsTranslated.x, mMapCoordsTranslated.y, radius, mCirclePaint);

            mCirclePaint.setAlpha(150);
            mCirclePaint.setStyle(Style.STROKE);
            canvas.drawCircle(mMapCoordsTranslated.x, mMapCoordsTranslated.y, radius, mCirclePaint);
        }

        canvas.getMatrix(mMatrix);
        mMatrix.getValues(mMatrixValues);

        if (DEBUGMODE) {
            final float tx = (-mMatrixValues[Matrix.MTRANS_X] + 20)
                    / mMatrixValues[Matrix.MSCALE_X];
            final float ty = (-mMatrixValues[Matrix.MTRANS_Y] + 90)
                    / mMatrixValues[Matrix.MSCALE_Y];
            canvas.drawText("Lat: " + lastFix.getLatitude(), tx, ty + 5, mPaint);
            canvas.drawText("Lon: " + lastFix.getLongitude(), tx, ty + 20, mPaint);
            canvas.drawText("Alt: " + lastFix.getAltitude(), tx, ty + 35, mPaint);
            canvas.drawText("Acc: " + lastFix.getAccuracy(), tx, ty + 50, mPaint);
        }

        // Calculate real scale including accounting for rotation
        float scaleX = (float) Math.sqrt(mMatrixValues[Matrix.MSCALE_X]
                * mMatrixValues[Matrix.MSCALE_X] + mMatrixValues[Matrix.MSKEW_Y]
                * mMatrixValues[Matrix.MSKEW_Y]);
        float scaleY = (float) Math.sqrt(mMatrixValues[Matrix.MSCALE_Y]
                * mMatrixValues[Matrix.MSCALE_Y] + mMatrixValues[Matrix.MSKEW_X]
                * mMatrixValues[Matrix.MSKEW_X]);
        if (lastFix.hasBearing()) {
            canvas.save();
            // Rotate the icon
            canvas.rotate(lastFix.getBearing(), mMapCoordsTranslated.x, mMapCoordsTranslated.y);
            // Counteract any scaling that may be happening so the icon stays the same size
            canvas.scale(1 / scaleX, 1 / scaleY, mMapCoordsTranslated.x, mMapCoordsTranslated.y);
            // Draw the bitmap
            canvas.drawBitmap(mDirectionArrowBitmap, mMapCoordsTranslated.x
                            - mDirectionArrowCenterX, mMapCoordsTranslated.y - mDirectionArrowCenterY,
                    mPaint);
            canvas.restore();
        } else {
            canvas.save();
            // Unrotate the icon if the maps are rotated so the little man stays upright
            canvas.rotate(-mMapView.getMapOrientation(), mMapCoordsTranslated.x,
                    mMapCoordsTranslated.y);
            // Counteract any scaling that may be happening so the icon stays the same size
            canvas.scale(1 / scaleX, 1 / scaleY, mMapCoordsTranslated.x, mMapCoordsTranslated.y);
            // Draw the bitmap
            canvas.drawBitmap(mIconBitmap, mMapCoordsTranslated.x - mPersonHotspot.x,
                    mMapCoordsTranslated.y - mPersonHotspot.y, mPaint);
            canvas.restore();
        }
    }
 
开发者ID:Arman92,项目名称:Mapsforge-OsmDroid-GraphHopper,代码行数:78,代码来源:MyLocationNewOverlay.java

示例6: buildPathPortion

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
/** 
 * Note - highly optimized to handle long paths, proceed with care.
 * Should be fine up to 10K points.
 */
protected void buildPathPortion(Projection pj){
	final int size = mConvertedPoints.size();
	if (size < 2) // nothing to paint
		return;

	// precompute new points to the intermediate projection.
	if (!mPrecomputed){
		for (int i=0; i<size; i++) {
			final Point pt = mConvertedPoints.get(i);
			pj.toProjectedPixels(pt.x, pt.y, pt);
		}
		mPrecomputed = true;
	}

	Point projectedPoint0 = mConvertedPoints.get(0); // points from the points list
	Point projectedPoint1;
	
	Point screenPoint0 = pj.toPixelsFromProjected(projectedPoint0, mTempPoint1); // points on screen
	Point screenPoint1;
	
	mPath.moveTo(screenPoint0.x, screenPoint0.y);
	
	for (int i=0; i<size; i++) {
		// compute next points
		projectedPoint1 = mConvertedPoints.get(i);
		screenPoint1 = pj.toPixelsFromProjected(projectedPoint1, mTempPoint2);

		if (Math.abs(screenPoint1.x - screenPoint0.x) + Math.abs(screenPoint1.y - screenPoint0.y) <= 1) {
			// skip this point, too close to previous point
			continue;
		}

		mPath.lineTo(screenPoint1.x, screenPoint1.y);

		// update starting point to next position
		projectedPoint0 = projectedPoint1;
		screenPoint0.x = screenPoint1.x;
		screenPoint0.y = screenPoint1.y;
	}
	mPath.close();
}
 
开发者ID:jeffallen,项目名称:MarshrutMe,代码行数:46,代码来源:Polygon.java

示例7: draw

import org.osmdroid.views.Projection; //导入方法依赖的package包/类
@Override protected void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {

		if (shadow) {
			return;
		}

		final int size = this.mPoints.size();
		if (size < 2) {
			// nothing to paint
			return;
		}

		final Projection pj = mapView.getProjection();

		// precompute new points to the intermediate projection.
		precomputePoints(pj);

		Point screenPoint0 = null; // points on screen
		Point screenPoint1;
		Point projectedPoint0; // points from the points list
		Point projectedPoint1;

		// clipping rectangle in the intermediate projection, to avoid performing projection.
		BoundingBoxE6 boundingBox = pj.getBoundingBox();
		Point topLeft = pj.toProjectedPixels(boundingBox.getLatNorthE6(),
				boundingBox.getLonWestE6(), null);
		Point bottomRight = pj.toProjectedPixels(boundingBox.getLatSouthE6(),
				boundingBox.getLonEastE6(), null);
		final Rect clipBounds = new Rect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
		// take into account map orientation:
		if (mapView.getMapOrientation() != 0.0f)
			GeometryMath.getBoundingBoxForRotatatedRectangle(clipBounds, mapView.getMapOrientation(), clipBounds);
		
		mPath.rewind();
		projectedPoint0 = this.mPoints.get(size - 1);
		mLineBounds.set(projectedPoint0.x, projectedPoint0.y, projectedPoint0.x, projectedPoint0.y);

		for (int i = size - 2; i >= 0; i--) {
			// compute next points
			projectedPoint1 = this.mPoints.get(i);
			mLineBounds.union(projectedPoint1.x, projectedPoint1.y);

			if (!Rect.intersects(clipBounds, mLineBounds)) {
				// skip this line, move to next point
				projectedPoint0 = projectedPoint1;
				screenPoint0 = null;
				continue;
			}

			// the starting point may be not calculated, because previous segment was out of clip
			// bounds
			if (screenPoint0 == null) {
				screenPoint0 = pj.toPixelsFromProjected(projectedPoint0, this.mTempPoint1);
				mPath.moveTo(screenPoint0.x, screenPoint0.y);
			}

			screenPoint1 = pj.toPixelsFromProjected(projectedPoint1, this.mTempPoint2);

			// skip this point, too close to previous point
			if (Math.abs(screenPoint1.x - screenPoint0.x) + Math.abs(screenPoint1.y - screenPoint0.y) <= 1) {
				continue;
			}

			mPath.lineTo(screenPoint1.x, screenPoint1.y);

			// update starting point to next position
			projectedPoint0 = projectedPoint1;
			screenPoint0.x = screenPoint1.x;
			screenPoint0.y = screenPoint1.y;
			mLineBounds.set(projectedPoint0.x, projectedPoint0.y, projectedPoint0.x, projectedPoint0.y);
		}

		canvas.drawPath(mPath, mPaint);
	}
 
开发者ID:jeffallen,项目名称:MarshrutMe,代码行数:75,代码来源:Polyline.java


注:本文中的org.osmdroid.views.Projection.toPixelsFromProjected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。