use of com.google.android.libraries.maps.model.PolylineOptions in project android-maps-utils by googlemaps.
the class PolySimplifyDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
GoogleMap map = getMap();
// Original line
List<LatLng> line = PolyUtil.decode(LINE);
map.addPolyline(new PolylineOptions().addAll(line).color(Color.BLACK));
if (!isRestore) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
}
List<LatLng> simplifiedLine;
/*
* Simplified lines - increasing the tolerance will result in fewer points in the simplified
* line
*/
// meters
double tolerance = 5;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.RED - ALPHA_ADJUSTMENT));
// meters
tolerance = 20;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.GREEN - ALPHA_ADJUSTMENT));
// meters
tolerance = 50;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.MAGENTA - ALPHA_ADJUSTMENT));
// meters
tolerance = 500;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.YELLOW - ALPHA_ADJUSTMENT));
// meters
tolerance = 1000;
simplifiedLine = PolyUtil.simplify(line, tolerance);
map.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.BLUE - ALPHA_ADJUSTMENT));
// Triangle polygon - the polygon should be closed
ArrayList<LatLng> triangle = new ArrayList<>();
// Should match last point
triangle.add(new LatLng(28.06025, -82.41030));
triangle.add(new LatLng(28.06129, -82.40945));
triangle.add(new LatLng(28.06206, -82.40917));
triangle.add(new LatLng(28.06125, -82.40850));
triangle.add(new LatLng(28.06035, -82.40834));
triangle.add(new LatLng(28.06038, -82.40924));
// Should match first point
triangle.add(new LatLng(28.06025, -82.41030));
map.addPolygon(new PolygonOptions().addAll(triangle).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified triangle polygon
// meters
tolerance = 88;
List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
map.addPolygon(new PolygonOptions().addAll(simplifiedTriangle).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
// Oval polygon - the polygon should be closed
List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
map.addPolygon(new PolygonOptions().addAll(oval).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
// Simplified oval polygon
// meters
tolerance = 10;
List simplifiedOval = PolyUtil.simplify(oval, tolerance);
map.addPolygon(new PolygonOptions().addAll(simplifiedOval).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
}
Aggregations