Announcement

Collapse
No announcement yet.

Openstreetmap tiles numbering

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Openstreetmap tiles numbering

    Hi, I am doing some tests to make NWW-Android to work in offline mode with the mapsforge project (on a public clone of the worldwind project, so is anyone is interested...).

    It works from a tiles generation point of view (basing on the geopackage plugin), but I still have issues when trying to define the proper tiles to get. Currently they are scrambled.

    Since they are following the Openstreetmap tile numbering, I was wondering if someone can help me out.

    I tried to solve it as I used to in the java desktop version, but without success:

    Code:
    double north = sector.maxLatitude();
    double south = sector.minLatitude();
    double east = sector.maxLongitude();
    double west = sector.minLongitude();
    double centerX = west + (east - west) / 2.0;
    double centerY = south + (north - south) / 2.0;
    int[] tileNumber = getTileNumber(centerY, centerX, zoomLevel);
    int y = tileNumber[1];
    int x = tileNumber[0];
    with getTileNumber being:

    Code:
    public static int[] getTileNumber(final double lat, final double lon, final int zoom) {
       int xtile = (int) Math.floor((lon + 180) / 360 * (1 << zoom));
       int ytile = (int) Math.floor(
               (1 - Math.log(Math.tan(Math.toRadians(lat)) + 1 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2 * (1 << zoom));
       if (xtile < 0)
           xtile = 0;
       if (xtile >= (1 << zoom))
           xtile = ((1 << zoom) - 1);
       if (ytile < 0)
           ytile = 0;
       if (ytile >= (1 << zoom))
           ytile = ((1 << zoom) - 1);
       return new int[]{xtile, ytile};
    }
    Is this supposed to work?

    Has anyone implemented a Openstreetmap layer? That would probably work the same.

    Thanks,
    Andrea



Working...
X