在Google Map V2中的多边形上绘制网格 [英] Draw grid over polygon in Google map V2

查看:168
本文介绍了在Google Map V2中的多边形上绘制网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Google Map v2上制作了一个多边形,现在我要在该多边形上添加一个网格,如参考图像所示,并且网格必须重新调整大小,并且网格的某些部分应该是可选的.

I have made one polygon over Google map v2 and now on that polygon I want to add one grid as shown in Reference Image and that grid should have to re-sizable and portions of grid should be selectable.

我对此没有任何想法,因此请对此提供帮助. 到目前为止,我一直在尝试此操作,但仍然没有任何结果. 感谢您的所有帮助.

I don't have any idea about this so please help on this. I am trying this so far but still don't have any result. All your help is appreciated.

参考图片:

推荐答案

不确定Google Maps,但是对于osmdroid,您应该使用

Not sure about Google Maps, but with osmdroid you should use osmbonuspack and implement a custom Polygon:

public class GridPolygon extends Polygon {

    private BitmapShader bitmapShader;
    private IGeoPoint lastCenterGeoPoint;
    private int xOffset = 0;
    private int yOffset = 0;

    public GridPolygon(Context ctx) {
        super(ctx);
    }

    public void setPatternBMP(@NonNull final Bitmap patternBMP) {
        bitmapShader = new BitmapShader(patternBMP, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        mFillPaint.setShader(bitmapShader);
    }

    protected void recalculateMatrix(@NonNull final MapView mapView) {
        //final int mapSize = TileSystem.MapSize(mapView.getZoomLevel());

        final Projection projection = mapView.getProjection();
        final IGeoPoint geoPoint = mapView.getMapCenter();
        if (lastCenterGeoPoint == null) lastCenterGeoPoint = geoPoint;

        final Point point = projection.toPixels(geoPoint, null);
        final Point lastCenterPoint = projection.toPixels(lastCenterGeoPoint, null);

        xOffset += lastCenterPoint.x - point.x;
        yOffset += lastCenterPoint.y - point.y;

        xOffset %= 100; // 100 is pixel size of shader image
        yOffset %= 100;

        final Matrix matrix = new Matrix();
        matrix.reset();
        matrix.setScale(1,1);
        matrix.preTranslate(xOffset, yOffset);
        //matrix.setTranslate(xOffset, yOffset);
        bitmapShader.setLocalMatrix(matrix);

        mFillPaint.setShader(bitmapShader);

        lastCenterGeoPoint = geoPoint;
    }

    @Override
    protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
        recalculateMatrix(mapView);
        super.draw(canvas, mapView, shadow);
    }
}

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆