Skip to content

Commit 8fa2014

Browse files
author
jonatas.silvestrini
committed
feat: COF #10682 - Color, weight and other attributes working with Encoded Polyline (#668)
1 parent 5c9135a commit 8fa2014

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
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: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
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
/**
@@ -29,6 +32,10 @@ public class EncodedPolyline implements Serializable {
2932

3033
private static final long serialVersionUID = 1L;
3134

35+
private int weight;
36+
private String color;
37+
private String fillcolor;
38+
private boolean geodesic;
3239
private final String points;
3340

3441
public EncodedPolyline() {
@@ -48,7 +55,7 @@ public EncodedPolyline(List<LatLng> points) {
4855
}
4956

5057
public String getEncodedPath() {
51-
return points;
58+
return toUrlValue();
5259
}
5360

5461
public List<LatLng> decodePath() {
@@ -61,4 +68,44 @@ public List<LatLng> decodePath() {
6168
public String toString() {
6269
return String.format("[EncodedPolyline: %s]", points);
6370
}
71+
72+
public void weight(int weight) {
73+
this.weight = weight;
74+
}
75+
76+
public void setColor(String color) {
77+
this.color = color;
78+
}
79+
80+
public void fillcolor(String fillcolor) {
81+
this.fillcolor = fillcolor;
82+
}
83+
84+
public void geodesic(boolean geodesic) {
85+
this.geodesic = geodesic;
86+
}
87+
88+
public String toUrlValue() {
89+
List<String> urlParts = new ArrayList<>();
90+
91+
if (weight > 0) {
92+
urlParts.add("weight:" + weight);
93+
}
94+
95+
if (color != null) {
96+
urlParts.add("color:" + color);
97+
}
98+
99+
if (fillcolor != null) {
100+
urlParts.add("fillcolor:" + fillcolor);
101+
}
102+
103+
if (geodesic) {
104+
urlParts.add("geodesic:" + geodesic);
105+
}
106+
107+
urlParts.add("enc:" + points);
108+
109+
return StringJoin.join('|', urlParts.toArray(new String[urlParts.size()]));
110+
}
64111
}

0 commit comments

Comments
 (0)