Search in sources :

Example 1 with Gap

use of com.google.android.libraries.maps.model.Gap in project android-samples by googlemaps.

the class PolylineDemoActivity method onMapReady.

@Override
public void onMapReady(GoogleMap map) {
    // For accessibility mode. Ideally this string would be localised.
    map.setContentDescription("Google Map with polylines.");
    // Non-loop polyline that goes past Australian cities. Added before sydneyPolyline and would
    // normally be underneath, but increase Z-Index so that this line is on top.
    australiaPolyline = map.addPolyline(new PolylineOptions().add(PERTH, ADELAIDE, SYDNEY, MELBOURNE).pattern(Arrays.asList(new Dot(), new Gap(20.0f))).color(Color.MAGENTA).zIndex(1));
    // Geodesic polyline that goes around the world.
    worldPolyline = map.addPolyline(new PolylineOptions().add(LONDON, AUCKLAND, LOS_ANGELES, NEW_YORK, LONDON).width(5).color(Color.BLUE).geodesic(true).clickable(true));
    // Loop polyline centered at Sydney.
    int radius = 4;
    sydneyPolyline = map.addPolyline(new PolylineOptions().add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)).add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude - radius)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude - radius)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude + radius)).add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)).pattern(Arrays.asList(new Dash(45.0f), new Gap(10.0f))).color(Color.RED).width(5).clickable(true));
    // Create Melbourne polyline to show layering of polylines with same Z-Index. This is added
    // second so it will be layered on top of the Sydney polyline (both have Z-Index == 0).
    melbournePolyline = map.addPolyline(new PolylineOptions().add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)).add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude - radius)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude - radius)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude + radius)).add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)).color(Color.GREEN).width(5).clickable(true));
    map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY));
    selectedPolyline = australiaPolyline;
    polylineRadio.check(R.id.polyline_radio_australia);
    pager.addOnPageChangeListener(this);
    polylineRadio.setOnCheckedChangeListener(this);
    map.setOnPolylineClickListener(this);
}
Also used : Dash(com.google.android.libraries.maps.model.Dash) Gap(com.google.android.libraries.maps.model.Gap) Dot(com.google.android.libraries.maps.model.Dot) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Example 2 with Gap

use of com.google.android.libraries.maps.model.Gap in project android-samples by googlemaps.

the class PolylinePatternControlFragment method toString.

private static String toString(List<PatternItem> pattern) {
    if (pattern == null) {
        return "<SOLID>";
    }
    StringBuilder sb = new StringBuilder("");
    for (PatternItem item : pattern) {
        if (item instanceof Dot) {
            sb.append("DOT");
        } else if (item instanceof Dash) {
            sb.append(String.format("%.1fpx-DASH", ((Dash) item).length));
        } else if (item instanceof Gap) {
            sb.append(String.format("%.1fpx-GAP", ((Gap) item).length));
        }
        sb.append(" ");
    }
    sb.append("<repeat>");
    return sb.toString();
}
Also used : Dash(com.google.android.libraries.maps.model.Dash) PatternItem(com.google.android.libraries.maps.model.PatternItem) Gap(com.google.android.libraries.maps.model.Gap) Dot(com.google.android.libraries.maps.model.Dot)

Example 3 with Gap

use of com.google.android.libraries.maps.model.Gap in project android-samples by googlemaps.

the class PolylinePatternControlFragment method onClick.

@Override
public void onClick(View view) {
    if (polyline == null) {
        return;
    }
    int id = view.getId();
    List<PatternItem> pattern;
    if (id == R.id.patternSolidBtn) {
        pattern = null;
    } else if (id == R.id.patternDottedBtn) {
        pattern = Arrays.asList(new Dot(), new Gap(RANDOM.nextFloat() * MAX_GAP_LENGTH));
    } else if (id == R.id.patternDashedBtn) {
        pattern = Arrays.asList(new Dash(RANDOM.nextFloat() * MAX_DASH_LENGTH), new Gap(RANDOM.nextFloat() * MAX_GAP_LENGTH));
    } else if (id == R.id.patternMixedBtn) {
        int size = 2 * (1 + RANDOM.nextInt(MAX_PATTERN_SIZE / 2));
        pattern = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            if ((i % 2) == 0) {
                pattern.add(RANDOM.nextBoolean() ? new Dot() : new Dash(RANDOM.nextFloat() * MAX_DASH_LENGTH));
            } else {
                pattern.add(new Gap(RANDOM.nextFloat() * MAX_GAP_LENGTH));
            }
        }
    } else {
        throw new IllegalStateException("Unknown button");
    }
    polyline.setPattern(pattern);
    patternTextView.setText(toString(pattern));
}
Also used : Dash(com.google.android.libraries.maps.model.Dash) PatternItem(com.google.android.libraries.maps.model.PatternItem) Gap(com.google.android.libraries.maps.model.Gap) Dot(com.google.android.libraries.maps.model.Dot) ArrayList(java.util.ArrayList)

Aggregations

Dash (com.google.android.libraries.maps.model.Dash)3 Dot (com.google.android.libraries.maps.model.Dot)3 Gap (com.google.android.libraries.maps.model.Gap)3 PatternItem (com.google.android.libraries.maps.model.PatternItem)2 LatLng (com.google.android.libraries.maps.model.LatLng)1 PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)1 ArrayList (java.util.ArrayList)1