最近,我通过创建一个覆盖类并使用路径绘制它,在我的国家周围绘制了一个自定义多边形。我有很多地图扇区,每个扇区都被划分并用覆盖类填充颜色。但是,当我使用 ontap 函数时,只会调用最后一个覆盖项 ontap 函数。
我相信是因为我没有为叠加层设置边界?以下是我的叠加代码
public class SectorOverlay extends Overlay{
CustomPolygon customPolygon =null;
Context context;
public SectorOverlay(Context context, CustomPolygon customPolygon) {
this.context=context;
this.customPolygon =customPolygon;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
shadow=false;
Paint paint = new Paint();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(2);
paint.setColor(0x10000000);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);
Point point1_draw = new Point();
if(customPolygon!=null)
{
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
for(int n=0;n<customPolygon.getCorrdinateList().size();n++)
{
GeoPoint sector1 = new GeoPoint((int)(customPolygon.getCorrdinateList().get(n).getLatitude()*1e6), (int)((customPolygon.getCorrdinateList().get(n).getLongitude())*1e6));
if(n==0){
mapView.getProjection().toPixels(sector1, point1_draw);
path.moveTo(point1_draw.x,point1_draw.y);
}else
{
mapView.getProjection().toPixels(sector1, point1_draw);
path.lineTo(point1_draw.x,point1_draw.y);
}
}
path.close();
canvas.drawPath(path, paint);
}
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
new CommonOpearation().showToast(context, customPolygon.getName());
return true;
}
}