Get current OverlayItem value

I want to get some link to the current object that is being drawn

@Override
        public void draw(Canvas canvas, MapView mapView,boolean shadow) {
            //Log.i("DRAW","MARKER");
            super.draw(canvas, mapView, false);
        }

Above is my draw method, and I want to extend the draw method to write a title under each element, for example. This will require the .getTitle () method from OverlayItem. Some tracking of objects outside of this method is possible, but not sure where to put it ....

+3
source share
1 answer

I did something similar. I added a few labels to MapView, and then connected them to the line.

I have a class LineOverlaythat extends Overlay. In the constructor, he gets a list of elements that should be connected by lines.

Sort of:

public LineOverlay(ItemizedOverlay<? extends OverlayItem> itemizedOverlay, int lineColor) {
    mItemizedOverlay = itemizedOverlay;
    colorRGB = lineColor;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(colorRGB);
    mPaint.setStrokeWidth(LINE_WIDTH);
}

onDraw() :

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    if ( mItemizedOverlay.size() == 0 || mItemizedOverlay.size() == 1 )
        return;

    Projection projection = mapView.getProjection();

    int i = 0;

    while( i < mItemizedOverlay.size() - 1 ){
        OverlayItem begin = mItemizedOverlay.getItem(i);
        OverlayItem end = mItemizedOverlay.getItem(i+1);
        paintLineBetweenStations(begin,end,projection,canvas);
        i++;
    }

    super.draw(canvas, mapView, shadow);
}

private void paintLineBetweenStations(OverlayItem from, OverlayItem to, Projection projection, Canvas canvas){
    GeoPoint bPoint = from.getPoint();
    GeoPoint ePoint = to.getPoint();

    Point bPixel = projection.toPixels(bPoint, null);
    Point ePixel = projection.toPixels(ePoint, null);

    canvas.drawLine(bPixel.x, bPixel.y, ePixel.x, ePixel.y, mPaint);
}

- , SubtitleOverlay, Overlay, , draw .

0

Source: https://habr.com/ru/post/1753647/


All Articles