Java源码示例:org.oscim.core.Tile
示例1
/**
* 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;
}
}
示例2
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);
}
示例3
/**
* 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);
}
示例4
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);
}
}
}
示例5
@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();
}
示例6
@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);
}
}
示例7
@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;
}
示例8
@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);
}
示例9
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);
}
}
示例10
/**
* 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);
}
示例11
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);
}
示例12
/**
* 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;
}
示例13
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);
}
示例14
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;
}
示例15
/**
* 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);
}
示例16
/**
* 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;
}
}
示例17
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);
}
示例18
@Override
public boolean decode(Tile tile, ITileDataSink sink, InputStream is)
throws IOException {
Bitmap bitmap = CanvasAdapter.decodeBitmap(is);
if (!bitmap.isValid()) {
log.debug("{} invalid bitmap", tile);
return false;
}
sink.setTileImage(bitmap);
return true;
}
示例19
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();
}
示例20
@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;
}
示例21
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;
}
示例22
@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;
}
示例23
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);
}
示例24
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;
}
示例25
@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);
}
示例26
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();
}
}
示例27
@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);
}
示例28
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); }
示例29
@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);
}
示例30
@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;
}