org.oscim.core.Point Java Examples

The following examples show how to use org.oscim.core.Point. 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: BackendMap.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
@Override
public void onInputEvent(Event event, MotionEvent motionEvent) {
    if ((motionEvent.getAction() == MotionEvent.ACTION_CANCEL || motionEvent.getAction() == MotionEvent.ACTION_UP) && currentlyDraggedItem != null) {
        currentlyDraggedItem.onDragStop();
        currentlyDraggedItem = null;
    }
    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
        dragLastX = motionEvent.getX();
        dragLastY = motionEvent.getY();
    }
    if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && currentlyDraggedItem != null) {
        Point out = new Point();
        mapView.map().viewport().toScreenPoint(GmsMapsTypeHelper.fromLatLng(currentlyDraggedItem.getPosition()), out);
        out.x += mapView.getWidth() / 2;
        out.y += mapView.getHeight() / 2;
        float mx = motionEvent.getX() - dragLastX;
        float my = motionEvent.getY() - dragLastY;
        currentlyDraggedItem.setPosition(GmsMapsTypeHelper.toLatLng(mapView.map().viewport().fromScreenPoint((float) out.getX() + mx, (float) out.getY() + my)));
        currentlyDraggedItem.onDragProgress();
        dragLastX += mx;
        dragLastY += my;
    }
}
 
Example #2
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onItemLongPress(int index, MarkerItem item) {
    if (!mObjectInteractionEnabled)
        return true;
    if (mLocationState != LocationState.DISABLED && mLocationState != LocationState.ENABLED)
        return false;
    Object uid = item.getUid();
    if (uid != null) {
        Waypoint waypoint = (Waypoint) uid;
        if (waypoint.locked) {
            Toast.makeText(this, R.string.msgPlaceLocked, Toast.LENGTH_SHORT).show();
            return true;
        }
    }
    mActiveMarker = item;
    // For better experience get delta from marker position and finger press
    // and consider it when moving marker
    Point point = new Point();
    mMap.viewport().toScreenPoint(item.getPoint(), point);
    deltaX = (float) (downX - point.x);
    deltaY = (float) (downY - point.y);
    // Shift map to reveal marker tip position
    mMap.getEventLayer().enableMove(false);
    mMap.animator().animateTo(MAP_POSITION_ANIMATION_DURATION / 2, mMap.viewport().fromScreenPoint(mMap.getWidth() / 2f, mMap.getHeight() / 2f + 3 * mFingerTipSize), 1, true);
    return true;
}
 
Example #3
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the screen pixel for map coordinates
 *
 * @param out Point projected to screen coordinate
 */
public synchronized void toScreenPoint(double x, double y, boolean relativeToCenter, Point out) {

    double cs = mPos.scale * Tile.SIZE;
    double cx = mPos.x * cs;
    double cy = mPos.y * cs;

    mv[0] = (float) (x * cs - cx);
    mv[1] = (float) (y * cs - cy);

    mv[2] = 0;
    mv[3] = 1;

    mViewProjMatrix.prj(mv);

    out.x = (mv[0] * (mWidth / 2));
    out.y = -(mv[1] * (mHeight / 2));

    if (!relativeToCenter) {
        out.x += mWidth / 2;
        out.y += mHeight / 2;
    }
}
 
Example #4
Source File: MapCoverageLayer.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onGesture(Gesture gesture, MotionEvent event) {
    Point point = new Point();
    mMap.viewport().fromScreenPoint(event.getX(), event.getY(), point);
    int tileX = (int) (point.getX() / TILE_SCALE);
    int tileY = (int) (point.getY() / TILE_SCALE);
    if (tileX < 0 || tileX > 127 || tileY < 0 || tileY > 127)
        return false;
    Index.MapStatus mapStatus = mMapIndex.getNativeMap(tileX, tileY);
    if (gesture instanceof Gesture.LongPress) {
        if (mapStatus.downloading != 0L)
            mMapIndex.selectNativeMap(tileX, tileY, Index.ACTION.CANCEL);
        else if (mapStatus.created > 0)
            mMapIndex.selectNativeMap(tileX, tileY, Index.ACTION.REMOVE);
        return true;
    }
    if (gesture instanceof Gesture.Tap || gesture instanceof Gesture.DoubleTap) {
        if (mapStatus.downloading != 0L)
            return true;
        if (mMapIndex.hasDownloadSizes()) {
            if (mapStatus.downloadSize == 0L)
                return true;
        }
        mMapIndex.selectNativeMap(tileX, tileY, Index.ACTION.DOWNLOAD);
        return true;
    }
    return false;
}
 
Example #5
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private void zoomMap(double scaleBy, float x, float y) {
    if (mLocationOverlay.isEnabled() && mLocationOverlay.isVisible()) {
        Point out = new Point();
        mMap.viewport().toScreenPoint(mLocationOverlay.getX(), mLocationOverlay.getY(), true, out);
        mMap.animator().animateZoom(MAP_ZOOM_ANIMATION_DURATION >> 2, scaleBy, (float) out.x, (float) out.y);
    } else {
        mMap.animator().animateZoom(MAP_ZOOM_ANIMATION_DURATION, scaleBy, x, y);
    }
}
 
Example #6
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the map position for x,y in screen coordinates.
 *
 * @param x screen coordinate
 * @param y screen coordinate
 */
public synchronized void fromScreenPoint(double x, double y, Point out) {
    unprojectScreen(x, y, mu);

    double cs = mPos.scale * Tile.SIZE;
    double cx = mPos.x * cs;
    double cy = mPos.y * cs;

    double dx = cx + mu[0];
    double dy = cy + mu[1];

    dx /= cs;
    dy /= cs;

    while (dx > 1)
        dx -= 1;
    while (dx < 0)
        dx += 1;

    if (dy > 1)
        dy = 1;
    else if (dy < 0)
        dy = 0;

    out.x = dx;
    out.y = dy;
}
 
Example #7
Source File: BezierPath.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * from http://paulbourke.net/geometry/bezier/index.html
 * Four control point Bezier interpolation
 * mu ranges from 0 to 1, start to end of curve
 */
public static Point cubicBezier(Point p1, Point p2, Point p3, Point p4, double mu) {
    double mum1, mum13, mu3;
    Point p = new Point();

    mum1 = 1 - mu;
    mum13 = mum1 * mum1 * mum1;
    mu3 = mu * mu * mu;

    p.x = mum13 * p1.x + 3 * mu * mum1 * mum1 * p2.x + 3 * mu * mu * mum1 * p3.x + mu3 * p4.x;
    p.y = mum13 * p1.y + 3 * mu * mum1 * mum1 * p2.y + 3 * mu * mu * mum1 * p3.y + mu3 * p4.y;
    //p.z = mum13*p1.z + 3*mu*mum1*mum1*p2.z + 3*mu*mu*mum1*p3.z + mu3*p4.z;

    return (p);
}
 
Example #8
Source File: BezierPath.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * from http://paulbourke.net/geometry/bezier/index.html
 * Three control point Bezier interpolation
 * mu ranges from 0 to 1, start to end of the curve
 */
public static Point bezier3(Point p1, Point p2, Point p3, double mu) {
    double mum1, mum12, mu2;
    Point p = new Point();

    mu2 = mu * mu;
    mum1 = 1 - mu;
    mum12 = mum1 * mum1;
    p.x = p1.x * mum12 + 2 * p2.x * mum1 * mu + p3.x * mu2;
    p.y = p1.y * mum12 + 2 * p2.y * mum1 * mu + p3.y * mu2;
    //p.z = p1.z * mum12 + 2 * p2.z * mum1 * mu + p3.z * mu2;

    return (p);
}
 
Example #9
Source File: GeoPointUtils.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a point on the segment nearest to the specified point.
 * <p>
 * libGDX (Apache 2.0)
 */
public static Point nearestSegmentPoint(double startX, double startY, double endX, double endY, double pointX, double pointY) {
    double xDiff = endX - startX;
    double yDiff = endY - startY;
    double length2 = xDiff * xDiff + yDiff * yDiff;
    if (length2 == 0) return new Point(startX, startY);
    double t = ((pointX - startX) * (endX - startX) + (pointY - startY) * (endY - startY)) / length2;
    if (t < 0) return new Point(startX, startY);
    if (t > 1) return new Point(endX, endY);
    return new Point(startX + t * (endX - startX), startY + t * (endY - startY));
}
 
Example #10
Source File: MapTrekDataSource.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private void addFeaturesToTile(MapTile tile, ITileDataSink sink, String sql, String[] args) {
    MapTrekTileLayer.AmenityTileData td = get(tile);

    try (Cursor c = mDatabase.rawQuery(sql, args)) {
        c.moveToFirst();
        while (!c.isAfterLast()) {
            ExtendedMapElement element = new ExtendedMapElement(1, 1);
            element.id = c.getLong(0);
            element.kind = c.getInt(1);
            Tags.setTypeTag(c.getInt(2), element.tags);
            element.database = this;

            double px = MercatorProjection.longitudeToX(c.getDouble(4));
            double py = MercatorProjection.latitudeToY(c.getDouble(3));

            td.amenities.add(new Pair<>(new Point(px, py), element.id));

            px = (px - tile.x) * tile.mapSize;
            py = (py - tile.y) * tile.mapSize;

            element.startPoints();
            element.addPoint((float) px, (float) py);

            sink.process(element);
            c.moveToNext();
        }
    } catch (Exception e) {
        logger.error("Query error", e);
    }
}
 
Example #11
Source File: ProjectionImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Override
public LatLng fromScreenLocation(IObjectWrapper obj) throws RemoteException {
    Point point = GmsMapsTypeHelper
            .fromPoint((android.graphics.Point) ObjectWrapper.unwrap(obj));
    return GmsMapsTypeHelper
            .toLatLng(viewport.fromScreenPoint((float) point.x, (float) point.y));
}
 
Example #12
Source File: BezierPath.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
/**
 * from geodroid
 * FIXME
 */
public static List<Point> cubicSplineControlPoints(Point[] coords, float alpha) {

    if (alpha < 0.0 || alpha > 1.0) {
        throw new IllegalArgumentException("alpha must be between 0 and 1 inclusive");
    }

    if (coords.length < 2) {
        throw new IllegalArgumentException("number of Points must be >= 2");
    }

    int n = coords.length;

    List<Point> ctrl = new ArrayList<Point>();

    Point curr = new Point(2 * coords[0].x - coords[1].x, 2 * coords[0].y - coords[1].y);
    Point next = coords[0];

    Point mid = new Point();
    mid.x = (curr.x + next.x) / 2.0;
    mid.y = (curr.y + next.y) / 2.0;

    Point midPrev = new Point();

    Point last = new Point(2 * coords[n - 1].x - coords[n - 2].x,
            2 * coords[n - 1].y - coords[n - 2].y);

    Point anchor = new Point();
    double dv = curr.distance(next);

    for (int i = 0; i < n; i++) {
        curr = next;
        next = i < n - 1 ? coords[i + 1] : last;

        midPrev.x = mid.x;
        midPrev.y = mid.y;

        mid.x = (curr.x + next.x) / 2.0;
        mid.y = (curr.y + next.y) / 2.0;

        double dvPrev = dv;
        dv = curr.distance(next);

        double p = dvPrev / (dvPrev + dv);

        anchor.x = midPrev.x + p * (mid.x - midPrev.x);
        anchor.y = midPrev.y + p * (mid.y - midPrev.y);

        double dx = anchor.x - curr.x;
        double dy = anchor.y - curr.y;

        if (i > 0) {
            ctrl.add(new Point(alpha * (curr.x - midPrev.x + dx) + midPrev.x - dx,
                    alpha * (curr.y - midPrev.y + dy) + midPrev.y - dy));
        }
        if (i < n - 1) {
            ctrl.add(new Point(alpha * (curr.x - mid.x + dx) + mid.x - dx,
                    alpha * (curr.y - mid.y + dy) + mid.y - dy));
        }
    }

    return ctrl;
}
 
Example #13
Source File: MainActivity.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
private void updateNavigationUI() {
    logger.debug("updateNavigationUI()");
    boolean enabled = mLocationService != null && mLocationService.getStatus() == BaseLocationService.GPS_OK &&
            mNavigationService != null && mNavigationService.isNavigating();
    boolean changed = mViews.gaugePanel.setNavigationMode(enabled);
    if (enabled) {
        if (mViews.navigationArrow.getVisibility() == View.GONE) {
            mViews.navigationArrow.setAlpha(0f);
            mViews.navigationArrow.setVisibility(View.VISIBLE);
            mViews.navigationArrow.animate().alpha(1f).setDuration(MAP_POSITION_ANIMATION_DURATION).setListener(null);
        }
        GeoPoint destination = mNavigationService.getWaypoint().coordinates;
        if (mNavigationLayer == null) {
            mNavigationLayer = new NavigationLayer(mMap, 0x66ffff00, 8);
            mNavigationLayer.setDestination(destination);
            Point point = mLocationOverlay.getPosition();
            mNavigationLayer.setPosition(MercatorProjection.toLatitude(point.y), MercatorProjection.toLongitude(point.x));
            mMap.layers().add(mNavigationLayer, MAP_POSITIONAL);
        } else {
            GeoPoint current = mNavigationLayer.getDestination();
            if (!destination.equals(current)) {
                mNavigationLayer.setDestination(destination);
            }
        }
    } else {
        if (mViews.navigationArrow.getAlpha() == 1f) {
            mViews.navigationArrow.animate().alpha(0f).setDuration(MAP_POSITION_ANIMATION_DURATION).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mViews.navigationArrow.setVisibility(View.GONE);
                }
            });
        }
        if (mNavigationLayer != null) {
            mMap.layers().remove(mNavigationLayer);
            mNavigationLayer = null;
        }
    }
    if (changed)
        updateMapViewArea();
}
 
Example #14
Source File: ProjectionImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 4 votes vote down vote up
@Override
public IObjectWrapper toScreenLocation(LatLng latLng) throws RemoteException {
    Point point = new Point();
    viewport.toScreenPoint(GmsMapsTypeHelper.fromLatLng(latLng), point);
    return ObjectWrapper.wrap(GmsMapsTypeHelper.toPoint(point));
}
 
Example #15
Source File: MapTrekTileLayer.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onGesture(Gesture g, MotionEvent e) {
    if (!(g instanceof Gesture.Tap))
        return false;

    Point point = new Point();
    mMap.viewport().fromScreenPoint(e.getX(), e.getY(), point);

    Box box = mMap.viewport().getBBox(null, 128);

    double cs = mScale * Tile.SIZE;
    double distance = mFingerTipSize * mFingerTipSize / cs / cs;

    long nearest = 0L;

    for (int i = 0; i < mTileSet.cnt; i++) {
        MapTile t = mTileSet.tiles[i];
        AmenityTileData td = (AmenityTileData) t.getData(POI_DATA);
        if (td == null || td.amenities.isEmpty())
            continue;

        double dist = distance;

        int size = td.amenities.size();
        for (int j = 0; j < size; j++) {
            Pair<Point, Long> amenity = td.amenities.get(j);

            if (!box.contains(amenity.first))
                continue;

            double dx = amenity.first.x - point.x;
            double dy = amenity.first.y - point.y;

            double d = dx * dx + dy * dy;
            if (d > dist)
                continue;

            dist = d;
            nearest = amenity.second;
        }

    }

    if (nearest > 0L) {
        return mOnAmenityGestureListener != null &&
                mOnAmenityGestureListener.onAmenitySingleTapUp(nearest);
    }
    return false;
}
 
Example #16
Source File: LocationOverlay.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public Point getPosition() {
    return new Point(mLocation.x, mLocation.y);
}
 
Example #17
Source File: MarkerLayer.java    From trekarta with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Checks to see if the given x and y are close enough to an item
 * resulting in snapping the current action (e.g. zoom) to the item.
 *
 * @param x         The x in screen coordinates.
 * @param y         The y in screen coordinates.
 * @param snapPoint To be filled with the the interesting point (in screen
 *                  coordinates) that is closest to the given x and y. Can be
 *                  untouched if not snapping.
 * @return Whether or not to snap to the interesting point.
 */
boolean onSnapToItem(int x, int y, Point snapPoint);
 
Example #18
Source File: GeoPointUtils.java    From trekarta with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the distance between the given segment and point.
 * <p>
 * libGDX (Apache 2.0)
 */
public static double distanceSegmentPoint(double startX, double startY, double endX, double endY, double pointX, double pointY) {
    Point nearest = nearestSegmentPoint(startX, startY, endX, endY, pointX, pointY);
    return Math.hypot(nearest.x - pointX, nearest.y - pointY);
}
 
Example #19
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the screen pixel for map coordinates (relative to center)
 *
 * @param out Point projected to screen coordinate relative to center
 */
public void toScreenPoint(double x, double y, Point out) {
    toScreenPoint(x, y, true, out);
}
 
Example #20
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the screen pixel for a GeoPoint
 *
 * @param geoPoint the GeoPoint
 * @param out      Point projected to screen pixel
 */
public void toScreenPoint(GeoPoint geoPoint, boolean relativeToCenter, Point out) {
    MercatorProjection.project(geoPoint, out);
    toScreenPoint(out.x, out.y, relativeToCenter, out);
}
 
Example #21
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the screen pixel for a GeoPoint (relative to center)
 *
 * @param geoPoint the GeoPoint
 * @param out      Point projected to screen pixel relative to center
 */
public void toScreenPoint(GeoPoint geoPoint, Point out) {
    toScreenPoint(geoPoint, true, out);
}