2015-12-25 161 views
4

我已經在Google地圖v2上製作了一個多邊形,現在在該多邊形上我想添加一個網格,如參考圖片並且該網格應該具有可重定尺寸以及部分網格應該可以選擇。谷歌地圖V2中的多邊形上繪製網格

我對此沒有任何想法,所以請在此幫忙。 我想這個到目前爲止,但仍然沒有任何結果。 所有的幫助表示讚賞。

參考圖片:

Reference Image

+0

你好,你做到了嗎? – David

回答

1

不知道關於谷歌地圖,但你應該使用osmbonuspack並實現自定義的多邊形osmdroid:

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); 
    } 
} 

enter image description here

Full source code

+1

那形狀看起來很熟悉! ;) – Reafidy