com.nextgis.maplib.datasource.GeoLineString Java Examples

The following examples show how to use com.nextgis.maplib.datasource.GeoLineString. 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: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void fillDrawLine(GeoLineString lineString) {
    GeoPoint[] geoPoints =
            lineString.getPoints().toArray(new GeoPoint[lineString.getPointCount()]);
    float[] points = mapToScreen(geoPoints);

    mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, points);
    mDrawItems.add(mSelectedItem);

    if (points.length < 2)
        return;

    float[] edgePoints = new float[points.length - 2];
    for (int i = 0; i < points.length - 2; i++)
        edgePoints[i] = (points[i] + points[i + 2]) * .5f;

    mSelectedItem.addEdges(edgePoints);
}
 
Example #2
Source File: SimpleLineStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void onDraw(GeoLineString lineString, GISDisplay display) {
    if (null == lineString) {
        return;
    }

    float scaledWidth = (float) (mWidth / display.getScale());
    Path mainPath = null;
    switch (mType) {
        case LineStyleSolid:
            mainPath = drawSolidLine(scaledWidth, lineString, display);
            break;

        case LineStyleDash:
            mainPath = drawDashLine(scaledWidth, lineString, display);
            break;

        case LineStyleEdgingSolid:
            mainPath = drawSolidEdgingLine(scaledWidth, lineString, display);
            break;
    }

    drawText(scaledWidth, mainPath, display);
}
 
Example #3
Source File: SimpleLineStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    mColor = Color.argb(mInnerAlpha, Color.red(mColor), Color.green(mColor), Color.blue(mColor));
    mOutColor = Color.argb(mOuterAlpha, Color.red(mOutColor), Color.green(mOutColor), Color.blue(mOutColor));

    switch (geoGeometry.getType()) {
        case GTLineString:
            onDraw((GeoLineString) geoGeometry, display);
            break;

        case GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geoGeometry;
            for (int i = 0; i < multiLineString.size(); i++) {
                onDraw(multiLineString.get(i), display);
            }
            break;

        //throw new IllegalArgumentException(
        //        "The input geometry type is not support by this style");
    }

}
 
Example #4
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 #5
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 #6
Source File: TrackLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadTrack(int trackId)
{
    Cursor track = getTrack(trackId);

    if (track == null || !track.moveToFirst()) {
        return;
    }

    float x0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LON)),
            y0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LAT));

    GeoLineString trackLine = new GeoLineString();
    trackLine.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    trackLine.add(new GeoPoint(x0, y0));

    while (track.moveToNext()) {
        x0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LON));
        y0 = track.getFloat(track.getColumnIndex(TrackLayer.FIELD_LAT));
        trackLine.add(new GeoPoint(x0, y0));
    }

    mTracks.put(trackId, trackLine);
}
 
Example #7
Source File: RulerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRestoreState(Bundle bundle) {
    if (bundle.containsKey(BUNDLE_GEOMETRY))
        try {
            mRulerString = (GeoLineString) GeoGeometryFactory.fromBlob(bundle.getByteArray(BUNDLE_GEOMETRY));
        } catch (IOException e) {
            e.printStackTrace();
        }

    super.onRestoreState(bundle);
}
 
Example #8
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 #9
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    switch (geoGeometry.getType()) {
        case GTPolygon:
            drawPolygon((GeoPolygon) geoGeometry, display);
            break;
        case GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geoGeometry;

            for (int i = 0; i < multiPolygon.size(); i++) {
                drawPolygon(multiPolygon.get(i), display);
            }
            break;
        case GTPoint:
            drawPoint((GeoPoint) geoGeometry, display);
            break;
        case GTMultiPoint:
            GeoMultiPoint multiPoint = (GeoMultiPoint) geoGeometry;
            for (int i = 0; i < multiPoint.size(); i++) {
                drawPoint(multiPoint.get(i), display);
            }
            break;
        case GTLineString:
            drawLineString((GeoLineString) geoGeometry, display);
            break;
        case GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geoGeometry;
            for (int i = 0; i < multiLineString.size(); i++) {
                drawLineString(multiLineString.get(i), display);
            }
            break;
    }
}
 
Example #10
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void drawLineString(GeoLineString line, GISDisplay display) {
    final Paint lnPaint = new Paint();
    lnPaint.setColor(mColor);
    lnPaint.setAlpha(mOuterAlpha);
    lnPaint.setStrokeWidth((float) (mWidth / display.getScale()));
    lnPaint.setStrokeCap(Paint.Cap.ROUND);
    lnPaint.setAntiAlias(true);

    final Path linePath = getPath(line);

    lnPaint.setStyle(Paint.Style.STROKE);
    display.drawPath(linePath, lnPaint);
}
 
Example #11
Source File: TrackLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Map<Integer, GeoLineString> getTracks()
{
    if (mTracks.size() == 0) {
        reloadTracks(INSERT);
    }

    return mTracks;
}
 
Example #12
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected String getRulerText() {
    GeoPoint p1 = new GeoPoint(mScaleRuler.getLeft(), mScaleRuler.getBottom());
    GeoPoint p2 = new GeoPoint(mScaleRuler.getRight(), mScaleRuler.getBottom());
    p1 = mMap.getMap().screenToMap(p1);
    p2 = mMap.getMap().screenToMap(p2);
    p1.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    p2.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    GeoLineString s = new GeoLineString();
    s.add(p1);
    s.add(p2);

    return LocationUtil.formatLength(getContext(), s.getLength(), 1);
}
 
Example #13
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void fillDrawItems(GeoGeometry geom) {
    int lastItemsCount = mDrawItems.size();
    int lastSelectedItemPosition = mDrawItems.indexOf(mSelectedItem);
    DrawItem lastSelectedItem = mSelectedItem;
    mDrawItems.clear();

    if (null == geom) {
        Log.w(Constants.TAG, "the geometry is null in fillDrawItems method");
        return;
    }

    GeoPoint[] geoPoints = new GeoPoint[1];
    Location last = mGpsEventSource.getLastKnownLocation();
    switch (geom.getType()) {
        case GeoConstants.GTPoint:
            geoPoints[0] = (GeoPoint) geom;
            mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
            mDrawItems.add(mSelectedItem);
            break;
        case GeoConstants.GTMultiPoint:
            GeoMultiPoint geoMultiPoint = (GeoMultiPoint) geom;
            for (int i = 0; i < geoMultiPoint.size(); i++) {
                geoPoints[0] = geoMultiPoint.get(i);
                mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
                mDrawItems.add(mSelectedItem);
            }
            break;
        case GeoConstants.GTLineString:
            fillDrawLine((GeoLineString) geom);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geom;
            for (int i = 0; i < multiLineString.size(); i++)
                fillDrawLine(multiLineString.get(i));
            break;
        case GeoConstants.GTPolygon:
            fillDrawPolygon((GeoPolygon) geom);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geom;
            for (int i = 0; i < multiPolygon.size(); i++)
                fillDrawPolygon(multiPolygon.get(i));
            break;
        case GeoConstants.GTGeometryCollection:
            GeoGeometryCollection collection = (GeoGeometryCollection) geom;
            for (int i = 0; i < collection.size(); i++) {
                GeoGeometry geoGeometry = collection.get(i);
                fillDrawItems(geoGeometry);
            }
            break;
        default:
            break;
    }

    if (mDrawItems.size() == lastItemsCount && lastSelectedItem != null &&
            lastSelectedItemPosition != Constants.NOT_FOUND) {
        mSelectedItem = mDrawItems.get(lastSelectedItemPosition);
        mSelectedItem.setSelectedRing(lastSelectedItem.getSelectedRingId());
        mSelectedItem.setSelectedPoint(lastSelectedItem.getSelectedPointId());
    } else {
        mSelectedItem = mDrawItems.get(0);
    }

    switch (geom.getType()) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTMultiPoint:
            updateDistance(last, null);
            break;
    }
}
 
Example #14
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;
}