多边形不是没有填写android mapview

时间:2012-12-27 14:27:35

标签: android google-maps canvas fill polygons

我正在尝试在我的应用中的地图视图上绘制填充多边形。无论我尝试过什么,它都不会被填满。我可以让笔画出现,但我无法填写。下面是我的多边形类的绘制方法。它会覆盖叠加层。

public void draw(Canvas canvas, MapView mapv, boolean shadow) {
            super.draw(canvas, mapv, shadow);

            Paint mPaint = new Paint();

            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setColor(Color.BLACK);
            mPaint.setStrokeJoin(Paint.Join.ROUND);
            mPaint.setStrokeCap(Paint.Cap.ROUND);
            mPaint.setStrokeWidth(6);

            Paint mPaintFill = new Paint();

            mPaintFill.setStyle(Paint.Style.FILL);
            mPaintFill.setColor(Color.GREEN);

            Path path = new Path();

            GeoPoint start = route.get(0);
            for (int i = 1; i < route.size(); ++i) {
                    Point p1 = new Point();
                    Point p2 = new Point();

                    Projection projection = mapv.getProjection();
                    projection.toPixels(start, p1);
                    projection.toPixels(route.get(i), p2);

                    path.moveTo(p2.x, p2.y);
                    path.lineTo(p1.x, p1.y);

                    start = route.get(i);
            }              


            canvas.drawPath(path, mPaint);
            canvas.drawPath(path, mPaintFill);
            //canvas.clipPath(path, Op.DIFFERENCE); 
    }

上面的代码对我来说会正确绘制线条但是没有填写。删除canvas.drawPath(path,mPaint);而只是离开填充一个导致地图上没有任何显示。我甚至尝试将Paint.Style.STROKE设置为Paint.Style.FILL_AND_STROKE。我完全失去了,在这一点上,我认为这是一个简单的事情,我一直在寻找。

0 个答案:

没有答案