Skip to content

Commit

Permalink
Batch create, batch delete symbols [getting rid of command classes]
Browse files Browse the repository at this point in the history
  • Loading branch information
Anastasia Chechulina committed May 30, 2020
1 parent 0a5d098 commit 89ead44
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 295 deletions.

This file was deleted.

This file was deleted.

49 changes: 29 additions & 20 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.mapbox.mapboxsdk.plugins.annotation.Line;
import com.mapbox.mapboxsdk.plugins.annotation.LineManager;
import com.mapbox.geojson.Feature;
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -555,42 +556,50 @@ public void onError(@NonNull String message) {
result.success(symbolId);
break;
}
case "symbol#add_many": {
List<String> newSymbolIds = null;
final List<Object> options = call.argument("options");
if (options != null) {
final BatchSymbolsCreateCommand batchSymbolsCreateCommand = new BatchSymbolsCreateCommand();
SymbolOptionsProvider symbolOptionsProvider;
for (Object o : options) {
symbolOptionsProvider = new SymbolOptionsProvider();
Convert.interpretSymbolOptions(o, symbolOptionsProvider);
symbolOptionsProvider.commitToBatchCreateCommand(batchSymbolsCreateCommand);
case "symbol#addAll": {
List<String> newSymbolIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<SymbolOptions> symbolOptionsList = new ArrayList<SymbolOptions>();
if (options != null) {
SymbolBuilder symbolBuilder;
for (Object o : options) {
symbolBuilder = newSymbolBuilder();
Convert.interpretSymbolOptions(o, symbolBuilder);
symbolOptionsList.add(symbolBuilder.getSymbolOptions());
}
if (!symbolOptionsList.isEmpty()) {
List<Symbol> newSymbols = symbolManager.create(symbolOptionsList);
String symbolId;
for (Symbol symbol : newSymbols) {
symbolId = String.valueOf(symbol.getId());
newSymbolIds.add(symbolId);
symbols.put(symbolId, new SymbolController(symbol, true, this));
}
}
}
Map<String, SymbolController> newSymbolControllers = batchSymbolsCreateCommand.create(symbolManager, this);
symbols.putAll(newSymbolControllers);
newSymbolIds = new ArrayList<>(newSymbolControllers.keySet());
}
result.success(newSymbolIds);
break;
result.success(newSymbolIds);
break;
}
case "symbol#remove": {
final String symbolId = call.argument("symbol");
removeSymbol(symbolId);
result.success(null);
break;
}
case "symbol#remove_many": {
case "symbol#removeAll": {
final ArrayList<String> symbolIds = call.argument("symbols");
final BatchSymbolsRemoveCommand batchSymbolsRemoveCommand = new BatchSymbolsRemoveCommand();
SymbolController symbolController;

List<Symbol> symbolList = new ArrayList<Symbol>();
for(String symbolId : symbolIds){
symbolController = symbols.remove(symbolId);
if (symbolController != null) {
symbolController.commitToBatchRemoveCommand(batchSymbolsRemoveCommand);
symbolList.add(symbolController.getSymbol());
}
}
batchSymbolsRemoveCommand.delete(symbolManager);
if(!symbolList.isEmpty()) {
symbolManager.delete(symbolList);
}
result.success(null);
break;
}
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/SymbolBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Symbol build() {
return symbolManager.create(symbolOptions);
}

public SymbolOptions getSymbolOptions(){
return this.symbolOptions;
}

@Override
public void setIconSize(float iconSize) {
symbolOptions.withIconSize(iconSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ boolean onTap() {
return consumeTapEvents;
}

void commitToBatchRemoveCommand(BatchSymbolsRemoveCommand batchSymbolsRemoveCommand) {
batchSymbolsRemoveCommand.add(symbol);
public Symbol getSymbol(){
return this.symbol;
}

void remove(SymbolManager symbolManager) {
Expand Down
158 changes: 0 additions & 158 deletions android/src/main/java/com/mapbox/mapboxgl/SymbolOptionsProvider.java

This file was deleted.

Loading

0 comments on commit 89ead44

Please sign in to comment.