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

Light cleanup of FeatureCollection and Source initialization #1310

Merged
merged 2 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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