Skip to content

Commit

Permalink
COF #10682 - Color, weight and other attributes working with Encoded …
Browse files Browse the repository at this point in the history
…Polyline
  • Loading branch information
jonatas.silvestrini authored and JonSilvestrini committed Mar 27, 2020
1 parent 5c9135a commit 165cc86
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/google/maps/StaticMapsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
123 changes: 95 additions & 28 deletions src/main/java/com/google/maps/model/EncodedPolyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>See <a href="https://developers.google.com/maps/documentation/utilities/polylinealgorithm">
* <p>
* See <a href=
* "https://developers.google.com/maps/documentation/utilities/polylinealgorithm">
* Encoded Polyline Algorithm</a> 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<LatLng> points) {
this.points = PolylineEncoding.encode(points);
}

public String getEncodedPath() {
return toUrlValue();
}

public List<LatLng> 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<String> 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<LatLng> 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<LatLng> 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()]));
}
}

0 comments on commit 165cc86

Please sign in to comment.