GisMobi,欢迎关注

专注移动Gis开发,Android,Windows Mobile,WP,iOS

基于Arcgis for Android runtime在地图上画圆

本人参照DrawTools改编实现,具体出处不详. 更多信息请关注 www.gismobi.com

代码如下:

//----------------------绘制圆形-----------------------
    private static GraphicsLayer drawCircleLayer = null;

    /**
     * 清除绘制圆的图层
     */
    public void clearDrawCircleLayer() {
        if (drawCircleLayer != null) {
            drawCircleLayer.removeAll();
        }
    }

    /**
     * 绘制圆,配合 clearDrawCircleLayer()清除
     *
     * @param center 圆心
     * @param radius 半径
     * @param alpha 填充的透明度 0-100
     * @param fillColor 填充的颜色
     */
    public static void DrawCircle(Point center, double radius, int alpha, int fillColor) {
        if (drawCircleLayer == null) { //是否已添加绘制图层
            drawCircleLayer = new GraphicsLayer();
            _map.addLayer(drawCircleLayer);
        }
        Polygon polygon = new Polygon();
        getCircle(center, radius, polygon);
        FillSymbol symbol = new SimpleFillSymbol(fillColor);
        symbol.setAlpha(alpha);

        Graphic g = new Graphic(polygon,symbol);
        drawCircleLayer.addGraphic(g);
    }

    /**
     * 获取圆的图形对象
     *
     * @param center
     * @param radius
     * @return
     */
    public static Polygon getCircle(Point center, double radius) {
        Polygon polygon = new Polygon();
        getCircle(center, radius, polygon);
        return polygon;
    }

    private static void getCircle(Point center, double radius, Polygon circle) {
        circle.setEmpty();
        Point[] points = getPoints(center, radius);
        circle.startPath(points[0]);
        for (int i = 1; i < points.length; i++)
            circle.lineTo(points[i]);
    }

    private static Point[] getPoints(Point center, double radius) {
        Point[] points = new Point[50];
        double sin;
        double cos;
        double x;
        double y;
        for (double i = 0; i < 50; i++) {
            sin = Math.sin(Math.PI * 2 * i / 50);
            cos = Math.cos(Math.PI * 2 * i / 50);
            x = center.getX() + radius * sin;
            y = center.getY() + radius * cos;
            points[(int) i] = new Point(x, y);
        }
        return points;
    }


阅读更多
个人分类: Arcgis for Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

基于Arcgis for Android runtime在地图上画圆

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭