我正試圖在Android地圖上使用Google地圖引擎覆蓋地圖上的不規則多邊形。Android帆布:填充時多邊形會變形(Paint.Style.Fill)?
這是一個示例代碼,我正在測試...覆蓋Overlay類的繪製方法。
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
points.add(getPoint(40.69601721120307,-7.975247972597344));
points.add(getPoint(39.59209428101375,-5.602198679879018));
points.add(getPoint(37.98114679179523,-5.43877491468928));
points.add(getPoint(39.01059159609532,-4.050442951443798));
points.add(getPoint(37.99556954318146,-1.728440918734253));
points.add(getPoint(39.26565517073047,-2.576421100521262));
points.add(getPoint(40.21994329403012,-1.164105822610836));
points.add(getPoint(40.57540056971796,-3.415060042751821));
points.add(getPoint(42.5081775151286,-4.553753858729792));
points.add(getPoint(40.74284989396188,-5.388244948956315));
points.add(getPoint(40.69601721120307,-7.975247972597344));
Paint mPaint = new Paint();
mPaint.setColor(Color.RED);
mPaint.setStyle(Style.STROKE);
mPaint.setStrokeWidth(2);
Point point1 = null;
Path path = new Path();
for(GeoPoint p : points){
Point point2 = new Point();
mapView.getProjection().toPixels(p, point2);
if(point1 != null){
path.lineTo(point2.x, point2.y);
canvas.drawPath(path, mPaint);
mapView.getProjection().toPixels(p, point1);
} else {
point1 = new Point();
mapView.getProjection().toPixels(p, point1);
path.moveTo(point1.x, point1.y);
}
}
return true;
}
當我運行測試,我可以在地圖上看到這樣的結果:
然而,當我改變風格Style.STROKE_FILL或Style.FILL我得到的下面上圖:
我發現在論壇上沒有解決這個問題。
我將不勝感激任何幫助。
謝謝。
謝謝soooo多! :) –
它工作?如果有的話,請接受答案。 – Simon