动态绘制的Andr​​oid图形页面多GeoPoints之间的行 [英] Dynamically draw lines between multiple GeoPoints in Android MapView

查看:117
本文介绍了动态绘制的Andr​​oid图形页面多GeoPoints之间的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发有一个MapView的一些自定义覆盖的应用程序 - 再presenting船只。当选择一个容器,我显示在地图上previous位置,再次定制覆盖的项目,我想他们用线连接。

I am developing an application that has a few custom overlays on a MapView - representing vessels. When selecting a vessel, I am showing its previous positions on the map, again with custom overlay items, and I would like to connect them with a line.

我在这里看到一些相关的问题被重写Draw方法解决,并通过硬编码GeoPoints坐标绘制方法。这并不能帮助我的人,因为我有不同的船只多点,并且不能硬$ C C他们都$成平局。

Some relevant problems I saw here were solved by overriding the Draw method, and by hard-coding the GeoPoints' coordinates in the Draw method. That does not help me at all, since I have many points from different vessels, and cannot hard-code them all into Draw.

有只绘制GeoPoints之间的线内的for循环用来显示自定义的叠加?一个简单的方法

Is there a simple way to just draw a line between the GeoPoints inside the for loop used to display the custom overlays??

感谢你在前进。

推荐答案

使用了投影图形页面的为了GeoPoints转换为画面之分。之后,你可以使用路径来绘制所需的行。第一点应与 path.moveTo(X,Y),其余与 path.lineTo(X,Y)。在最后,你叫 canvas.drawPath(路径)和你做。

Use the Projection from the MapView in order to convert GeoPoints to "screen" points. After that you can use Path to draw the line that you want. The first point should be specified with path.moveTo(x, y) and the rest with path.lineTo(x, y). At the end you call canvas.drawPath(path) and you are done.

下面是我的draw()方法绘制围绕一组点的多边形A code。请注意,您不必使用 path.close(),因为我做了我的code。

Below is a code from my draw() method that draws a polygon around a set of points. Note that you do not have to use path.close() as I did on my code.

public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow){
    if(shadow){
        if(isDrawing == false){
            return;
        }
        Projection proj = mapView.getProjection();

        boolean first = true;
        /*Clear the old path at first*/
        path.rewind();
        /* The first tap */
        Paint circlePaint = new Paint();
        Point tempPoint = new Point();
        for(GeoPoint point: polygon){
            proj.toPixels(point, tempPoint);
            if(first){
                path.moveTo(tempPoint.x, tempPoint.y);
                first = false;
                circlePaint.setARGB(100, 255, 117, 0);
                circlePaint.setAntiAlias(true);
                canvas.drawCircle(tempPoint.x, tempPoint.y, FIRST_CIRCLE_RADIOUS, circlePaint);
            }
            else{
                path.lineTo(tempPoint.x, tempPoint.y);
                circlePaint.setARGB(100, 235, 0, 235);
                circlePaint.setAntiAlias(true);
                canvas.drawCircle(tempPoint.x, tempPoint.y, CIRCLE_RADIOUS, circlePaint);
            }
        }
        /* If indeed is a polygon just close the perimeter */
        if(polygon.size() > 2){
            path.close();
        }
        canvas.drawPath(path, polygonPaint);
        super.draw(canvas, mapView, shadow);
    }
}

这篇关于动态绘制的Andr​​oid图形页面多GeoPoints之间的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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