Skip to content

Commit 165cc86

Browse files
jonatas.silvestriniJonSilvestrini
authored andcommitted
COF #10682 - Color, weight and other attributes working with Encoded Polyline
1 parent 5c9135a commit 165cc86

File tree

2 files changed

+96
-29
lines changed

2 files changed

+96
-29
lines changed

src/main/java/com/google/maps/StaticMapsRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public StaticMapsRequest path(Path path) {
443443
* @return Returns this {@code StaticMapsRequest} for call chaining.
444444
*/
445445
public StaticMapsRequest path(EncodedPolyline path) {
446-
return paramAddToList("path", "enc:" + path.getEncodedPath());
446+
return paramAddToList("path", path.getEncodedPath());
447447
}
448448

449449
/**

src/main/java/com/google/maps/model/EncodedPolyline.java

Lines changed: 95 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,116 @@
1616
package com.google.maps.model;
1717

1818
import com.google.maps.internal.PolylineEncoding;
19+
import com.google.maps.internal.StringJoin;
20+
1921
import java.io.Serializable;
22+
import java.util.ArrayList;
2023
import java.util.List;
2124

2225
/**
2326
* Encoded Polylines are used by the API to represent paths.
2427
*
25-
* <p>See <a href="https://developers.google.com/maps/documentation/utilities/polylinealgorithm">
28+
* <p>
29+
* See <a href=
30+
* "https://developers.google.com/maps/documentation/utilities/polylinealgorithm">
2631
* Encoded Polyline Algorithm</a> for more detail on the protocol.
2732
*/
2833
public class EncodedPolyline implements Serializable {
2934

30-
private static final long serialVersionUID = 1L;
35+
private static final long serialVersionUID = 1L;
36+
37+
private int weight;
38+
private String color;
39+
private String fillcolor;
40+
private boolean geodesic;
41+
private final String points;
42+
43+
public EncodedPolyline() {
44+
this.points = null;
45+
}
46+
47+
/**
48+
* @param encodedPoints A string representation of a path, encoded with the
49+
* Polyline Algorithm.
50+
*/
51+
public EncodedPolyline(String encodedPoints) {
52+
this.points = encodedPoints;
53+
}
54+
55+
/** @param points A path as a collection of {@code LatLng} points. */
56+
public EncodedPolyline(List<LatLng> points) {
57+
this.points = PolylineEncoding.encode(points);
58+
}
59+
60+
public String getEncodedPath() {
61+
return toUrlValue();
62+
}
63+
64+
public List<LatLng> decodePath() {
65+
return PolylineEncoding.decode(points);
66+
}
67+
68+
// Use the encoded point representation; decoding to get an alternate
69+
// representation for
70+
// individual points would be expensive.
71+
@Override
72+
public String toString() {
73+
return String.format("[EncodedPolyline: %s]", points);
74+
}
75+
76+
public int getWeight() {
77+
return weight;
78+
}
79+
80+
public void setWeight(int weight) {
81+
this.weight = weight;
82+
}
83+
84+
public String getColor() {
85+
return color;
86+
}
87+
88+
public void setColor(String color) {
89+
this.color = color;
90+
}
91+
92+
public String getFillcolor() {
93+
return fillcolor;
94+
}
95+
96+
public void setFillcolor(String fillcolor) {
97+
this.fillcolor = fillcolor;
98+
}
99+
100+
public boolean isGeodesic() {
101+
return geodesic;
102+
}
103+
104+
public void setGeodesic(boolean geodesic) {
105+
this.geodesic = geodesic;
106+
}
31107

32-
private final String points;
108+
public String toUrlValue() {
109+
List<String> urlParts = new ArrayList<>();
33110

34-
public EncodedPolyline() {
35-
this.points = null;
36-
}
111+
if (weight > 0) {
112+
urlParts.add("weight:" + weight);
113+
}
37114

38-
/**
39-
* @param encodedPoints A string representation of a path, encoded with the Polyline Algorithm.
40-
*/
41-
public EncodedPolyline(String encodedPoints) {
42-
this.points = encodedPoints;
43-
}
115+
if (color != null) {
116+
urlParts.add("color:" + color);
117+
}
44118

45-
/** @param points A path as a collection of {@code LatLng} points. */
46-
public EncodedPolyline(List<LatLng> points) {
47-
this.points = PolylineEncoding.encode(points);
48-
}
119+
if (fillcolor != null) {
120+
urlParts.add("fillcolor:" + fillcolor);
121+
}
49122

50-
public String getEncodedPath() {
51-
return points;
52-
}
123+
if (geodesic) {
124+
urlParts.add("geodesic:" + geodesic);
125+
}
53126

54-
public List<LatLng> decodePath() {
55-
return PolylineEncoding.decode(points);
56-
}
127+
urlParts.add("enc:" + points);
57128

58-
// Use the encoded point representation; decoding to get an alternate representation for
59-
// individual points would be expensive.
60-
@Override
61-
public String toString() {
62-
return String.format("[EncodedPolyline: %s]", points);
63-
}
129+
return StringJoin.join('|', urlParts.toArray(new String[urlParts.size()]));
130+
}
64131
}

0 commit comments

Comments
 (0)