Java Code Examples for com.nextgis.maplib.datasource.GeoLineString#getPoints()

The following examples show how to use com.nextgis.maplib.datasource.GeoLineString#getPoints() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleLineStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Path drawSolidLine(float scaledWidth, GeoLineString lineString, GISDisplay display) {
    Paint paint = new Paint();
    paint.setColor(mColor);
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeCap(mStrokeCap);
    paint.setStrokeWidth(scaledWidth);

    List<GeoPoint> points = lineString.getPoints();

    Path path = new Path();
    path.incReserve(points.size());

    path.moveTo((float) points.get(0).getX(), (float) points.get(0).getY());

    for (int i = 1; i < points.size(); ++i) {
        path.lineTo((float) points.get(i).getX(), (float) points.get(i).getY());
    }

    display.drawPath(path, paint);

    return path;
}
 
Example 2
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Path getPath(GeoLineString lineString) {
    List<GeoPoint> points = lineString.getPoints();
    Path path = new Path();
    float x0, y0;

    if (points.size() > 0) {
        x0 = (float) points.get(0).getX();
        y0 = (float) points.get(0).getY();
        path.moveTo(x0, y0);

        for (int i = 1; i < points.size(); i++) {
            x0 = (float) points.get(i).getX();
            y0 = (float) points.get(i).getY();

            path.lineTo(x0, y0);
        }
    }

    return path;
}
 
Example 3
Source File: SimpleLineStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Path drawSolidEdgingLine(float scaledWidth, GeoLineString lineString, GISDisplay display) {
    Paint mainPaint = new Paint();
    mainPaint.setColor(mColor);
    mainPaint.setAntiAlias(true);
    mainPaint.setStyle(Paint.Style.STROKE);
    mainPaint.setStrokeCap(Paint.Cap.BUTT);
    mainPaint.setStrokeWidth(scaledWidth);

    Paint edgingPaint = new Paint(mainPaint);
    edgingPaint.setColor(mOutColor);
    edgingPaint.setStrokeCap(Paint.Cap.BUTT);
    edgingPaint.setStrokeWidth(scaledWidth * 3);

    List<GeoPoint> points = lineString.getPoints();

    Path path = new Path();
    path.incReserve(points.size());

    path.moveTo((float) points.get(0).getX(), (float) points.get(0).getY());

    for (int i = 1; i < points.size(); ++i) {
        path.lineTo((float) points.get(i).getX(), (float) points.get(i).getY());
    }

    display.drawPath(path, edgingPaint);
    display.drawPath(path, mainPaint);

    return path;
}
 
Example 4
Source File: SimpleLineStyle.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected Path drawDashLine(float scaledWidth, GeoLineString lineString, GISDisplay display) {
    Paint paint = new Paint();
    paint.setColor(mColor);
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeCap(Paint.Cap.BUTT);
    paint.setStrokeWidth(scaledWidth);

    List<GeoPoint> points = lineString.getPoints();

    // workaround for "DashPathEffect/drawLine not working properly when hardwareAccelerated="true""
    // https://code.google.com/p/android/issues/detail?id=29944

    // get all points to the main path
    Path mainPath = new Path();
    mainPath.incReserve(points.size());

    mainPath.moveTo((float) points.get(0).getX(), (float) points.get(0).getY());

    for (int i = 1; i < points.size(); ++i) {
        mainPath.lineTo((float) points.get(i).getX(), (float) points.get(i).getY());
    }

    // draw along the main path
    PathMeasure pm = new PathMeasure(mainPath, false);
    float[] coordinates = new float[2];
    float length = pm.getLength();
    float dash = (float) (10 / display.getScale());
    float gap = (float) (5 / display.getScale());
    float distance = dash;
    boolean isDash = true;

    Path dashPath = new Path();
    dashPath.incReserve((int) (2 * length / (dash + gap)));

    dashPath.moveTo((float) points.get(0).getX(), (float) points.get(0).getY());

    while (distance < length) {
        // get a point from the main path
        pm.getPosTan(distance, coordinates, null);

        if (isDash) {
            dashPath.lineTo(coordinates[0], coordinates[1]);
            distance += gap;
        } else {
            dashPath.moveTo(coordinates[0], coordinates[1]);
            distance += dash;
        }

        isDash = !isDash;
    }

    // add a rest from the main path
    if (isDash) {
        distance = distance - dash;
        float rest = length - distance;

        if (rest > (float) (1 / display.getScale())) {
            distance = length - 1;
            pm.getPosTan(distance, coordinates, null);
            dashPath.lineTo(coordinates[0], coordinates[1]);
        }
    }

    display.drawPath(dashPath, paint);

    return mainPath;
}