Skip to content

Commit

Permalink
feat: COF #10682 - Color, weight and other attributes working with En…
Browse files Browse the repository at this point in the history
…coded Polyline (#668)
  • Loading branch information
jonatas.silvestrini committed Mar 27, 2020
1 parent 5c9135a commit 8fa2014
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 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
49 changes: 48 additions & 1 deletion src/main/java/com/google/maps/model/EncodedPolyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
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;

/**
Expand All @@ -29,6 +32,10 @@ public class EncodedPolyline implements Serializable {

private static final long serialVersionUID = 1L;

private int weight;
private String color;
private String fillcolor;
private boolean geodesic;
private final String points;

public EncodedPolyline() {
Expand All @@ -48,7 +55,7 @@ public EncodedPolyline(List<LatLng> points) {
}

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

public List<LatLng> decodePath() {
Expand All @@ -61,4 +68,44 @@ public List<LatLng> decodePath() {
public String toString() {
return String.format("[EncodedPolyline: %s]", points);
}

public void weight(int weight) {
this.weight = weight;
}

public void setColor(String color) {
this.color = color;
}

public void fillcolor(String fillcolor) {
this.fillcolor = fillcolor;
}

public void geodesic(boolean geodesic) {
this.geodesic = geodesic;
}

public String toUrlValue() {
List<String> urlParts = new ArrayList<>();

if (weight > 0) {
urlParts.add("weight:" + weight);
}

if (color != null) {
urlParts.add("color:" + color);
}

if (fillcolor != null) {
urlParts.add("fillcolor:" + fillcolor);
}

if (geodesic) {
urlParts.add("geodesic:" + geodesic);
}

urlParts.add("enc:" + points);

return StringJoin.join('|', urlParts.toArray(new String[urlParts.size()]));
}
}

0 comments on commit 8fa2014

Please sign in to comment.