Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS][Android] Batch creation/removal for circles, fills and lines #576

Merged
merged 8 commits into from
Apr 12, 2021
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
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/CircleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class CircleBuilder implements CircleOptionsSink {
this.circleOptions = new CircleOptions();
}

public CircleOptions getCircleOptions(){
return this.circleOptions;
}

Circle build() {
return circleManager.create(circleOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class CircleController implements CircleOptionsSink {
this.onTappedListener = onTappedListener;
}

public Circle getCircle(){
return this.circle;
}

boolean onTap() {
if (onTappedListener != null) {
onTappedListener.onCircleTapped(circle);
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/FillBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class FillBuilder implements FillOptionsSink {
this.fillOptions = new FillOptions();
}

public FillOptions getFillOptions(){
return this.fillOptions;
}

Fill build() {
return fillManager.create(fillOptions);
}
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/FillController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class FillController implements FillOptionsSink {
this.onTappedListener = onTappedListener;
}

public Fill getFill(){
return this.fill;
}

boolean onTap() {
if (onTappedListener != null) {
onTappedListener.onFillTapped(fill);
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/LineBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class LineBuilder implements LineOptionsSink {
this.lineOptions = new LineOptions();
}

public LineOptions getLineOptions(){
return this.lineOptions;
}

Line build() {
return lineManager.create(lineOptions);
}
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/LineController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class LineController implements LineOptionsSink {
this.onTappedListener = onTappedListener;
}

public Line getLine(){
return this.line;
}

boolean onTap() {
if (onTappedListener != null) {
onTappedListener.onLineTapped(line);
Expand Down
129 changes: 128 additions & 1 deletion android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@
import com.mapbox.mapboxsdk.plugins.annotation.Annotation;
import com.mapbox.mapboxsdk.plugins.annotation.Circle;
import com.mapbox.mapboxsdk.plugins.annotation.CircleManager;
import com.mapbox.mapboxsdk.plugins.annotation.CircleOptions;
import com.mapbox.mapboxsdk.plugins.annotation.Fill;
import com.mapbox.mapboxsdk.plugins.annotation.FillManager;
import com.mapbox.mapboxsdk.plugins.annotation.FillOptions;
import com.mapbox.mapboxsdk.plugins.annotation.Line;
import com.mapbox.mapboxsdk.plugins.annotation.LineManager;
import com.mapbox.mapboxsdk.plugins.annotation.LineOptions;
import com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener;
import com.mapbox.mapboxsdk.plugins.annotation.Symbol;
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager;
Expand Down Expand Up @@ -627,7 +630,7 @@ public void onError(@NonNull String message) {
break;
}
case "symbols#removeAll": {
final ArrayList<String> symbolIds = call.argument("symbols");
final ArrayList<String> symbolIds = call.argument("ids");
SymbolController symbolController;

List<Symbol> symbolList = new ArrayList<Symbol>();
Expand Down Expand Up @@ -699,6 +702,47 @@ public void onError(@NonNull String message) {
result.success(null);
break;
}
case "line#addAll": {
List<String> newIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<LineOptions> optionList = new ArrayList<LineOptions>();
if (options != null) {
LineBuilder builder;
for (Object o : options) {
builder = newLineBuilder();
Convert.interpretLineOptions(o, builder);
optionList.add(builder.getLineOptions());
}
if (!optionList.isEmpty()) {
List<Line> newLines = lineManager.create(optionList);
String id;
for (Line line : newLines) {
id = String.valueOf(line.getId());
newIds.add(id);
lines.put(id, new LineController(line, true, this));
}
}
}
result.success(newIds);
break;
}
case "line#removeAll": {
final ArrayList<String> ids = call.argument("ids");
LineController lineController;

List<Line> toBeRemoved = new ArrayList<Line>();
for(String id : ids){
lineController = lines.remove(id);
if (lineController != null) {
toBeRemoved.add(lineController.getLine());
}
}
if(!toBeRemoved.isEmpty()) {
lineManager.delete(toBeRemoved);
}
result.success(null);
break;
}
case "line#update": {
final String lineId = call.argument("line");
final LineController line = line(lineId);
Expand Down Expand Up @@ -730,6 +774,47 @@ public void onError(@NonNull String message) {
result.success(circleId);
break;
}
case "circle#addAll": {
List<String> newIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<CircleOptions> optionList = new ArrayList<CircleOptions>();
if (options != null) {
CircleBuilder builder;
for (Object o : options) {
builder = newCircleBuilder();
Convert.interpretCircleOptions(o, builder);
optionList.add(builder.getCircleOptions());
}
if (!optionList.isEmpty()) {
List<Circle> newCircles = circleManager.create(optionList);
String id;
for (Circle circle : newCircles) {
id = String.valueOf(circle.getId());
newIds.add(id);
circles.put(id, new CircleController(circle, true, this));
}
}
}
result.success(newIds);
break;
}
case "circle#removeAll": {
final ArrayList<String> ids = call.argument("ids");
CircleController circleController;

List<Circle> toBeRemoved = new ArrayList<Circle>();
for(String id : ids){
circleController = circles.remove(id);
if (circleController != null) {
toBeRemoved.add(circleController.getCircle());
}
}
if(!toBeRemoved.isEmpty()) {
circleManager.delete(toBeRemoved);
}
result.success(null);
break;
}
case "circle#remove": {
final String circleId = call.argument("circle");
removeCircle(circleId);
Expand Down Expand Up @@ -764,6 +849,48 @@ public void onError(@NonNull String message) {
result.success(fillId);
break;
}

case "fill#addAll": {
List<String> newIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<FillOptions> optionList = new ArrayList<FillOptions>();
if (options != null) {
FillBuilder builder;
for (Object o : options) {
builder = newFillBuilder();
Convert.interpretFillOptions(o, builder);
optionList.add(builder.getFillOptions());
}
if (!optionList.isEmpty()) {
List<Fill> newFills = fillManager.create(optionList);
String id;
for (Fill fill : newFills) {
id = String.valueOf(fill.getId());
newIds.add(id);
fills.put(id, new FillController(fill, true, this));
}
}
}
result.success(newIds);
break;
}
case "fill#removeAll": {
final ArrayList<String> ids = call.argument("ids");
FillController fillController;

List<Fill> toBeRemoved = new ArrayList<Fill>();
for(String id : ids){
fillController = fills.remove(id);
if (fillController != null) {
toBeRemoved.add(fillController.getFill());
}
}
if(!toBeRemoved.isEmpty()) {
fillManager.delete(toBeRemoved);
}
result.success(null);
break;
}
case "fill#remove": {
final String fillId = call.argument("fill");
removeFill(fillId);
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:location/location.dart';
import 'package:mapbox_gl_example/custom_marker.dart';
import 'package:mapbox_gl_example/full_map.dart';
import 'package:mapbox_gl_example/offline_regions.dart';
import 'package:mapbox_gl_example/place_batch.dart';

import 'animate_camera.dart';
import 'annotation_order_maps.dart';
Expand Down Expand Up @@ -38,6 +39,7 @@ final List<ExamplePage> _allPages = <ExamplePage>[
OfflineRegionsPage(),
AnnotationOrderPage(),
CustomMarkerPage(),
BatchAddPage(),
];

class MapsDemo extends StatelessWidget {
Expand Down
Loading