diff --git a/src/main/java/com/google/maps/StaticMapsRequest.java b/src/main/java/com/google/maps/StaticMapsRequest.java index 327a84780..88698f64e 100644 --- a/src/main/java/com/google/maps/StaticMapsRequest.java +++ b/src/main/java/com/google/maps/StaticMapsRequest.java @@ -443,7 +443,7 @@ public StaticMapsRequest path(Path path) { * @return Returns this {@code StaticMapsRequest} for call chaining. */ public StaticMapsRequest path(EncodedPolyline path) { - return paramAddToList("path", "enc:" + path.getEncodedPath()); + return paramAddToList("path", path.getEncodedPath()); } /** diff --git a/src/main/java/com/google/maps/model/EncodedPolyline.java b/src/main/java/com/google/maps/model/EncodedPolyline.java index 07f75ddeb..995b9d34c 100644 --- a/src/main/java/com/google/maps/model/EncodedPolyline.java +++ b/src/main/java/com/google/maps/model/EncodedPolyline.java @@ -16,49 +16,116 @@ package com.google.maps.model; import com.google.maps.internal.PolylineEncoding; +import com.google.maps.internal.StringJoin; + import java.io.Serializable; +import java.util.ArrayList; import java.util.List; /** * Encoded Polylines are used by the API to represent paths. * - *

See + *

+ * See * Encoded Polyline Algorithm for more detail on the protocol. */ public class EncodedPolyline implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; + + private int weight; + private String color; + private String fillcolor; + private boolean geodesic; + private final String points; + + public EncodedPolyline() { + this.points = null; + } + + /** + * @param encodedPoints A string representation of a path, encoded with the + * Polyline Algorithm. + */ + public EncodedPolyline(String encodedPoints) { + this.points = encodedPoints; + } + + /** @param points A path as a collection of {@code LatLng} points. */ + public EncodedPolyline(List points) { + this.points = PolylineEncoding.encode(points); + } + + public String getEncodedPath() { + return toUrlValue(); + } + + public List decodePath() { + return PolylineEncoding.decode(points); + } + + // Use the encoded point representation; decoding to get an alternate + // representation for + // individual points would be expensive. + @Override + public String toString() { + return String.format("[EncodedPolyline: %s]", points); + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public String getFillcolor() { + return fillcolor; + } + + public void setFillcolor(String fillcolor) { + this.fillcolor = fillcolor; + } + + public boolean isGeodesic() { + return geodesic; + } + + public void setGeodesic(boolean geodesic) { + this.geodesic = geodesic; + } - private final String points; + public String toUrlValue() { + List urlParts = new ArrayList<>(); - public EncodedPolyline() { - this.points = null; - } + if (weight > 0) { + urlParts.add("weight:" + weight); + } - /** - * @param encodedPoints A string representation of a path, encoded with the Polyline Algorithm. - */ - public EncodedPolyline(String encodedPoints) { - this.points = encodedPoints; - } + if (color != null) { + urlParts.add("color:" + color); + } - /** @param points A path as a collection of {@code LatLng} points. */ - public EncodedPolyline(List points) { - this.points = PolylineEncoding.encode(points); - } + if (fillcolor != null) { + urlParts.add("fillcolor:" + fillcolor); + } - public String getEncodedPath() { - return points; - } + if (geodesic) { + urlParts.add("geodesic:" + geodesic); + } - public List decodePath() { - return PolylineEncoding.decode(points); - } + urlParts.add("enc:" + points); - // Use the encoded point representation; decoding to get an alternate representation for - // individual points would be expensive. - @Override - public String toString() { - return String.format("[EncodedPolyline: %s]", points); - } + return StringJoin.join('|', urlParts.toArray(new String[urlParts.size()])); + } }