ArrowLineLayer extends KujakuLayer { @Override public void updateFeatures(@NonNull FeatureCollection featureCollection) { if (this.builder.featureConfig.featureCollection != null) { this.builder.featureConfig.featureCollection = featureCollection; } if (this.builder.featureConfig.featureFilterBuilder != null) { this.builder.featureConfig.featureFilterBuilder.setFeatureCollection(featureCollection); } if (lineLayer != null) { GenericAsyncTask genericAsyncTask = new GenericAsyncTask(new AsyncTaskCallable() { @Override public Object[] call() throws Exception { FeatureCollection filteredFeatureCollection = filterFeatures(builder.featureConfig, builder.sortConfig); FeatureCollection arrowHeadFeatures; if (builder.sortConfig != null) { FeatureCollection sortedFeatureCollection = sortFeatures(filteredFeatureCollection, builder.sortConfig); LineString arrowLine = calculateLineString(sortedFeatureCollection); arrowHeadFeatures = generateArrowHeadFeatureCollection(arrowLine); return new Object[]{arrowLine, arrowHeadFeatures}; } else if (builder.oneToManyConfig != null) { MultiLineString arrowLine = calculateMultiLineString(filteredFeatureCollection, builder.oneToManyConfig); arrowHeadFeatures = generateArrowHeadFeatureCollection(arrowLine); return new Object[]{arrowLine, arrowHeadFeatures}; } else { throw new IllegalArgumentException("SortConfig & OneToManyConfig not available to draw the line layer"); } } }); genericAsyncTask.setOnFinishedListener(new OnFinishedListener() { @Override public void onSuccess(Object[] objects) { Geometry arrowLine = (Geometry) objects[0]; FeatureCollection arrowHeadFeatures = (FeatureCollection) objects[1]; arrowHeadSource.setGeoJson(arrowHeadFeatures); lineLayerSource.setGeoJson(arrowLine); } @Override public void onError(Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } }); genericAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } private  ArrowLineLayer(@NonNull Builder builder); LineLayer getLineLayer(); SymbolLayer getArrowHeadLayer(); @Override void addLayerToMap(@NonNull MapboxMap mapboxMap); @Override void enableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void disableLayerOnMap(@NonNull MapboxMap mapboxMap); @Override @NonNull String[] getLayerIds(); @Override boolean removeLayerOnMap(@NonNull MapboxMap mapboxMap); @Override void updateFeatures(@NonNull FeatureCollection featureCollection); static Point getCenter(@NonNull Geometry featureGeometry); @Override FeatureCollection getFeatureCollection(); static final String ARROW_HEAD_BEARING; static final int MIN_ARROW_ZOOM; static final int MAX_ARROW_ZOOM; static final float MIN_ZOOM_ARROW_HEAD_SCALE; static final float MAX_ZOOM_ARROW_HEAD_SCALE; }
@Test public void updateFeaturesShouldUpdateFeatureCollectionWhenNoFilterIsBeingUsed() throws InvalidArrowLineConfigException { ArrayList<Feature> featuresList = new ArrayList<>(); FeatureCollection featureCollection = FeatureCollection.fromFeatures(featuresList); ArrowLineLayer.FeatureConfig featureConfig = new ArrowLineLayer.FeatureConfig(featureCollection); ArrowLineLayer.SortConfig sortConfig = new ArrowLineLayer.SortConfig("", ArrowLineLayer.SortConfig.SortOrder.DESC, ArrowLineLayer.SortConfig.PropertyType.NUMBER); ArrowLineLayer.Builder builder = new ArrowLineLayer.Builder(context, featureConfig, sortConfig); ArrowLineLayer arrowLineLayer = builder.build(); FeatureCollection updatedFeatureCollection = FeatureCollection.fromFeatures(new ArrayList<Feature>()); arrowLineLayer.updateFeatures(updatedFeatureCollection); assertEquals(updatedFeatureCollection, ReflectionHelpers.getField( ReflectionHelpers.getField( ReflectionHelpers.getField(arrowLineLayer, "builder") , "featureConfig") , "featureCollection") ); }