org.oscim.core.Tile Java Examples

The following examples show how to use org.oscim.core.Tile. 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: OnlineTileSource.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getTileUrl(Tile tile) {
    String tileUrl = null;
    if (mProviderClient == null)
        return null;
    Uri contentUri = Uri.parse(mUri + "/" + tile.zoomLevel + "/" + tile.tileX + "/" + tile.tileY);
    try {
        Cursor cursor = mProviderClient.query(contentUri, TILE_COLUMNS, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            tileUrl = cursor.getString(0);
            cursor.close();
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    return tileUrl;
}
 
Example #2
Source File: UrlTileSource.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String formatTilePath(UrlTileSource tileSource, Tile tile) {

    StringBuilder sb = new StringBuilder();
    for (String b : tileSource.getTilePath()) {
        if (b.length() == 1) {
            switch (b.charAt(0)) {
                case 'X':
                    sb.append(tileSource.tileXToUrlX(tile.tileX));
                    continue;
                case 'Y':
                    sb.append(tileSource.tileYToUrlY(tile.tileY));
                    continue;
                case 'Z':
                    sb.append(tileSource.tileZToUrlZ(tile.zoomLevel));
                    continue;
                default:
                    break;
            }
        }
        sb.append(b);
    }
    return sb.toString();
}
 
Example #3
Source File: OkHttpEngine.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendRequest(Tile tile) throws IOException {
    if (tile == null) {
        throw new IllegalArgumentException("Tile cannot be null.");
    }
    try {
        URL url = new URL(mTileSource.getTileUrl(tile));
        Request.Builder builder = new Request.Builder()
                .url(url);
        for (Entry<String, String> opt : mTileSource.getRequestHeader().entrySet())
            builder.addHeader(opt.getKey(), opt.getValue());
        Request request = builder.build();
        Response response = mClient.newCall(request).execute();
        if (mTileSource.tileCache != null) {
            mCachedData = response.body().bytes();
            mInputStream = new ByteArrayInputStream(mCachedData);
        } else
            mInputStream = response.body().byteStream();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
 
Example #4
Source File: GridRenderer.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
private void addLabels(int x, int y, int z) {
    int s = Tile.SIZE;

    TextBucket tl = mTextBucket;
    tl.clear();

    StringBuilder sb = mStringBuffer;

    for (int yy = -2; yy < 2; yy++) {
        for (int xx = -2; xx < 2; xx++) {

            sb.setLength(0);
            sb.append(z)
                    .append(" / ")
                    .append(x + xx)
                    .append(" / ")
                    .append(y + yy);

            TextItem ti = TextItem.pool.get();
            ti.set(s * xx + s / 2, s * yy + s / 2, sb.toString(), mText);
            tl.addText(ti);
        }
    }
}
 
Example #5
Source File: MapTrekTileSource.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void process(MapElement el) {
    ExtendedMapElement element = (ExtendedMapElement) el;
    if (!mTileClipper.clip(element))
        return;
    element.scale(scale, scale);
    element.translate(-dx, -dy);
    if (element.hasLabelPosition && element.labelPosition != null) {
        element.labelPosition.x = element.labelPosition.x * scale - dx;
        element.labelPosition.y = element.labelPosition.y * scale - dy;
        if (element.labelPosition.x < 0 || element.labelPosition.x > Tile.SIZE
                || element.labelPosition.y < 0 || element.labelPosition.y > Tile.SIZE)
            element.labelPosition = null;
    }
    mapDataSink.process(element);
}
 
Example #6
Source File: ExtrusionBucket.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
/**
 * ExtrusionLayer for polygon geometries.
 */
public ExtrusionBucket(int level, float groundResolution, float[] colors) {
    super(RenderBucket.EXTRUSION, true, false);
    this.level = level;
    this.colors = colors;
    this.color = 0;

    mGroundResolution = groundResolution;

    mIndices = new VertexData[5];

    for (int i = 0; i <= IND_MESH; i++)
        mIndices[i] = new VertexData();

    mClipper = new LineClipper(0, 0, Tile.SIZE, Tile.SIZE);
}
 
Example #7
Source File: SharedTileCache.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
public void saveTile(Tile tile, ByteArrayOutputStream data, boolean success) {
    byte[] bytes = null;
    if (success) {
        bytes = data.toByteArray();
    }

    synchronized (this.cacheBuffers) {
        data.reset();
        this.cacheBuffers.add(data);
    }

    if (success) {
        ContentValues values = new ContentValues();
        values.put("x", tile.tileX);
        values.put("y", tile.tileY);
        values.put("z", tile.zoomLevel);
        values.put("time", 0);
        values.put("last_access", 0);
        values.put("data", bytes);
        context.getContentResolver().insert(SharedTileProvider.PROVIDER_URI, values);
    }
}
 
Example #8
Source File: BucketRenderer.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
protected void setMatrix(GLMatrix mvp, GLViewport v, boolean project, float coordScale) {
    MapPosition oPos = mMapPosition;

    double tileScale = Tile.SIZE * v.pos.scale;

    double x = oPos.x - v.pos.x;
    double y = oPos.y - v.pos.y;

    if (mFlipOnDateLine) {
        //wrap around date-line
        while (x < 0.5)
            x += 1.0;
        while (x > 0.5)
            x -= 1.0;
    }

    mvp.setTransScale((float) (x * tileScale),
            (float) (y * tileScale),
            (float) (v.pos.scale / oPos.scale) / coordScale);

    mvp.multiplyLhs(project ? v.viewproj : v.view);
}
 
Example #9
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 #10
Source File: SharedTileCache.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Override
public TileWriter writeTile(Tile tile) {
    ByteArrayOutputStream os;
    synchronized (this.cacheBuffers) {
        if (this.cacheBuffers.isEmpty()) {
            os = new ByteArrayOutputStream('耀');
        } else {
            os = this.cacheBuffers.remove(this.cacheBuffers.size() - 1);
        }
    }

    return new CacheTileWriter(tile, os);
}
 
Example #11
Source File: MapTrekTileSource.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
TransformTileDataSink(MapTile baseTile, MapTile tile, ITileDataSink mapDataSink) {
this.mapDataSink = mapDataSink;
int dz = tile.zoomLevel - baseTile.zoomLevel;
scale = 1 << dz;
dx = (tile.tileX - (baseTile.tileX << dz)) * Tile.SIZE;
dy = (tile.tileY - (baseTile.tileY << dz)) * Tile.SIZE;
float buffer = CLIP_BUFFER * CanvasAdapter.getScale();
mTileClipper = new TileClipper((dx - buffer) / scale, (dy - buffer) / scale,
        (dx + Tile.SIZE + buffer) / scale, (dy + Tile.SIZE + buffer) / scale);        }
 
Example #12
Source File: BitmapTileLoader.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setTileImage(Bitmap bitmap) {
    if (isCanceled() || !mTile.state(LOADING)) {
        bitmap.recycle();
        return;
    }

    BitmapBucket l = new BitmapBucket(false);
    l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE, mLayer.pool);

    RenderBuckets buckets = new RenderBuckets();
    buckets.set(l);
    mTile.data = buckets;
}
 
Example #13
Source File: TileCache.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized TileReader getTile(Tile tile) {

    //if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB)
    //    return getTileApi11(tile);

    mQueryVals[0] = String.valueOf(tile.zoomLevel);
    mQueryVals[1] = String.valueOf(tile.tileX);
    mQueryVals[2] = String.valueOf(tile.tileY);

    Cursor cursor = mDatabase.rawQuery("SELECT " + COLUMN_DATA +
            " FROM " + TABLE_NAME +
            " WHERE z=? AND x=? AND y=?", mQueryVals);

    if (!cursor.moveToFirst()) {
        if (dbg)
            log.debug("not in cache {}", tile);

        cursor.close();
        return null;
    }

    InputStream in = new ByteArrayInputStream(cursor.getBlob(0));
    cursor.close();

    if (dbg)
        log.debug("load tile {}", tile);

    return new CacheTileReader(tile, in);
}
 
Example #14
Source File: TileCache.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void saveTile(Tile tile, ByteArrayOutputStream data, boolean success) {
    byte[] bytes = null;

    if (success)
        bytes = data.toByteArray();

    synchronized (mCacheBuffers) {
        data.reset();
        mCacheBuffers.add(data);
    }

    if (dbg)
        log.debug("store tile {} {}", tile, Boolean.valueOf(success));

    if (!success)
        return;

    synchronized (mStmtPutTile) {
        mStmtPutTile.bindLong(1, tile.tileX);
        mStmtPutTile.bindLong(2, tile.tileY);
        mStmtPutTile.bindLong(3, tile.zoomLevel);
        mStmtPutTile.bindLong(4, 0);
        mStmtPutTile.bindLong(5, 0);
        mStmtPutTile.bindBlob(6, bytes);

        mStmtPutTile.execute();
        mStmtPutTile.clearBindings();
    }
}
 
Example #15
Source File: TileCache.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public TileWriter writeTile(Tile tile) {
    ByteArrayOutputStream os;

    synchronized (mCacheBuffers) {
        if (mCacheBuffers.size() == 0)
            os = new ByteArrayOutputStream(32 * 1024);
        else
            os = mCacheBuffers.remove(mCacheBuffers.size() - 1);
    }
    return new CacheTileWriter(tile, os);
}
 
Example #16
Source File: MapEventLayer2.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private boolean doFling(float velocityX, float velocityY) {

        int w = Tile.SIZE * 5;
        int h = Tile.SIZE * 5;

        mMap.animator().animateFling(velocityX * 2, velocityY * 2,
                -w, w, -h, h);
        return true;
    }
 
Example #17
Source File: TileManager.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void init() {
    if (mCurrentTiles != null)
        mCurrentTiles.releaseTiles();

    mIndex.drop();

    /* Pass VBOs and VertexItems back to pools */
    for (int i = 0; i < mTilesEnd; i++) {
        MapTile t = mTiles[i];
        if (t == null)
            continue;

        /* Check if tile is used by another thread */
        if (!t.isLocked())
            t.clear();

        /* In case the tile is still loading or used by
         * another thread: clear when returned from loader
         * or becomes unlocked */
        t.setState(DEADBEEF);
    }

    /* clear references to cached MapTiles */
    Arrays.fill(mTiles, null);
    mTilesEnd = 0;
    mTilesCount = 0;

    /* Set up TileSet large enough to hold current tiles.
     * Use screen size as workaround for blank tiles in #520. */
    int num = Math.max(mMap.getScreenWidth(), mMap.getScreenHeight());
    int size = Tile.SIZE >> 1;
    int numTiles = (num * num) / (size * size) * 4;

    mNewTiles = new TileSet(numTiles);
    mCurrentTiles = new TileSet(numTiles);
}
 
Example #18
Source File: ViewController.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Moves this Viewport by the given amount of pixels.
 *
 * @param mx the amount of pixels to move the map horizontally.
 * @param my the amount of pixels to move the map vertically.
 */
public synchronized void moveMap(float mx, float my) {
    ThreadUtils.assertMainThread();

    applyRotation(mx, my, mPos.bearing, mMovePoint);
    double tileScale = mPos.scale * Tile.SIZE;
    moveTo(mPos.x - mMovePoint.x / tileScale, mPos.y - mMovePoint.y / tileScale);
}
 
Example #19
Source File: MapEventLayer.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private boolean doFling(float velocityX, float velocityY) {

        int w = Tile.SIZE * 5;
        int h = Tile.SIZE * 5;

        mMap.animator().animateFling(velocityX * 2, velocityY * 2,
                -w, w, -h, h);
        return true;
    }
 
Example #20
Source File: SQLiteTileSource.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {

    Bitmap bitmap = CanvasAdapter.decodeBitmap(is);
    if (!bitmap.isValid()) {
        logger.warn("invalid bitmap {}", tile);
        return false;
    }
    sink.setTileImage(bitmap);

    return true;
}
 
Example #21
Source File: SharedTileCache.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@Override
public TileReader getTile(Tile tile) {
    Cursor cursor = context.getContentResolver().query(SharedTileProvider.PROVIDER_URI, new String[]{"data"}, "z=? AND x=? AND y=?", new String[]{String.valueOf(tile.zoomLevel), String.valueOf(tile.tileX), String.valueOf(tile.tileY)}, null);
    if (cursor != null) {
        if (!cursor.moveToFirst()) {
            cursor.close();
            return null;
        } else {
            ByteArrayInputStream in = new ByteArrayInputStream(cursor.getBlob(0));
            cursor.close();
            return new CacheTileReader(tile, in);
        }
    }
    return null;
}
 
Example #22
Source File: GPMapProjection.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
public Coordinate fromPixels(int x, int y, int zoom) {
    double[] meters = MercatorUtils.pixelsToMeters(x, y, zoom, Tile.SIZE);
    double lon = MercatorUtils.metersXToLongitude(meters[0]);
    double lat = MercatorUtils.metersYToLatitude(meters[1]);
    long mapSize = MercatorProjection.getMapSize((byte) zoom);
    GeoPoint point = MercatorProjection.fromPixels(x, y, mapSize);
    return new Coordinate(point.getLongitude(), point.getLatitude());
}
 
Example #23
Source File: Animator.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void animateTo(long duration, BoundingBox bbox, Easing.Type easingType, int state) {
    ThreadUtils.assertMainThread();

    mMap.getMapPosition(mStartPos);
    /* TODO for large distance first scale out, then in
     * calculate the maximum scale at which the BoundingBox
     * is completely visible */
    double dx = Math.abs(longitudeToX(bbox.getMaxLongitude())
            - longitudeToX(bbox.getMinLongitude()));

    double dy = Math.abs(latitudeToY(bbox.getMinLatitude())
            - latitudeToY(bbox.getMaxLatitude()));

    log.debug("anim bbox " + bbox);

    double zx = mMap.getWidth() / (dx * Tile.SIZE);
    double zy = mMap.getHeight() / (dy * Tile.SIZE);
    double newScale = Math.min(zx, zy);

    GeoPoint p = bbox.getCenterPoint();

    mDeltaPos.set(longitudeToX(p.getLongitude()) - mStartPos.x,
            latitudeToY(p.getLatitude()) - mStartPos.y,
            newScale - mStartPos.scale,
            -mStartPos.bearing,
            -mStartPos.tilt);

    animStart(duration, state, easingType);
}
 
Example #24
Source File: GeoPointUtils.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the scale that allows to display the {@link BoundingBox} on a view with width and
 * height.
 *
 * @param bbox       the {@link BoundingBox} to display.
 * @param viewWidth  the width of the view.
 * @param viewHeight the height of the view.
 * @return the scale that allows to display the {@link BoundingBox} on a view with width and
 * height.
 */
public static double scaleForBounds(BoundingBox bbox, int viewWidth, int viewHeight) {
    double minx = MercatorProjection.longitudeToX(bbox.getMinLongitude());
    double miny = MercatorProjection.latitudeToY(bbox.getMaxLatitude());

    double dx = Math.abs(MercatorProjection.longitudeToX(bbox.getMaxLongitude()) - minx);
    double dy = Math.abs(MercatorProjection.latitudeToY(bbox.getMinLatitude()) - miny);
    double zx = viewWidth / (dx * Tile.SIZE);
    double zy = viewHeight / (dy * Tile.SIZE);

    return Math.min(zx, zy);
}
 
Example #25
Source File: UrlTileSource.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public String getTileUrl(Tile tile) {
    StringBuilder sb = new StringBuilder();
    sb.append(mUrl).append(mTileUrlFormatter.formatTilePath(this, tile));
    if (mApiKey != null) {
        sb.append("?").append(mKeyName).append("=").append(mApiKey);
    }
    return sb.toString();
}
 
Example #26
Source File: ExtrusionUtils.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Map the raw buffer scale to scale of coordinates
 */
public static void mapPolyCoordScale(GeometryBuffer buffer) {
    float tileScale = REF_TILE_SIZE / Tile.SIZE;
    float[] points = buffer.points;
    for (int pPos = 0; pPos < buffer.pointNextPos; pPos++) {
        points[pPos] = points[pPos] * tileScale;
    }
}
 
Example #27
Source File: ScanBox.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private float[] transScale(double x, double y, double scale, int zoom, float[] box) {
    scale *= Tile.SIZE;

    //double curScale = Tile.SIZE * scale;
    double div = scale / (1 << zoom);

    x *= scale;
    y *= scale;

    for (int i = 0; i < 8; i += 2) {
        mBox[i + 0] = (float) ((x + box[i + 0]) / div);
        mBox[i + 1] = (float) ((y + box[i + 1]) / div);
    }
    return mBox;
}
 
Example #28
Source File: GridRenderer.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public GridRenderer(int numLines, LineStyle lineStyle, TextStyle textStyle) {
    int size = Tile.SIZE;

    /* not needed to set but we know: 16 lines 'a' two points */
    mLines = new GeometryBuffer(2 * 16, 16);

    float pos = -size * 4;

    /* 8 vertical lines */
    for (int i = 0; i < 8 * numLines; i++) {
        float x = pos + i * size / numLines;
        mLines.startLine();
        mLines.addPoint(x, pos);
        mLines.addPoint(x, pos + size * 8);
    }

    /* 8 horizontal lines */
    for (int j = 0; j < 8 * numLines; j++) {
        float y = pos + j * size / numLines;
        mLines.startLine();
        mLines.addPoint(pos, y);
        mLines.addPoint(pos + size * 8, y);
    }

    mText = textStyle;

    mLineBucket = new LineBucket(0);
    mLineBucket.line = lineStyle;

    if (mText != null) {
        mTextBucket = new TextBucket();
        mTextBucket.next = mLineBucket;
    } else {
        mTextBucket = null;
        mLineBucket.addLine(mLines);
        buckets.set(mLineBucket);
    }

    mStringBuffer = new StringBuilder(32);
}
 
Example #29
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 #30
Source File: OverzoomDataSink.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public OverzoomDataSink(ITileDataSink sink, Tile overzoomTile, Tile tile) {
    this.sink = sink;

    int diff = tile.zoomLevel - overzoomTile.zoomLevel;
    dx = (tile.tileX - (overzoomTile.tileX << diff)) * Tile.SIZE;
    dy = (tile.tileY - (overzoomTile.tileY << diff)) * Tile.SIZE;
    scale = 1 << diff;
    float buffer = 32 * CanvasAdapter.getScale();
    clipper = new TileClipper((dx - buffer) / scale, (dy - buffer) / scale,
            (dx + Tile.SIZE + buffer) / scale, (dy + Tile.SIZE + buffer) / scale);
    separator = new TileSeparator(dx / scale, dy / scale,
            (dx + Tile.SIZE) / scale, (dy + Tile.SIZE) / scale);
}