Java Code Examples for com.nextgis.maplib.datasource.GeoPoint#getY()

The following examples show how to use com.nextgis.maplib.datasource.GeoPoint#getY() . 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: Overlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void drawOnZooming(
        Canvas canvas,
        PointF currentFocusLocation,
        float scale,
        OverlayItem overlayItem,
        boolean scaleMarker)
{
    if(null == canvas || null == overlayItem || null == overlayItem.getMarker())
        return;

    if (!isVisible())
        return;

    GeoPoint offset = getScaledOffset(currentFocusLocation, overlayItem, scale, scaleMarker);
    float zoomedX = (float) (overlayItem.getScreenX() - offset.getX());
    float zoomedY = (float) (overlayItem.getScreenY() - offset.getY());

    Matrix matrix = new Matrix();

    if (scaleMarker) {
        matrix.postScale(scale, scale);
    }

    matrix.postTranslate(zoomedX, zoomedY);
    canvas.drawBitmap(overlayItem.getMarker(), matrix, null);
}
 
Example 2
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void autopanTo(Location autopanLocation, Location location) {
    GeoPoint oldLocation = new GeoPoint(autopanLocation.getLongitude(), autopanLocation.getLatitude());
    GeoPoint newLocation = new GeoPoint(location.getLongitude(), location.getLatitude());
    oldLocation.setCRS(GeoConstants.CRS_WGS84);
    oldLocation.project(GeoConstants.CRS_WEB_MERCATOR);
    newLocation.setCRS(GeoConstants.CRS_WGS84);
    newLocation.project(GeoConstants.CRS_WEB_MERCATOR);

    double dx = oldLocation.getX() - newLocation.getX();
    double dy = oldLocation.getY() - newLocation.getY();
    GeoPoint newCenter = mMapViewOverlays.getMapCenter();
    newCenter.setX(newCenter.getX() - dx);
    newCenter.setY(newCenter.getY() - dy);

    mMapViewOverlays.panTo(newCenter);
}
 
Example 3
Source File: MapView.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void zoomStop()
{
    if (mDrawingState == DRAW_STATE_zooming && mMap != null) {

        float zoom = MapUtil.getZoomForScaleFactor(mScaleFactor, mMap.getZoomLevel());

        GeoEnvelope env = mMap.getFullScreenBounds();
        GeoPoint focusPt = new GeoPoint(-mCurrentFocusLocation.x, -mCurrentFocusLocation.y);

        double invertScale = 1 / mScaleFactor;

        double offX = (1 - invertScale) * focusPt.getX();
        double offY = (1 - invertScale) * focusPt.getY();
        env.scale(invertScale);
        env.offset(offX, offY);

        GeoPoint newCenterPt = env.getCenter();
        GeoPoint newCenterPtMap = mMap.screenToMap(newCenterPt);

        if(Constants.DEBUG_MODE) {
            Log.d(TAG, "zoomStop: setZoomAndCenter");
        }

        setZoomAndCenter(zoom, newCenterPtMap);
    }
}
 
Example 4
Source File: GISDisplay.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public synchronized void draw(
        Canvas canvas,
        float x,
        float y,
        float scale)
{
    clearBackground(canvas);

    if (null == canvas) {
        return;
    }

    GeoPoint pt = getScaledOffset(x, y, scale);

    float mainBitmapOffsetX = (float) pt.getX();
    float mainBitmapOffsetY = (float) pt.getY();

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);
    matrix.postTranslate(-mainBitmapOffsetX, -mainBitmapOffsetY);
    //Log.d(TAG, "matix: " + matrix.toShortString());

    canvas.drawBitmap(mDoubleBufferBitmap, matrix, mRasterPaint);
}
 
Example 5
Source File: GISDisplay.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void buffer(
        float x,
        float y,
        float scale)
{
    mDoubleBufferBitmap.eraseColor(Color.TRANSPARENT);

    if (scale == 1) {
        mDoubleBufferCanvas.drawBitmap(mMainBitmap, x, y, null);
    } else {
        GeoPoint pt = getScaledOffset(x, y, scale);

        float mainBitmapOffsetX = (float) pt.getX();
        float mainBitmapOffsetY = (float) pt.getY();

        Matrix matrix = new Matrix();
        matrix.postScale(scale, scale);
        matrix.postTranslate(-mainBitmapOffsetX, -mainBitmapOffsetY);

        mDoubleBufferCanvas.drawBitmap(mMainBitmap, matrix, mRasterPaint);
    }
}
 
Example 6
Source File: MapView.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onDoubleTap(final MotionEvent e)
{
    if (mMap == null) {
        return false;
    }

    mDrawingState = DRAW_STATE_zooming;
    mScaleFactor = 2;
    mCurrentFocusLocation.set(-e.getX(), -e.getY());
    //invalidate();

    GeoEnvelope env = mMap.getFullScreenBounds();
    GeoPoint focusPt = new GeoPoint(-mCurrentFocusLocation.x, -mCurrentFocusLocation.y);

    double invertScale = 1 / mScaleFactor;

    double offX = (1 - invertScale) * focusPt.getX();
    double offY = (1 - invertScale) * focusPt.getY();
    env.scale(invertScale);
    env.offset(offX, offY);

    GeoPoint newCenterPt = env.getCenter();
    GeoPoint newCenterPtMap = mMap.screenToMap(newCenterPt);

    //Log.d(TAG, "onDoubleTap: setZoomAndCenter");

    mMap.buffer(0, 0, 1);
    setZoomAndCenter((float) Math.ceil(getZoomLevel() + 0.5), newCenterPtMap);

    postInvalidate();

    return true;
}
 
Example 7
Source File: SimplePolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void drawText(Float scaledTextSize, GeoPoint center, GISDisplay display) {
    if (TextUtils.isEmpty(mText) || null == scaledTextSize) { return; }

    Paint textPaint = new Paint();
    textPaint.setColor(Color.BLACK);
    textPaint.setAntiAlias(true);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setStrokeCap(Paint.Cap.ROUND);
    textPaint.setAlpha(128);

    Rect textRect = new Rect();
    textPaint.setTextSize(scaledTextSize);
    textPaint.getTextBounds(mText, 0, mText.length(), textRect);

    float halfW = textRect.width() / 2;
    float halfH = textRect.height() / 2;

    float textX = (float) (center.getX() - halfW);
    float textY = (float) (center.getY() + halfH);

    Path textPath = new Path();
    textPaint.getTextPath(mText, 0, mText.length(), textX, textY, textPath);
    textPath.close();

    Matrix matrix = new Matrix();
    matrix.reset();
    matrix.setScale(1, -1, (float) center.getX(), (float) center.getY());
    textPath.transform(matrix);

    display.drawPath(textPath, textPaint);
}
 
Example 8
Source File: GISDisplay.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoPoint screenToMap(final GeoPoint pt)
{
    float points[] = new float[2];
    points[0] = (float) pt.getX();
    points[1] = (float) pt.getY();
    mInvertTransformMatrix.mapPoints(points);

    return new GeoPoint(points[0], points[1]);
}
 
Example 9
Source File: GISDisplay.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoPoint mapToScreen(final GeoPoint pt)
{
    float points[] = new float[2];
    points[0] = (float) pt.getX();
    points[1] = (float) pt.getY();
    mTransformMatrix.mapPoints(points);

    return new GeoPoint(points[0], points[1]);
}
 
Example 10
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean checkPointOverlaps(
        GeoPoint pt,
        double tolerance)
{
    double halfTolerance = tolerance * 0.3; // 0.85?
    GeoEnvelope envelope = new GeoEnvelope(pt.getX() - halfTolerance, pt.getX() + halfTolerance,
            pt.getY() - halfTolerance, pt.getY() + halfTolerance);
    return !mCache.search(envelope).isEmpty();
}
 
Example 11
Source File: OverlayItem.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void updateScreenCoordinates() {
    GeoPoint mts = mMapDrawable.mapToScreen((GeoPoint) mCoordinates.copy());
    mScreenCoordinates.x = (float) (mts.getX() - mOffsetX);
    mScreenCoordinates.y = (float) (mts.getY() - mOffsetY);
}
 
Example 12
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static float[] getNewGeometry(int geometryType, float tolerance, MapDrawable map) {
    float[] geoPoints;
    float add = tolerance * 2;
    GeoPoint center = map.getFullScreenBounds().getCenter();

    switch (geometryType) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTMultiPoint:
            geoPoints = new float[2];
            geoPoints[0] = (float) center.getX();
            geoPoints[1] = (float) center.getY();
            return geoPoints;
        case GeoConstants.GTLineString:
        case GeoConstants.GTMultiLineString:
            geoPoints = new float[4];
            geoPoints[0] = (float) center.getX() - add;
            geoPoints[1] = (float) center.getY() - add;
            geoPoints[2] = (float) center.getX() + add;
            geoPoints[3] = (float) center.getY() + add;
            return geoPoints;
        case GeoConstants.GTPolygon:
        case GeoConstants.GTMultiPolygon:
            geoPoints = new float[6];
            geoPoints[0] = (float) center.getX() - add;
            geoPoints[1] = (float) center.getY() - add;
            geoPoints[2] = (float) center.getX() - add;
            geoPoints[3] = (float) center.getY() + add;
            geoPoints[4] = (float) center.getX() + add;
            geoPoints[5] = (float) center.getY() + add;
            return geoPoints;
        case GeoConstants.GTLinearRing:
            geoPoints = new float[6];
            geoPoints[0] = (float) center.getX() + add;
            geoPoints[1] = (float) center.getY() + add;
            geoPoints[2] = (float) center.getX() - add;
            geoPoints[3] = (float) center.getY() + add;
            geoPoints[4] = (float) center.getX() - add;
            geoPoints[5] = (float) center.getY() - add;
            return geoPoints;
        default:
            return null;
    }
}
 
Example 13
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas, MapDrawable mapDrawable) {
    if (mCurrentLocation != null && isMarkerEnabled()) {
        double lat = mCurrentLocation.getLatitude();
        double lon = mCurrentLocation.getLongitude();
        mMarker.setMarker(getDefaultMarker());
        mMarker.setCoordinatesFromWGS(lon, lat);

        if (null != mapDrawable) {
            // set accuracy marker with proper meter radius
            double accuracy = mCurrentLocation.getAccuracy();
            accuracy = getAccuracyRadius(lat, accuracy);

            GeoPoint centerPoint = new GeoPoint(lon, lat);
            centerPoint.setCRS(GeoConstants.CRS_WGS84);
            centerPoint.project(GeoConstants.CRS_WEB_MERCATOR);
            centerPoint = mapDrawable.mapToScreen(centerPoint);
            GeoPoint newPoint = new GeoPoint(lon, accuracy);
            newPoint.setCRS(GeoConstants.CRS_WGS84);
            newPoint.project(GeoConstants.CRS_WEB_MERCATOR);
            newPoint = mapDrawable.mapToScreen(newPoint);

            int radius = (int) (centerPoint.getY() - newPoint.getY());
            mAccuracy.setMarker(getAccuracyMarker(radius));
            mAccuracy.setCoordinatesFromWGS(lon, lat);

            // set marker in current map and screen bounds flags
            newPoint = mMarker.getCoordinates(GeoConstants.CRS_WEB_MERCATOR);
            mIsInBounds = mapDrawable.getCurrentBounds().contains(newPoint);
            GeoEnvelope screenBounds = mapDrawable.getFullScreenBounds();
            mIsInScreenBounds = mapDrawable.screenToMap(screenBounds).contains(newPoint);
        }

        if (mIsInBounds) {
            if (mIsAccuracyEnabled) {
                drawOverlayItem(canvas, mAccuracy);
            }

            drawOverlayItem(canvas, mMarker);
        }
    }
}
 
Example 14
Source File: SimpleMarkerStyle.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void drawText(float radius, float size, GeoPoint pt, GISDisplay display) {
        if (TextUtils.isEmpty(mText))
            return;

        Paint textPaint = new Paint();
        textPaint.setColor(mTextColor);
        textPaint.setAntiAlias(true);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setStrokeCap(Paint.Cap.ROUND);

        float gap = (float) (1 / display.getScale());
        float innerRadius = radius - gap;
        float textSize = size * innerRadius; // initial text size

        Rect textRect = new Rect();
        textPaint.setTextSize(size);
        textPaint.getTextBounds(mText, 0, mText.length(), textRect);
        textPaint.setTextSize(textSize);

        float halfW = textRect.width() * innerRadius / 2;
        float halfH = textRect.height() * innerRadius / 2;
//        float outerTextRadius = (float) Math.sqrt(halfH * halfH + halfW * halfW);
//        float textScale = innerRadius / outerTextRadius;

        float textX = (float) (pt.getX() - halfW - radius / 2);
        float textY = (float) (pt.getY() + halfH - radius / 2);

        switch (mTextAlignment) {
            case ALIGN_TOP:
                textY = textY - halfH * 2;
                break;
            case ALIGN_TOP_RIGHT:
                textX = textX + halfW * 2 - halfW * .5f;
                textY = textY - halfH * 2;
                break;
            case ALIGN_RIGHT:
                textX = textX + halfW * 2 - halfW * 0.25f;
                break;
            case ALIGN_BOTTOM_RIGHT:
                textX = textX + halfW * 2 - halfW * .5f;
                textY = textY + halfH * 2;
                break;
            case ALIGN_BOTTOM:
                textY = textY + halfH * 2;
                break;
            case ALIGN_BOTTOM_LEFT:
                textX = textX - halfW * 2 + halfW * .5f;
                textY = textY + halfH * 2;
                break;
            case ALIGN_LEFT:
                textX = textX - halfW * 2 + halfW * 0.25f;
                break;
            case ALIGN_TOP_LEFT:
                textX = textX - halfW * 2 + halfW * .5f;
                textY = textY - halfH * 2;
                break;
        }
        Path textPath = new Path();
        textPaint.getTextPath(mText, 0, mText.length(), textX, textY, textPath);
        textPath.close();

        Matrix matrix = new Matrix();
        matrix.reset();
        matrix.setScale(1, -1, (float) pt.getX(), (float) pt.getY());
        textPath.transform(matrix);

        display.drawPath(textPath, textPaint);
    }
 
Example 15
Source File: GeoUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static boolean rightTurn(GeoPoint a, GeoPoint b, GeoPoint c)
{
    return (b.getX() - a.getX())*(c.getY() - a.getY()) - (b.getY() - a.getY())*(c.getX() - a.getX()) > 0;
}