圈画在图形页面透明度 [英] draw circle with transparency in mapview

查看:116
本文介绍了圈画在图形页面透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图形页面和覆盖的问题。

我一定要画在地图上的每次改变GPS位置的圆。
我使用的方法战平扩展覆盖我的叠加类。
问题是,我必须提请这些圆圈的透明度,但是当圈的交汇点相互重叠点是不同的颜色,因为有阿尔法的总和。

我怎样才能解决这个问题?

这是我的叠加类:

公共类ImpactOverlay扩展覆盖{私有静态诠释CIRCLERADIUS = 0;
私人的GeoPoint的GeoPoint;
私人诠释myCircleRadius;
逐点=新点();
油漆圈=新的油漆(Paint.ANTI_ALIAS_FLAG);
私人长期SYSTEMTIME = -1;公共ImpactOverlay(GeoPoint的角度,诠释myRadius){    的GeoPoint =点;
    CIRCLERADIUS = myRadius; // assegna raggio德尔cerchio
}@覆盖
公共无效画(油画画布,MapView类MapView类,布尔阴影){     // Transfrom geoposition到点在画布上
     投影投影= MapView.getProjection()在;
     projection.toPixels(GeoPoint对象,点);     //圆圈标记现货
     circle.setColor(Color.parseColor(#88ff0000));
     circle.setAlpha(122); // trasparenza     myCircleRadius = metersToRadius(CIRCLERADIUS,MapView类,
     (双)geopoint.getLatitudeE6()/ 1000000);     canvas.drawCircle(point.x,point.y,myCircleRadius,圆圈);}公共静态INT metersToRadius(浮点米,MapView的地图,双纬度){
    回报(INT)(map.getProjection()。metersToEquatorPixels(米)*(1 /数学
            名为.cos(Math.toRadians(纬度))));
}@覆盖
每eseguire变焦苏拉mappa / * Implementa IL Doppio的自来水* /
公共布尔onTouchEvent(MotionEvent事件,MapView类MapView类){
    开关(event.getAction()){
    案例MotionEvent.ACTION_DOWN:
        如果((System.currentTimeMillis的() - SYSTEMTIME)所述; 250){
            。mapView.getController()zoomIn();
        }
        SYSTEMTIME = System.currentTimeMillis的();
        打破;
    }    返回false;
}
}


解决方案

  CircleOptions圈=新CircleOptions();
        circle.center(新经纬度(纬度,经度))
        .radius(1500)//在米
        .strokeColor(Color.BLUE)//边框颜色
        .strokeWidth(3.0F)//边框宽度
        .fillColor(0x200000ff); //内圆
        googleMap.addCircle(圈); // GoogleMap的GoogleMap的(相应的初始化)

I have a problem with mapview and Overlay.

I must to draw a circle on the map everytime that change GPS position. I used the method draw in my overlay class that extend overlay. The problem is that I must draw these circles with transparency, but when the circles overlap each other in the intersection point the color it's different because there is a sum of alpha.

How I can fix it?

This is my overlay class:

public class ImpactOverlay extends Overlay {

private static int CIRCLERADIUS = 0;
private GeoPoint geopoint;
private int myCircleRadius;
Point point = new Point();
Paint circle = new Paint(Paint.ANTI_ALIAS_FLAG);
private long systemTime= -1 ;



public ImpactOverlay(GeoPoint point, int myRadius) {

    geopoint = point;
    CIRCLERADIUS = myRadius; // assegna raggio del cerchio
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {

     // Transfrom geoposition to Point on canvas
     Projection projection = mapView.getProjection();
     projection.toPixels(geopoint, point);

     // the circle to mark the spot
     circle.setColor(Color.parseColor("#88ff0000"));
     circle.setAlpha(122); // trasparenza

     myCircleRadius = metersToRadius(CIRCLERADIUS, mapView,
     (double) geopoint.getLatitudeE6() / 1000000);

     canvas.drawCircle(point.x, point.y, myCircleRadius, circle);       

}



public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1 / Math
            .cos(Math.toRadians(latitude))));
}

@Override
/* Implementa il doppio tap per eseguire zoom sulla mappa */
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if ((System.currentTimeMillis() - systemTime) < 250) {
            mapView.getController().zoomIn();
        }
        systemTime = System.currentTimeMillis();
        break;
    }

    return false;
}
}

解决方案

        CircleOptions circle = new CircleOptions();
        circle.center(new LatLng(latitude, longitude))
        .radius(1500)//in meters
        .strokeColor(Color.BLUE)//border color
        .strokeWidth(3.0f)//border width
        .fillColor(0x200000ff);//inside circle
        googleMap.addCircle(circle);//GoogleMap googleMap(initialize accordingly)

这篇关于圈画在图形页面透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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