Skip to content

Commit a33fab0

Browse files
authored
feat: added cap to polyline (#1603)
* feat: added startCap and endCap to polyline * feat: non-nullable
1 parent 0aaae62 commit a33fab0

File tree

1 file changed

+23
-83
lines changed

1 file changed

+23
-83
lines changed

library/src/main/java/com/google/maps/android/data/geojson/GeoJsonLineStringStyle.java

Lines changed: 23 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.maps.android.data.geojson;
1717

18+
import com.google.android.gms.maps.model.Cap;
1819
import com.google.android.gms.maps.model.PatternItem;
1920
import com.google.android.gms.maps.model.PolylineOptions;
2021
import com.google.maps.android.data.Style;
@@ -27,7 +28,7 @@
2728
/**
2829
* A class that allows for GeoJsonLineString objects to be styled and for these styles to be
2930
* translated into a PolylineOptions object. {@see
30-
* <a href="https://developer.android.com/reference/com/google/android/gms/maps/model/PolylineOptions.html">
31+
* <a href="https://developers.google.com/android/reference/com/google/android/gms/maps/model/PolylineOptions">
3132
* PolylineOptions docs</a> for more details about the options.}
3233
*/
3334
public class GeoJsonLineStringStyle extends Style implements GeoJsonStyle {
@@ -43,144 +44,72 @@ public GeoJsonLineStringStyle() {
4344
mPolylineOptions.clickable(true);
4445
}
4546

46-
/**
47-
* {@inheritDoc}
48-
*/
4947
@Override
5048
public String[] getGeometryType() {
5149
return GEOMETRY_TYPE;
5250
}
5351

54-
/**
55-
* Gets the color of the GeoJsonLineString as a 32-bit ARGB color
56-
*
57-
* @return color of the GeoJsonLineString
58-
*/
5952
public int getColor() {
6053
return mPolylineOptions.getColor();
6154
}
6255

63-
/**
64-
* Sets the color of the GeoJsonLineString as a 32-bit ARGB color
65-
*
66-
* @param color color value of the GeoJsonLineString
67-
*/
6856
public void setColor(int color) {
6957
mPolylineOptions.color(color);
7058
styleChanged();
7159
}
7260

73-
/**
74-
* Gets the clickability setting for this Options object
75-
*
76-
* @return true if the GeoJsonLineString is clickable; false if it is not
77-
*/
7861
public boolean isClickable() {
7962
return mPolylineOptions.isClickable();
8063
}
8164

82-
/**
83-
* Specifies whether this GeoJsonLineString is clickable
84-
*
85-
* @param clickable - new clickability setting for the GeoJsonLineString
86-
*/
8765
public void setClickable(boolean clickable) {
8866
mPolylineOptions.clickable(clickable);
8967
styleChanged();
9068
}
9169

92-
/**
93-
* Gets whether the GeoJsonLineString is geodesic
94-
*
95-
* @return true if GeoJsonLineString is geodesic, false otherwise
96-
*/
9770
public boolean isGeodesic() {
9871
return mPolylineOptions.isGeodesic();
9972
}
10073

101-
/**
102-
* Sets whether the GeoJsonLineString is geodesic
103-
*
104-
* @param geodesic true if GeoJsonLineString is geodesic, false otherwise
105-
*/
10674
public void setGeodesic(boolean geodesic) {
10775
mPolylineOptions.geodesic(geodesic);
10876
styleChanged();
10977
}
11078

111-
/**
112-
* Gets the width of the GeoJsonLineString in screen pixels
113-
*
114-
* @return width of the GeoJsonLineString
115-
*/
11679
public float getWidth() {
11780
return mPolylineOptions.getWidth();
11881
}
11982

120-
/**
121-
* Sets the width of the GeoJsonLineString in screen pixels
122-
*
123-
* @param width width value of the GeoJsonLineString
124-
*/
12583
public void setWidth(float width) {
12684
setLineStringWidth(width);
12785
styleChanged();
12886
}
12987

130-
/**
131-
* Gets the z index of the GeoJsonLineString
132-
*
133-
* @return z index of the GeoJsonLineString
134-
*/
13588
public float getZIndex() {
13689
return mPolylineOptions.getZIndex();
13790
}
13891

139-
/**
140-
* Sets the z index of the GeoJsonLineString
141-
*
142-
* @param zIndex z index value of the GeoJsonLineString
143-
*/
14492
public void setZIndex(float zIndex) {
14593
mPolylineOptions.zIndex(zIndex);
14694
styleChanged();
14795
}
14896

149-
/**
150-
* Gets whether the GeoJsonLineString is visible
151-
*
152-
* @return true if the GeoJsonLineString visible, false if not visible
153-
*/
15497
@Override
15598
public boolean isVisible() {
15699
return mPolylineOptions.isVisible();
157100
}
158101

159-
/**
160-
* Sets whether the GeoJsonLineString is visible
161-
*
162-
* @param visible true if the GeoJsonLineString is visible, false if not visible
163-
*/
164102
@Override
165103
public void setVisible(boolean visible) {
166104
mPolylineOptions.visible(visible);
167105
styleChanged();
168106
}
169107

170-
/**
171-
* Notifies the observers, GeoJsonFeature objects, that the style has changed. Indicates to the
172-
* GeoJsonFeature that it should check whether a redraw is needed for the feature.
173-
*/
174108
private void styleChanged() {
175109
setChanged();
176110
notifyObservers();
177111
}
178112

179-
/**
180-
* Gets a new PolylineOptions object containing styles for the GeoJsonLineString
181-
*
182-
* @return new PolylineOptions object
183-
*/
184113
public PolylineOptions toPolylineOptions() {
185114
PolylineOptions polylineOptions = new PolylineOptions();
186115
polylineOptions.color(mPolylineOptions.getColor());
@@ -190,6 +119,8 @@ public PolylineOptions toPolylineOptions() {
190119
polylineOptions.width(mPolylineOptions.getWidth());
191120
polylineOptions.zIndex(mPolylineOptions.getZIndex());
192121
polylineOptions.pattern(getPattern());
122+
polylineOptions.startCap(getStartCap());
123+
polylineOptions.endCap(getEndCap());
193124
return polylineOptions;
194125
}
195126

@@ -205,27 +136,36 @@ public String toString() {
205136
sb.append(",\n width=").append(getWidth());
206137
sb.append(",\n z index=").append(getZIndex());
207138
sb.append(",\n pattern=").append(getPattern());
139+
sb.append(",\n startCap=").append(getStartCap());
140+
sb.append(",\n endCap=").append(getEndCap());
208141
sb.append("\n}\n");
209142
return sb.toString();
210143
}
211144

212-
/**
213-
* Gets the pattern of the GeoJsonLineString
214-
*
215-
* @return line style of GeoJsonLineString
216-
*/
217145
public List<PatternItem> getPattern() {
218146
return mPolylineOptions.getPattern();
219147
}
220148

221-
/**
222-
* Sets the pattern of the GeoJsonLineString
223-
*
224-
* @param pattern line style of GeoJsonLineString
225-
*/
226149
public void setPattern(List<PatternItem> pattern) {
227150
mPolylineOptions.pattern(pattern);
228151
styleChanged();
229152
}
230153

154+
public void setStartCap(@NonNull Cap cap) {
155+
mPolylineOptions.startCap(cap);
156+
styleChanged();
157+
}
158+
159+
public void setEndCap(@NonNull Cap cap) {
160+
mPolylineOptions.endCap(cap);
161+
styleChanged();
162+
}
163+
164+
public Cap getStartCap() {
165+
return mPolylineOptions.getStartCap();
166+
}
167+
168+
public Cap getEndCap() {
169+
return mPolylineOptions.getEndCap();
170+
}
231171
}

0 commit comments

Comments
 (0)