Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
light cleanup of FeatureCollection and Source initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
langsmith authored and Langston Smith committed May 19, 2020
1 parent 753bf74 commit 813f08c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
public class DashedLineDirectionsPickerActivity extends AppCompatActivity
implements OnMapReadyCallback, MapboxMap.OnCameraIdleListener {

private static final String DIRECTIONS_LAYER_ID = "DIRECTIONS_LAYER_ID";
private static final String LAYER_BELOW_ID = "road-label-small";
private static final String SOURCE_ID = "SOURCE_ID";
private MapView mapView;
private MapboxMap mapboxMap;
private FeatureCollection dashedLineDirectionsFeatureCollection;
Expand Down Expand Up @@ -117,16 +120,15 @@ public void onCameraIdle() {
* to the place picker location
*/
private void initDottedLineSourceAndLayer(@NonNull Style loadedMapStyle) {
dashedLineDirectionsFeatureCollection = FeatureCollection.fromFeatures(new Feature[] {});
loadedMapStyle.addSource(new GeoJsonSource("SOURCE_ID", dashedLineDirectionsFeatureCollection));
loadedMapStyle.addSource(new GeoJsonSource(SOURCE_ID));
loadedMapStyle.addLayerBelow(
new LineLayer(
"DIRECTIONS_LAYER_ID", "SOURCE_ID").withProperties(
DIRECTIONS_LAYER_ID, SOURCE_ID).withProperties(
lineWidth(4.5f),
lineColor(Color.BLACK),
lineTranslate(new Float[] {0f, 4f}),
lineDasharray(new Float[] {1.2f, 1.2f})
), "road-label-small");
), LAYER_BELOW_ID);
}

/**
Expand Down Expand Up @@ -185,7 +187,7 @@ public void onStyleLoaded(@NonNull Style style) {
directionsRouteFeatureList.add(Feature.fromGeometry(LineString.fromLngLats(coordinates)));
}
dashedLineDirectionsFeatureCollection = FeatureCollection.fromFeatures(directionsRouteFeatureList);
GeoJsonSource source = style.getSourceAs("SOURCE_ID");
GeoJsonSource source = style.getSourceAs(SOURCE_ID);
if (source != null) {
source.setGeoJson(dashedLineDirectionsFeatureCollection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public void onStyleLoaded(@NonNull Style style) {
}

private void initFeatureCollection() {
featureCollection = FeatureCollection.fromFeatures(new Feature[] {});
List<Feature> featureList = new ArrayList<>();
if (featureCollection != null) {
for (LatLng latLng : coordinates) {
Expand Down
1 change: 1 addition & 0 deletions MapboxAndroidDemo/src/main/res/values/activity_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,5 @@
<string name="duration">Duration:</string>
<string name="color">Color:</string>
<string name="select">Select</string>

</resources>

0 comments on commit 813f08c

Please sign in to comment.