Search in sources :

Example 6 with PolylineOptions

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));
}
Also used : GoogleMap(com.google.android.libraries.maps.GoogleMap) PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Aggregations

PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)6 LatLng (com.google.android.libraries.maps.model.LatLng)5 PolygonOptions (com.google.android.libraries.maps.model.PolygonOptions)3 MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)2 JSArray (com.getcapacitor.JSArray)1 PluginMethod (com.getcapacitor.PluginMethod)1 GoogleMap (com.google.android.libraries.maps.GoogleMap)1 CircleOptions (com.google.android.libraries.maps.model.CircleOptions)1 Dash (com.google.android.libraries.maps.model.Dash)1 Dot (com.google.android.libraries.maps.model.Dot)1 Gap (com.google.android.libraries.maps.model.Gap)1 GroundOverlayOptions (com.google.android.libraries.maps.model.GroundOverlayOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1