Java Code Examples for org.oscim.core.MercatorProjection#toLongitude()

The following examples show how to use org.oscim.core.MercatorProjection#toLongitude() . 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: RMapsDatabase.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
static TileSource.OpenResult initialize(SQLiteTileSource tileSource, SQLiteDatabase database) {
    try {
        int minZoom = (int) database.compileStatement(SQL_GET_MIN_ZOOM).simpleQueryForLong();
        int maxZoom = (int) database.compileStatement(SQL_GET_MAX_ZOOM).simpleQueryForLong();
        tileSource.setMinZoom(minZoom);
        tileSource.setMaxZoom(maxZoom);

        String[] args = {String.valueOf(17 - maxZoom)};
        int minX = getInt(database, SQL_GET_MIN_X, args);
        int minY = getInt(database, SQL_GET_MIN_Y, args);
        int maxX = getInt(database, SQL_GET_MAX_X, args) + 1;
        int maxY = getInt(database, SQL_GET_MAX_Y, args) + 1;

        double scale = 1 << maxZoom;
        tileSource.mBoundingBox = new BoundingBox(
                MercatorProjection.toLatitude(maxY / scale),
                MercatorProjection.toLongitude(minX / scale),
                MercatorProjection.toLatitude(minY / scale),
                MercatorProjection.toLongitude(maxX / scale)
        );

        //TODO Try to fill zoom table and see what happens
    } catch (SQLException e) {
        return new TileSource.OpenResult(e.toString());
    }
    return TileSource.OpenResult.SUCCESS;
}
 
Example 2
Source File: MapFile.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if map contains given point
 */
public boolean contains(double x, double y) {
    if (polygonPoints == null) {
        GeoPoint geoPoint = new GeoPoint(MercatorProjection.toLatitude(y), MercatorProjection.toLongitude(x));
        return boundingBox.contains(geoPoint);
    }
    // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
    //  Note that division by zero is avoided because the division is protected
    //  by the "if" clause which surrounds it.
    int j = polygonPoints.length - 2;
    boolean inside = false;

    for (int i = 0; i < polygonPoints.length; i += 2) {
        double ix = polygonPoints[i];
        double iy = polygonPoints[i + 1];
        double jx = polygonPoints[j];
        double jy = polygonPoints[j + 1];
        if (iy < y && jy >= y || jy < y && iy >= y) {
            if (ix + (y - iy) * 1. / (jy - iy) * (jx - ix) < x) {
                inside = !inside;
            }
        }
        j = i;
    }

    return inside;
}
 
Example 3
Source File: GmsMapsTypeHelper.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public static LatLngBounds toLatLngBounds(Box box) {
    double minLon = MercatorProjection.toLongitude(box.xmin);
    double maxLon = MercatorProjection.toLongitude(box.xmax);
    double minLat = MercatorProjection.toLatitude(box.ymax);
    double maxLat = MercatorProjection.toLatitude(box.ymin);
    if (Double.isNaN(minLon) || Double.isNaN(maxLon) || Double.isNaN(minLat) || Double.isNaN(maxLat))
        minLon = maxLon = minLat = maxLat = 0;
    return new LatLngBounds(new LatLng(minLat, minLon), new LatLng(maxLat, maxLon));
}
 
Example 4
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
public BoundingBox getMapLimit() {
    return new BoundingBox(
            MercatorProjection.toLatitude(mMaxY), MercatorProjection.toLongitude(mMinX),
            MercatorProjection.toLatitude(mMinY), MercatorProjection.toLongitude(mMaxX)
    );
}
 
Example 5
Source File: Viewport.java    From trekarta with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Get the GeoPoint for x,y in screen coordinates.
 *
 * @param x screen coordinate
 * @param y screen coordinate
 * @return the corresponding GeoPoint
 */
public synchronized GeoPoint fromScreenPoint(float x, float y) {
    fromScreenPoint(x, y, mMovePoint);
    return new GeoPoint(
            MercatorProjection.toLatitude(mMovePoint.y),
            MercatorProjection.toLongitude(mMovePoint.x));
}