Java Code Examples for com.google.android.gms.maps.model.PolylineOptions#width()

The following examples show how to use com.google.android.gms.maps.model.PolylineOptions#width() . 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: GglMapAiPoint2PointManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void drawPointLine(LatLng latLngDevice) {
    if (this.pointMarker != null) {
        LatLng latLng = this.pointMarker.getPosition();
        this.latLngs.clear();
        this.latLngs.add(latLng);
        this.latLngs.add(latLngDevice);
        if (this.polyline == null) {
            PolylineOptions polylineOptions = new PolylineOptions();
            polylineOptions.addAll(this.latLngs);
            polylineOptions.color(this.context.getResources().getColor(R.color.x8_drone_inface_line)).zIndex(50.0f);
            polylineOptions.width(4.0f);
            if (this.polyline != null) {
                this.polyline.remove();
            }
            this.polyline = this.googleMap.addPolyline(polylineOptions);
            this.polyline.setPattern(PATTERN_DASHED);
        }
        this.polyline.setPoints(this.latLngs);
    }
}
 
Example 2
Source File: DistanceAction.java    From Companion-For-PUBG-Android with MIT License 6 votes vote down vote up
/**
 * If an origin and destination exist this will draw a line between them and
 * render the time it takes to reach the {@link DistanceAction#destination}
 */
private void addPolyline() {
    if (this.origin == null || this.destination == null) {
        return;
    }
    releasePolyline();
    this.destination.marker.setTitle(getTitleForDistance(getDistance()));
    this.destination.marker.setSnippet(this.snippet);
    this.destination.marker.showInfoWindow();
    final PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.add(this.origin.latLng);
    polylineOptions.add(this.destination.latLng);
    polylineOptions.width(5);
    polylineOptions.color(this.colorAccent);
    polylineOptions.zIndex(1000);
    this.polyline = this.mapController.addPolyline(polylineOptions);
}
 
Example 3
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Add a list of Polylines to the map
 *
 * @param map       google map
 * @param polylines multi polyline options
 * @return multi polyline
 */
public static MultiPolyline addPolylinesToMap(GoogleMap map,
                                              MultiPolylineOptions polylines) {
    MultiPolyline multiPolyline = new MultiPolyline();
    for (PolylineOptions polylineOption : polylines.getPolylineOptions()) {
        if (polylines.getOptions() != null) {
            polylineOption.color(polylines.getOptions().getColor());
            polylineOption.geodesic(polylines.getOptions().isGeodesic());
            polylineOption.visible(polylines.getOptions().isVisible());
            polylineOption.zIndex(polylines.getOptions().getZIndex());
            polylineOption.width(polylines.getOptions().getWidth());
        }
        Polyline polyline = addPolylineToMap(map, polylineOption);
        multiPolyline.add(polyline);
    }
    return multiPolyline;
}
 
Example 4
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Add a Polyline to the map as markers
 *
 * @param map                   google map
 * @param polylineOptions       polyline options
 * @param polylineMarkerOptions polyline marker options
 * @param globalPolylineOptions global polyline options
 * @return polyline markers
 */
public PolylineMarkers addPolylineToMapAsMarkers(GoogleMap map,
                                                 PolylineOptions polylineOptions,
                                                 MarkerOptions polylineMarkerOptions,
                                                 PolylineOptions globalPolylineOptions) {

    PolylineMarkers polylineMarkers = new PolylineMarkers(this);

    if (globalPolylineOptions != null) {
        polylineOptions.color(globalPolylineOptions.getColor());
        polylineOptions.geodesic(globalPolylineOptions.isGeodesic());
        polylineOptions.visible(globalPolylineOptions.isVisible());
        polylineOptions.zIndex(globalPolylineOptions.getZIndex());
        polylineOptions.width(globalPolylineOptions.getWidth());
    }

    Polyline polyline = addPolylineToMap(map, polylineOptions);
    polylineMarkers.setPolyline(polyline);

    List<Marker> markers = addPointsToMapAsMarkers(map,
            polylineOptions.getPoints(), polylineMarkerOptions, false);
    polylineMarkers.setMarkers(markers);

    return polylineMarkers;
}
 
Example 5
Source File: DriverMapActivity.java    From UberClone with MIT License 6 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex) {
    if(polylines.size()>0) {
        for (Polyline poly : polylines) {
            poly.remove();
        }
    }

    polylines = new ArrayList<>();
    //add route(s) to the map.
    for (int i = 0; i <route.size(); i++) {

        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(getResources().getColor(COLORS[colorIndex]));
        polyOptions.width(10 + i * 3);
        polyOptions.addAll(route.get(i).getPoints());
        Polyline polyline = mMap.addPolyline(polyOptions);
        polylines.add(polyline);

        Toast.makeText(getApplicationContext(),"Route "+ (i+1) +": distance - "+ route.get(i).getDistanceValue()+": duration - "+ route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show();
    }

}
 
Example 6
Source File: NearbyLocationActivity.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> route, int j) {
    if (polylines.size() > 0) {
        for (Polyline poly : polylines) {
            poly.remove();
        }
    }

    polylines = new ArrayList<>();
    //add route(s) to the map.
    for (int i = 0; i < route.size(); i++) {

        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(getResources().getColor(COLORS[colorIndex]));
        polyOptions.width(10 + i * 3);
        polyOptions.addAll(route.get(i).getPoints());
        Polyline polyline = mMap.addPolyline(polyOptions);
        polylines.add(polyline);
    }
}
 
Example 7
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 6 votes vote down vote up
private Polyline drawPath(List<LatLong> latLongs, int color, float zIndex, Polyline polyline) {
    if (googleMap != null && latLongs != null && !latLongs.isEmpty()) {
        PolylineOptions polyLineOptions = new PolylineOptions();
        polyLineOptions.width(getResources().getDimension(R.dimen._2dp));
        polyLineOptions.color(color);
        polyLineOptions.zIndex(zIndex);

        for (LatLong latLong : latLongs) {
            polyLineOptions.add(new LatLng(latLong.latitude(), latLong.longitude()));
        }

        if (polyline != null) polyline.remove();
        return googleMap.addPolyline(polyLineOptions);
    }

    return null;
}
 
Example 8
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void drawPointLine(LatLng latLngDevice) {
    if (this.gglMapLocationManager != null && this.gglMapLocationManager.getDevLocation() != null) {
        Polyline polyline;
        if (this.polylineList != null) {
            for (Polyline polyline2 : this.polylineList) {
                polyline2.remove();
            }
            this.polylineList.clear();
        }
        for (int i = 0; i < this.mMarkerList.size(); i++) {
            PolylineOptions polylineOptions = new PolylineOptions();
            if (i == 0) {
                polylineOptions.add(latLngDevice);
                polylineOptions.add(((Marker) this.mMarkerList.get(i)).getPosition());
            } else {
                polylineOptions.add(((Marker) this.mMarkerList.get(i - 1)).getPosition());
                polylineOptions.add(((Marker) this.mMarkerList.get(i)).getPosition());
            }
            polylineOptions.color(this.context.getResources().getColor(this.lineDefaultColor)).zIndex(3.0f);
            polylineOptions.width(4.0f);
            polyline2 = this.googleMap.addPolyline(polylineOptions);
            polyline2.setPattern(PATTERN_DASHED);
            try {
                this.polylineList.add(polyline2);
            } catch (Exception e) {
            }
        }
    }
}
 
Example 9
Source File: KmlStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new PolylineOption from given properties of an existing PolylineOption
 *
 * @param originalPolylineOption An existing PolylineOption instance
 * @return A new PolylineOption
 */
private static PolylineOptions createPolylineOptions(PolylineOptions originalPolylineOption) {
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.color(originalPolylineOption.getColor());
    polylineOptions.width(originalPolylineOption.getWidth());
    polylineOptions.clickable(originalPolylineOption.isClickable());
    return polylineOptions;
}
 
Example 10
Source File: GeoJsonLineStringStyle.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a new PolylineOptions object containing styles for the GeoJsonLineString
 *
 * @return new PolylineOptions object
 */
public PolylineOptions toPolylineOptions() {
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.color(mPolylineOptions.getColor());
    polylineOptions.clickable(mPolylineOptions.isClickable());
    polylineOptions.geodesic(mPolylineOptions.isGeodesic());
    polylineOptions.visible(mPolylineOptions.isVisible());
    polylineOptions.width(mPolylineOptions.getWidth());
    polylineOptions.zIndex(mPolylineOptions.getZIndex());
    polylineOptions.pattern(getPattern());
    return polylineOptions;
}
 
Example 11
Source File: Renderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the inline linestring style by copying over the styles that have been set
 *
 * @param polylineOptions polygon options object to add inline styles to
 * @param inlineStyle     inline styles to apply
 */
private void setInlineLineStringStyle(PolylineOptions polylineOptions, KmlStyle inlineStyle) {
    PolylineOptions inlinePolylineOptions = inlineStyle.getPolylineOptions();
    if (inlineStyle.isStyleSet("outlineColor")) {
        polylineOptions.color(inlinePolylineOptions.getColor());
    }
    if (inlineStyle.isStyleSet("width")) {
        polylineOptions.width(inlinePolylineOptions.getWidth());
    }
    if (inlineStyle.isLineRandomColorMode()) {
        polylineOptions.color(KmlStyle.computeRandomColor(inlinePolylineOptions.getColor()));
    }
}
 
Example 12
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private void drawSegmentPathUser(LatLng latLng) {
    PolylineOptions polyLineOptions = new PolylineOptions();
    polyLineOptions.width(getResources().getDimension(R.dimen._2dp));
    polyLineOptions.color(ContextCompat.getColor(getContext(), R.color.blue));
    polyLineOptions.zIndex(2f);

    if (polylineUserLastPath != null) {
        for (LatLng latLngOld : polylineUserLastPath.getPoints())
            polyLineOptions.add(latLngOld);
    }

    polyLineOptions.add(latLng);
    polylineUserLastPath = removePath(polylineUserLastPath);
    polylineUserLastPath = googleMap.addPolyline(polyLineOptions);
}
 
Example 13
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public Polyline getPolyline(int index, Polyline pl, int color) {
    PolylineOptions polylineOptions = new PolylineOptions();
    polylineOptions.addAll(pl.getPoints());
    polylineOptions.color(this.context.getResources().getColor(color)).zIndex(3.0f);
    polylineOptions.width(4.0f);
    Polyline line = this.googleMap.addPolyline(polylineOptions);
    line.setPattern(PATTERN_DASHED);
    return line;
}
 
Example 14
Source File: HistorySingleActivity.java    From UberClone with MIT License 4 votes vote down vote up
@Override
public void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex) {

    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    builder.include(pickupLatLng);
    builder.include(destinationLatLng);
    LatLngBounds bounds = builder.build();

    int width = getResources().getDisplayMetrics().widthPixels;
    int padding = (int) (width*0.2);

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);

    mMap.animateCamera(cameraUpdate);

    mMap.addMarker(new MarkerOptions().position(pickupLatLng).title("pickup location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup)));
    mMap.addMarker(new MarkerOptions().position(destinationLatLng).title("destination"));

    if(polylines.size()>0) {
        for (Polyline poly : polylines) {
            poly.remove();
        }
    }

    polylines = new ArrayList<>();
    //add route(s) to the map.
    for (int i = 0; i <route.size(); i++) {

        //In case of more than 5 alternative routes
        int colorIndex = i % COLORS.length;

        PolylineOptions polyOptions = new PolylineOptions();
        polyOptions.color(getResources().getColor(COLORS[colorIndex]));
        polyOptions.width(10 + i * 3);
        polyOptions.addAll(route.get(i).getPoints());
        Polyline polyline = mMap.addPolyline(polyOptions);
        polylines.add(polyline);

        Toast.makeText(getApplicationContext(),"Route "+ (i+1) +": distance - "+ route.get(i).getDistanceValue()+": duration - "+ route.get(i).getDurationValue(),Toast.LENGTH_SHORT).show();
    }

}
 
Example 15
Source File: MainActivity.java    From android-app with GNU General Public License v2.0 4 votes vote down vote up
protected void drawItineraryPolyline(Itinerary itinerary) {
    List<Spot> spots = itinerary.getSpots();
    if (spots != null && !spots.isEmpty()) {

        List<Spot> spotsGoing = new ArrayList<Spot>();
        List<Spot> spotsReturning = new ArrayList<Spot>();
        PolylineOptions line = new PolylineOptions();
        PolylineOptions lineReturning = new PolylineOptions();
        for(int i=0; i<spots.size(); i++) {
            Spot spot = spots.get(i);
            if(spot.getReturning().equalsIgnoreCase("true")){
                spotsReturning.add(spot);
                lineReturning.add(new LatLng(spot.getLatitude(),spot.getLongitude()));
            }
            else{
                spotsGoing.add(spot);
                line.add(new LatLng(spot.getLatitude(),spot.getLongitude()));
            }
        }

        Random rnd = new Random();
        float[] hsv = new float[3];
        map.setInfoWindowAdapter(new BusInfoWindowAdapter(this));
        MapMarker marker = new MapMarker(map);

        int r = rnd.nextInt(256); int g = rnd.nextInt(256); int b = rnd.nextInt(256);
        int color = Color.argb(255, r, g, b);
        lineReturning.color(color);
        lineReturning.width(6);
        lineReturning.geodesic(true);
        map.addPolyline(lineReturning);

        if(!spotsReturning.isEmpty()){
            Color.RGBToHSV(r, g, b, hsv);
            marker.addMarkers(spotsReturning.get(0), hsv[0], itinerary);
            marker.addMarkers(spotsReturning.get(spotsReturning.size() - 1), hsv[0], itinerary);
        }

        r *= 0.75; g *= 0.75; b *= 0.75;
        color = Color.argb(255, r, g, b);
        line.color(color);
        line.width(6);
        line.geodesic(true);
        map.addPolyline(line);

        Color.RGBToHSV(r, g, b, hsv);
        marker.addMarkers(spotsGoing.get(0), hsv[0], itinerary);
        marker.addMarkers(spotsGoing.get(spotsGoing.size() - 1), hsv[0], itinerary);
    }
}
 
Example 16
Source File: NiboOriginDestinationPickerFragment.java    From Nibo with MIT License 4 votes vote down vote up
private void drawPolyline(final List<Route> routes) {

        ArrayList<LatLng> points = null;
        PolylineOptions lineOptions = new PolylineOptions();

        mCoordinatorlayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                mOriginEditText.clearFocus();
                mDestinationEditText.clearFocus();
                mCoordinatorlayout.requestLayout();
            }
        }, 1000);

        for (int i = 0; i < routes.size(); i++) {
            this.mListLatLng.addAll(routes.get(i).points);
        }

        lineOptions.width(10);
        if (mPrimaryPolyLineColor == 0) {
            lineOptions.color(Color.BLACK);
        } else {
            lineOptions.color(ContextCompat.getColor(getContext(), mPrimaryPolyLineColor));
        }
        lineOptions.startCap(new SquareCap());
        lineOptions.endCap(new SquareCap());
        lineOptions.jointType(ROUND);
        mPrimaryPolyLine = mMap.addPolyline(lineOptions);

        PolylineOptions greyOptions = new PolylineOptions();
        greyOptions.width(10);
        if (mSecondaryPolyLineColor == 0) {
            greyOptions.color(Color.GRAY);
        } else {
            lineOptions.color(ContextCompat.getColor(getContext(), mSecondaryPolyLineColor));
        }
        greyOptions.startCap(new SquareCap());
        greyOptions.endCap(new SquareCap());
        greyOptions.jointType(ROUND);
        mSecondaryPolyLine = mMap.addPolyline(greyOptions);

        animatePolyLine();
    }
 
Example 17
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 3 votes vote down vote up
/**
 * Set the polyline options
 *
 * @param style           shape style
 * @param polylineOptions polyline options
 * @param visible         visible flag
 */
private void setPolylineOptions(ObservationShapeStyle style, PolylineOptions polylineOptions, boolean visible) {
    polylineOptions.width(style.getStrokeWidth());
    polylineOptions.color(style.getStrokeColor());
    polylineOptions.visible(visible);
    polylineOptions.geodesic(MapShapeObservation.GEODESIC);
}
 
Example 18
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Set the style into the polyline options
 *
 * @param polylineOptions polyline options
 * @param style           style row
 * @param density         display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polyline options
 */
public static boolean setStyle(PolylineOptions polylineOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polylineOptions.color(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polylineOptions.width((float) width * density);

    }

    return style != null;
}