gpt4 book ai didi

android - "overzoom"tileoverlay 谷歌地图

转载 作者:IT老高 更新时间:2023-10-28 23:11:50 28 4
gpt4 key购买 nike

我有一个问题,我目前正在尝试为其构建自定义解决方案。我正在苦苦挣扎,也许我可以让它工作,但也许已经有另一种解决方案了。

我的客户有一个用于获取图 block 叠加层的后端,但它只能持续到缩放级别 8。在那之后,不会显示图 block 。

为了制作更多细节图 block ,我使用了 https://stackoverflow.com/a/36696291/969016在过去。它从更高的缩放级别获取 4 个图 block 并将其构造为 1 个。

但是现在,我必须从较低的缩放级别获取图 block 并且需要将其放大。我一直试图以上述为基础,但尚未成功。如果有人知道不同的方法,我将不胜感激。

或者,也许可以让 Google map 保持缩放而不请求高于某个级别的新图层?我的意思是,它已经在缩放级别之间这样做了

最佳答案

@RadekJ here 采用提高图 block 分辨率的解决方案(将 4 个更高缩放级别的图 block 合并为 1 个)作为引用,我开始研究相反的结果:采用较低的缩放级别,将其分成 4 部分,然后使用它来构建更高的缩放级别。

假设您获得的磁贴的最大缩放级别是 8,但您希望能够通过放大这些磁贴来缩小到 9、10 等。

每次放大时,图 block 都除以 2。所以以缩放级别 9 为例,我将缩放级别 8 中的图 block 切割成 4 block 。然后我确定了第 9 层所请求的图 block 需要哪个“象限”。

接下来,我使用递归来获得更高级别的缩放级别。我对结果很满意。

如果您想查看带有 xy 的图 block ,请将 DRAW_DEBUG_DATA 设置为 true >缩放级别在其中绘制。

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.google.android.gms.maps.model.Tile;
import com.google.android.gms.maps.model.TileProvider;

import java.io.ByteArrayOutputStream;

public class OverZoomTileProvider implements TileProvider {

public static final int MAX_ZOOM = 8;

private static final boolean DRAW_DEBUG_DATA = false;

private static final int TILE_SIZE = 256;
private static final int HALF_TILE_SIZE = TILE_SIZE / 2;

private Paint tilePainter = new Paint();

// these will only be used when DRAW_DEBUG_DATA is true
private Paint debugRectPaint;
private Paint debugTextPaint;

private TileProvider mTileProvider;

public OverZoomTileProvider(TileProvider tileProvider) {
mTileProvider = tileProvider;

if (DRAW_DEBUG_DATA) {
debugRectPaint = new Paint();
debugRectPaint.setColor(Color.RED);
debugRectPaint.setStrokeWidth(1);
debugRectPaint.setStyle(Paint.Style.STROKE);

debugTextPaint = new Paint();
debugTextPaint.setColor(Color.WHITE);
debugTextPaint.setStyle(Paint.Style.FILL);
debugTextPaint.setColor(Color.BLACK);
debugTextPaint.setTextSize(20);
}
}

@Override
public Tile getTile(int x, int y, int zoom) {
Bitmap image = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE,
Bitmap.Config.ARGB_8888);
image.eraseColor(Color.TRANSPARENT);

Canvas canvas = new Canvas(image);
drawTile(canvas, zoom, x, y);

byte[] data = bitmapToByteArray(image);
image.recycle();

return new Tile(TILE_SIZE, TILE_SIZE, data);
}

private void drawTile(Canvas canvas, int zoom, int x, int y) {

Bitmap bitmap = getTileAsBitmap(x, y, zoom);

if (bitmap != null) {
canvas.drawBitmap(bitmap, 0, 0, tilePainter);
bitmap.recycle();
}

if (DRAW_DEBUG_DATA) {
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), debugRectPaint);
canvas.drawText("" + x + ", " + x + " (" + zoom + ")", 128, 128, debugTextPaint);
}
}

private Bitmap getTileAsBitmap(int x, int y, int zoom) {
if (zoom <= MAX_ZOOM) {
Tile tile = mTileProvider.getTile(x, y, zoom);

if (tile == NO_TILE) {
return null;
}

return BitmapFactory.decodeByteArray(tile.data, 0, tile.data.length);
}


boolean leftColumn = x % 2 == 0;
boolean topRow = y % 2 == 0;

Bitmap bitmap = getTileAsBitmap(x / 2, y / 2, zoom - 1);

int quadrant;
if (leftColumn && topRow) {
quadrant = 1;
} else if (!leftColumn && topRow) {
quadrant = 2;
} else if (leftColumn) {
quadrant = 3;
} else {
quadrant = 4;
}

switch (quadrant) {
case 1:
bitmap = Bitmap.createBitmap(bitmap, 0, 0, HALF_TILE_SIZE, HALF_TILE_SIZE);
break;
case 2:
bitmap = Bitmap.createBitmap(bitmap, HALF_TILE_SIZE, 0, HALF_TILE_SIZE, HALF_TILE_SIZE);
break;
case 3:
bitmap = Bitmap.createBitmap(bitmap, 0, HALF_TILE_SIZE, HALF_TILE_SIZE, HALF_TILE_SIZE);
break;
case 4:
bitmap = Bitmap.createBitmap(bitmap, HALF_TILE_SIZE, HALF_TILE_SIZE, HALF_TILE_SIZE, HALF_TILE_SIZE);
break;
}

return Bitmap.createScaledBitmap(bitmap, TILE_SIZE, TILE_SIZE, false);
}

private static byte[] bitmapToByteArray(Bitmap bm) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, bos);

byte[] data = bos.toByteArray();
try {
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
}

关于android - "overzoom"tileoverlay 谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46221533/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com