Skip to content
Permalink
Browse files

bug/#1280 - possibility to draw Polylines using Path (#1285)

New classes:
* `PolyOverlayWithIW`: extending `OverlayWithIW`, extended by both `Polyline` and `Polygon` given the number of common methods
* `SampleDrawPolylineAsPath`: sample similar to `SampleDrawPolyline`, but where `Polyline`s are drawing in the "path" mode (and not in the "lines" mode)

Impacted classes:
* `CustomPaintingSurface`: created mode `PolylineAsPath`; put alpha in the color in order to see the vertices for `Polyline`s
* `LinearRing`: added the `boolean` member `mClosed` in order to make both `Polyline` and `Polygon` draw using a `Path`; new constructor for `Path` with a `boolean pClosed` parameter; taking into account the `mClosed` member when building the `Path`
* `SampleFactory`: added `SampleDrawPolylineAsPath` just after `SampleDrawPolyline`
* `Polygon`: now extends new class `PolyOverlayWithIW`
* `Polyline`: now extends new class `PolyOverlayWithIW`

Impacted classes - slightly unrelated refactoring regarding `Paint`s:
* `Bug382Crash`
* `HeatMap`
* `LatLonGridlineOverlay`
* `LatLonGridlineOverlay2`
* `MarkerDrag`
* `MilStdMultipointOverlay`
* `OsmMapShapeConverter`
* `SampleMilestonesNonRepetitive`
* `SampleOsmPath`
* `SampleRace`
* `SampleZoomToBounding`
  • Loading branch information...
monsieurtanuki authored and spyhunter99 committed Sep 26, 2019
1 parent d80cc67 commit fadcd07de37ee583be65b2fd3794a2b7fde124d3
Showing with 422 additions and 365 deletions.
  1. +5 −5 OpenStreetMapViewer/src/main/java/org/osmdroid/bugtestfragments/Bug382Crash.java
  2. +2 −0 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/SampleFactory.java
  3. +5 −5 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/HeatMap.java
  4. +1 −1 ...treetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleMilestonesNonRepetitive.java
  5. +4 −4 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleOsmPath.java
  6. +3 −3 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleRace.java
  7. +10 −7 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/drawing/CustomPaintingSurface.java
  8. +26 −0 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/drawing/SampleDrawPolylineAsPath.java
  9. +2 −2 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/events/MarkerDrag.java
  10. +3 −3 OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/events/SampleZoomToBounding.java
  11. +10 −10 ...treetMapViewer/src/main/java/org/osmdroid/samplefragments/milstd2525/MilStdMultipointOverlay.java
  12. +20 −4 osmdroid-android/src/main/java/org/osmdroid/views/overlay/LinearRing.java
  13. +233 −0 osmdroid-android/src/main/java/org/osmdroid/views/overlay/PolyOverlayWithIW.java
  14. +30 −154 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Polygon.java
  15. +41 −140 osmdroid-android/src/main/java/org/osmdroid/views/overlay/Polyline.java
  16. +8 −8 osmdroid-android/src/main/java/org/osmdroid/views/overlay/gridlines/LatLonGridlineOverlay.java
  17. +8 −8 osmdroid-android/src/main/java/org/osmdroid/views/overlay/gridlines/LatLonGridlineOverlay2.java
  18. +11 −11 osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java
@@ -39,18 +39,18 @@ protected void addOverlays() {

polygon = new Polygon(mMapView);
polygon.setPoints(geoPoints.subList(0, 3));
polygon.setFillColor(0x96FF8200);
polygon.setStrokeColor(Color.RED);
polygon.setStrokeWidth(4);
polygon.getFillPaint().setColor(0x96FF8200);
polygon.getOutlinePaint().setColor(Color.RED);
polygon.getOutlinePaint().setStrokeWidth(4);
polygon.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, mMapView));
polygon.setTitle("Polygon tapped!");
mMapView.getOverlays().add(polygon);
mMapView.invalidate();

polyline = new Polyline(mMapView);
polyline.setPoints(geoPoints.subList(3, 6));
polyline.setColor(Color.YELLOW);
polyline.setWidth(8);
polyline.getOutlinePaint().setColor(Color.YELLOW);
polyline.getOutlinePaint().setStrokeWidth(8);
polyline.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, mMapView));
polyline.setTitle("Polyline tapped!");
mMapView.getOverlays().add(polyline);
@@ -36,6 +36,7 @@
import org.osmdroid.samplefragments.data.SampleRace;
import org.osmdroid.samplefragments.data.SampleSimpleFastPointOverlay;
import org.osmdroid.samplefragments.data.SampleSimpleLocation;
import org.osmdroid.samplefragments.drawing.SampleDrawPolylineAsPath;
import org.osmdroid.samplefragments.data.SampleSpeechBalloon;
import org.osmdroid.samplefragments.events.SampleAnimateToWithOrientation;
import org.osmdroid.samplefragments.events.SampleMapCenterOffset;
@@ -233,6 +234,7 @@ private SampleFactory() {
mSamples.add(SampleMyLocationWithClick.class);
//48
mSamples.add(SampleDrawPolyline.class);
mSamples.add(SampleDrawPolylineAsPath.class);
//49
mSamples.add(RecyclerCardView.class);
//50
@@ -289,19 +289,19 @@ public void run() {
private Overlay createPolygon(BoundingBox key, Integer value, int redthreshold, int orangethreshold) {
Polygon polygon = new Polygon(mMapView);
if (value < orangethreshold)
polygon.setFillColor(Color.parseColor(alpha + yellow));
polygon.getFillPaint().setColor(Color.parseColor(alpha + yellow));
else if (value < redthreshold)
polygon.setFillColor(Color.parseColor(alpha + orange));
polygon.getFillPaint().setColor(Color.parseColor(alpha + orange));
else if (value >= redthreshold)
polygon.setFillColor(Color.parseColor(alpha + red));
polygon.getFillPaint().setColor(Color.parseColor(alpha + red));
else {
//no polygon
}
polygon.setStrokeColor(polygon.getFillColor());
polygon.getOutlinePaint().setColor(polygon.getFillPaint().getColor());

//if you set this to something like 20f and have a low alpha setting,
// you'll end with a gaussian blur like effect
polygon.setStrokeWidth(0f);
polygon.getOutlinePaint().setStrokeWidth(0f);
List<GeoPoint> pts = new ArrayList<GeoPoint>();
pts.add(new GeoPoint(key.getLatNorth(), key.getLonWest()));
pts.add(new GeoPoint(key.getLatNorth(), key.getLonEast()));
@@ -85,7 +85,7 @@ public void addOverlays() {
}
final BoundingBox boundingBox = BoundingBox.fromGeoPoints(capitals);
polyline.setPoints(capitals);
polyline.setColor(Color.TRANSPARENT);
polyline.getOutlinePaint().setColor(Color.TRANSPARENT);
final List<MilestoneManager> managers = new ArrayList<>();
final MilestoneMeterDistanceSliceLister slicerForPath = new MilestoneMeterDistanceSliceLister();
managers.add(getAnimatedPathManager(slicerForPath));
@@ -81,7 +81,7 @@ protected void addOverlays() {
Polyline line = new Polyline(mMapView);
line.setTitle("Central Park, NYC");
line.setSubDescription(Polyline.class.getCanonicalName());
line.setWidth(20f);
line.getOutlinePaint().setStrokeWidth(20f);
List<GeoPoint> pts = new ArrayList<>();
//here, we create a polygon, note that you need 5 points in order to make a closed polygon (rectangle)

@@ -123,9 +123,9 @@ public boolean onClick(Polyline polyline, MapView mapView, GeoPoint eventPos) {
Polygon polygon = new Polygon(mMapView);
polygon.setTitle("This is a polygon");
polygon.setSubDescription(Polygon.class.getCanonicalName());
polygon.setFillColor(Color.RED);
polygon.getFillPaint().setColor(Color.RED);
polygon.setVisible(true);
polygon.setStrokeColor(Color.BLACK);
polygon.getOutlinePaint().setColor(Color.BLACK);
polygon.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, mMapView));


@@ -144,7 +144,7 @@ public boolean onClick(Polyline polyline, MapView mapView, GeoPoint eventPos) {
line = new Polyline(mMapView);
line.setTitle("TEST");
line.setSubDescription(Polyline.class.getCanonicalName());
line.setWidth(20f);
line.getOutlinePaint().setStrokeWidth(20f);
pts = new ArrayList<>();
//here, we create a polygon, note that you need 5 points in order to make a closed polygon (rectangle)

@@ -75,10 +75,10 @@ protected void addOverlays() {
super.addOverlays();

final Polyline line = new Polyline(mMapView);
line.setColor(COLOR_POLYLINE_STATIC);
line.setWidth(LINE_WIDTH_BIG);
line.getOutlinePaint().setColor(COLOR_POLYLINE_STATIC);
line.getOutlinePaint().setStrokeWidth(LINE_WIDTH_BIG);
line.setPoints(mGeoPoints);
line.getPaint().setStrokeCap(Paint.Cap.ROUND);
line.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
final List<MilestoneManager> managers = new ArrayList<>();
final MilestoneMeterDistanceSliceLister slicerForPath = new MilestoneMeterDistanceSliceLister();
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), org.osmdroid.library.R.drawable.next);
@@ -44,7 +44,8 @@ public void setMode(Mode mode) {
public enum Mode{
Polyline,
Polygon,
PolygonHole
PolygonHole,
PolylineAsPath
}
protected boolean withArrows=false;
private Bitmap mBitmap;
@@ -128,15 +129,17 @@ private void touch_up() {
//only plot a line unless there's at least one item
switch (drawingMode) {
case Polyline:
final int color = Color.BLACK;
Polyline line = new Polyline(map);
case PolylineAsPath:
final boolean asPath = drawingMode == Mode.PolylineAsPath;
final int color = Color.argb(100, 100, 100, 100);
final Polyline line = new Polyline(map, asPath);
line.setInfoWindow(
new BasicInfoWindow(org.osmdroid.library.R.layout.bonuspack_bubble, map));
line.setColor(color);
line.setTitle("This is a polyline");
line.getOutlinePaint().setColor(color);
line.setTitle("This is a polyline" + (asPath ? " as Path" : ""));
line.setPoints(geoPoints);
line.showInfoWindow();
line.getPaint().setStrokeCap(Paint.Cap.ROUND);
line.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
//example below
/*
line.setOnClickListener(new Polyline.OnClickListener() {
@@ -173,7 +176,7 @@ public boolean onClick(Polyline polyline, MapView mapView, GeoPoint eventPos) {
Polygon polygon = new Polygon(map);
polygon.setInfoWindow(
new BasicInfoWindow(org.osmdroid.library.R.layout.bonuspack_bubble, map));
polygon.setFillColor(Color.argb(75, 255,0,0));
polygon.getFillPaint().setColor(Color.argb(75, 255,0,0));
polygon.setPoints(geoPoints);
polygon.setTitle("A sample polygon");
polygon.showInfoWindow();
@@ -0,0 +1,26 @@
package org.osmdroid.samplefragments.drawing;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* @since 6.1.0
* @author Fabrice Fontaine
*/

public class SampleDrawPolylineAsPath extends SampleDrawPolyline {

@Override
public String getSampleTitle() {
return "Draw a polyline on screen as Path";
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View result = super.onCreateView(inflater, container, savedInstanceState);
paint.setMode(CustomPaintingSurface.Mode.PolylineAsPath);
return result;
}
}
@@ -45,8 +45,8 @@ public void addOverlays(){
OnMarkerDragListenerDrawer() {
mTrace = new ArrayList<GeoPoint>(100);
mPolyline = new Polyline(mMapView);
mPolyline.setColor(0xAA0000FF);
mPolyline.setWidth(2.0f);
mPolyline.getOutlinePaint().setColor(0xAA0000FF);
mPolyline.getOutlinePaint().setStrokeWidth(2.0f);
mPolyline.setGeodesic(true);
mMapView.getOverlays().add(mPolyline);
}
@@ -69,9 +69,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
btnCache.setOnClickListener(this);
btnCache.setText("Zoom to bounds");

polygon.setStrokeColor(Color.parseColor("#990000FF"));
polygon.setStrokeWidth(2);
polygon.setFillColor(Color.parseColor("#330000FF"));
polygon.getOutlinePaint().setColor(Color.parseColor("#990000FF"));
polygon.getOutlinePaint().setStrokeWidth(2);
polygon.getFillPaint().setColor(Color.parseColor("#330000FF"));
mMapView.getOverlays().add(polygon);

return root;
@@ -152,10 +152,10 @@ else if (!mCurrentCenter.equals(map.getMapCenter()))
}
line.setPoints(geoPoints);
if (info.getLineColor() != null)
line.setStrokeColor(info.getLineColor().toInt());
line.getOutlinePaint().setColor(info.getLineColor().toInt());
if (info.getFillColor() != null)
line.setFillColor(info.getFillColor().toInt());
line.setStrokeWidth(flot.getLineWidth());
line.getFillPaint().setColor(info.getFillColor().toInt());
line.getOutlinePaint().setStrokeWidth(flot.getLineWidth());
line.setId(id);
line.setTitle(name);
line.setSubDescription(description);
@@ -176,11 +176,11 @@ else if (!mCurrentCenter.equals(map.getMapCenter()))
}
line.setPoints(geoPoints);
if (info.getLineColor() != null)
line.setColor(info.getLineColor().toInt());
line.getOutlinePaint().setColor(info.getLineColor().toInt());
line.setGeodesic(true);
line.setId(id);
line.setTitle(name);
line.setWidth(flot.getLineWidth());
line.getOutlinePaint().setStrokeWidth(flot.getLineWidth());
line.setSubDescription(description);
line.setSnippet(symbolCode);
line.setVisible(true);
@@ -205,12 +205,12 @@ else if (!mCurrentCenter.equals(map.getMapCenter()))
}
line.setPoints(geoPoints);
if (info.getLineColor() != null)
line.setStrokeColor(info.getLineColor().toInt());
line.getOutlinePaint().setColor(info.getLineColor().toInt());
if (info.getFillColor() != null)
line.setFillColor(info.getFillColor().toInt());
line.getFillPaint().setColor(info.getFillColor().toInt());
line.setId(id);
line.setTitle(name);
line.setStrokeWidth(flot.getLineWidth());
line.getOutlinePaint().setStrokeWidth(flot.getLineWidth());
line.setSubDescription(description);
line.setSnippet(symbolCode);
line.setVisible(true);
@@ -225,9 +225,9 @@ else if (!mCurrentCenter.equals(map.getMapCenter()))
geoPoints.add(new GeoPoint(p.getY(), p.getX()));
}
line.setPoints(geoPoints);
line.setWidth(flot.getLineWidth());
line.getOutlinePaint().setStrokeWidth(flot.getLineWidth());
if (info.getLineColor() != null)
line.setColor(info.getLineColor().toInt());
line.getOutlinePaint().setColor(info.getLineColor().toInt());
line.setGeodesic(true);
line.setVisible(true);
lastOverlay.getItems().add(line);
@@ -59,12 +59,16 @@
private final PointAccepter mPointAccepter;
private boolean mGeodesic = false;

/**
* @since 6.1.0
*/
private final boolean mClosed;

/**
* Dedicated to `Path`
*/
public LinearRing(final Path pPath) {
mPath = pPath;
mPointAccepter = new PathBuilder(pPath);
this(pPath, true);
}

/**
@@ -74,6 +78,16 @@ public LinearRing(final Path pPath) {
public LinearRing(final LineBuilder pLineBuilder) {
mPath = null;
mPointAccepter = pLineBuilder;
mClosed = false;
}

/**
* @since 6.1.0
*/
public LinearRing(final Path pPath, final boolean pClosed) {
mPath = pPath;
mPointAccepter = new PathBuilder(pPath);
mClosed = pClosed;
}

void clearPath() {
@@ -194,9 +208,11 @@ PointL buildPathPortion(final Projection pProjection,
getBestOffset(pProjection, offset);
}
mSegmentClipper.init();
clipAndStore(pProjection, offset, true, pStorePoints, mSegmentClipper);
clipAndStore(pProjection, offset, mClosed, pStorePoints, mSegmentClipper);
mSegmentClipper.end();
mPath.close();
if (mClosed) {
mPath.close();
}
return offset;
}

0 comments on commit fadcd07

Please sign in to comment.
You can’t perform that action at this time.