Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – Google Maps v2 Custom Tile Provider大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个自定义磁贴提供商,以在Google地图上显示流量数据.在高缩放级别,它对我来说很好.

android – Google Maps v2 Custom Tile Provider

但折线在低级别缩放时重叠.

android – Google Maps v2 Custom Tile Provider

我的自定义磁贴提供程序类是

public class PolylineTileProvider implements TileProvider {
private static final String TAG = "TiLeoverlay";
private final int mTileSize = 256;
private final SphericalMercatorProjection mProjection = new SphericalMercatorProjection(mTileSizE);
private final int mScale = 2;
private final int mDimension = mScale * mTileSize;
private final List<PolylineOptions> polylines;

public PolylineTileProvider(List<PolylineOptions> polylines) {
    this.polylines = polylines;
}

@Override
public Tile getTile(int x,int y,int zoom) {
    Matrix matrix = new Matrix();
    float scale = ((float) Math.pow(2,zoom) * mScalE);
    matrix.postScale(scale,scalE);
    matrix.postTranslate(-x * mDimension,-y * mDimension);
    Bitmap bitmap = Bitmap.createBitmap(mDimension,mDimension,Bitmap.Config.ARGB_8888); //save memory on old phones
    Canvas c = new Canvas(bitmap);
    c.setMatrix(matriX);
    drawCanvasFromArray(c,scalE);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG,100,baos);
    return new Tile(mDimension,baos.toByteArray());
}

private void drawCanvasFromArray(Canvas c,float scalE) {

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.stroke);
    paint.setstrokeCap(Paint.Cap.ROUND);
    paint.setstrokeJoin(Paint.Join.ROUND);
    paint.setShadowLayer(0,0);
    paint.setAntiAlias(true);

    if (polylines != null) {
        for (int i = 0; i < polylines.size(); i++) {
            List<LatLng> route = polylines.get(i).getPoints();
            paint.setColor(polylines.get(i).getColor());
            paint.setstrokeWidth(getLineWidth(polylines.get(i).getWidth(),scalE));
            Path path = new Path();
            if (route != null && route.size() > 1) {
                Point screenPt1 = mProjection.toPoint(route.get(0)); //first point
                MarkerOptions m = new MarkerOptions();
                m.position(route.get(0));
                path.moveTo((float) screenPt1.x,(float) screenPt1.y);
                for (int j = 1; j < route.size(); j++) {
                    Point screenPt2 = mProjection.toPoint(route.get(j));
                    path.lineTo((float) screenPt2.x,(float) screenPt2.y);
                }
            }
            c.drawPath(path,paint);
        }
    }
}

private float getLineWidth(float width,float scalE) {
    return width / (scalE);
}
}

Trafic图层在Google Maps android应用程序中显示得非常好.

android – Google Maps v2 Custom Tile Provider

我怎样才能制作一个类似的图层.提前致谢.

解决方法

它之所以模糊,或者可能在屏幕上看不到,是因为你创建了一个图像,然后使用你提供的矩阵进行缩放.

相反,你不应该使用矩阵并生成正确大小的图像.

Todo所以,删除你在Canvas上的setMatrix调用

使用正确的缩放坐标将点添加到路径.

x = screenPt1.x * scale - x * mDimension;
 y = screenPt1.y * scale - y * mDimension;

然后在每个缩放级别获得指定的确切行.

大佬总结

以上是大佬教程为你收集整理的android – Google Maps v2 Custom Tile Provider全部内容,希望文章能够帮你解决android – Google Maps v2 Custom Tile Provider所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。