Skip to content

Commit

Permalink
Cherry-pick upstream#820 (HOTFIX Add option to not use annotations - …
Browse files Browse the repository at this point in the history
…android performance)

https: //github.com/flutter-mapbox-gl/maps/pull/820
Co-Authored-By: Felix Horvat <[email protected]>
  • Loading branch information
m0nac0 and felix-ht committed May 20, 2022
1 parent 6ec9b85 commit 272eea2
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
class MapboxMapBuilder implements MapboxMapOptionsSink {
public final String TAG = getClass().getSimpleName();
private final MapboxMapOptions options = new MapboxMapOptions()
.textureMode(true)
.attributionEnabled(true);
private boolean trackCameraPosition = false;
private boolean myLocationEnabled = false;
Expand Down
103 changes: 103 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ final class MapboxMapController
private List<String> annotationConsumeTapEvents;
private Set<String> featureLayerIdentifiers;
private LatLngBounds bounds = null;
private static final String annotationManagerNotCreatedErrorCode = "NO ANNOTATION MANAGER";
private static final String annotationManagerNotCreatedErrorMessage = "To use %ss please add it to the annotation list";

MapboxMapController(
int id,
Expand Down Expand Up @@ -559,6 +561,7 @@ private Feature firstFeatureOnLayers(RectF in) {

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {

switch (call.method) {
case "map#waitForMap":
if (mapboxMap != null) {
Expand Down Expand Up @@ -754,6 +757,10 @@ public void onError(@NonNull String message) {
break;
}
case "symbols#addAll": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
List<String> newSymbolIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<SymbolOptions> symbolOptionsList = new ArrayList<SymbolOptions>();
Expand All @@ -778,6 +785,10 @@ public void onError(@NonNull String message) {
break;
}
case "symbols#removeAll": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final ArrayList<String> symbolIds = call.argument("ids");
SymbolController symbolController;

Expand All @@ -795,6 +806,10 @@ public void onError(@NonNull String message) {
break;
}
case "symbol#update": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final String symbolId = call.argument("symbol");
final SymbolController symbol = symbol(symbolId);
Convert.interpretSymbolOptions(call.argument("options"), symbol);
Expand All @@ -803,6 +818,10 @@ public void onError(@NonNull String message) {
break;
}
case "symbol#getGeometry": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final String symbolId = call.argument("symbol");
final SymbolController symbol = symbol(symbolId);
final LatLng symbolLatLng = symbol.getGeometry();
Expand All @@ -812,30 +831,50 @@ public void onError(@NonNull String message) {
result.success(hashMapLatLng);
}
case "symbolManager#iconAllowOverlap": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final Boolean value = call.argument("iconAllowOverlap");
symbolManager.setIconAllowOverlap(value);
result.success(null);
break;
}
case "symbolManager#iconIgnorePlacement": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final Boolean value = call.argument("iconIgnorePlacement");
symbolManager.setIconIgnorePlacement(value);
result.success(null);
break;
}
case "symbolManager#textAllowOverlap": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final Boolean value = call.argument("textAllowOverlap");
symbolManager.setTextAllowOverlap(value);
result.success(null);
break;
}
case "symbolManager#textIgnorePlacement": {
if(symbolManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "symbol"), null);
return;
}
final Boolean iconAllowOverlap = call.argument("textIgnorePlacement");
symbolManager.setTextIgnorePlacement(iconAllowOverlap);
result.success(null);
break;
}
case "line#add": {
if(lineManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "line"), null);
return;
}
final LineBuilder lineBuilder = newLineBuilder();
Convert.interpretLineOptions(call.argument("options"), lineBuilder);
final Line line = lineBuilder.build();
Expand All @@ -845,12 +884,20 @@ public void onError(@NonNull String message) {
break;
}
case "line#remove": {
if(lineManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "line"), null);
return;
}
final String lineId = call.argument("line");
removeLine(lineId);
result.success(null);
break;
}
case "line#addAll": {
if(lineManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "line"), null);
return;
}
List<String> newIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<LineOptions> optionList = new ArrayList<LineOptions>();
Expand All @@ -875,6 +922,10 @@ public void onError(@NonNull String message) {
break;
}
case "line#removeAll": {
if(lineManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "line"), null);
return;
}
final ArrayList<String> ids = call.argument("ids");
LineController lineController;

Expand All @@ -892,6 +943,10 @@ public void onError(@NonNull String message) {
break;
}
case "line#update": {
if(lineManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "line"), null);
return;
}
final String lineId = call.argument("line");
final LineController line = line(lineId);
Convert.interpretLineOptions(call.argument("options"), line);
Expand All @@ -900,6 +955,10 @@ public void onError(@NonNull String message) {
break;
}
case "line#getGeometry": {
if(lineManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "line"), null);
return;
}
final String lineId = call.argument("line");
final LineController line = line(lineId);
final List<LatLng> lineLatLngs = line.getGeometry();
Expand All @@ -914,6 +973,10 @@ public void onError(@NonNull String message) {
break;
}
case "circle#add": {
if(circleManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "circle"), null);
return;
}
final CircleBuilder circleBuilder = newCircleBuilder();
Convert.interpretCircleOptions(call.argument("options"), circleBuilder);
final Circle circle = circleBuilder.build();
Expand All @@ -923,6 +986,10 @@ public void onError(@NonNull String message) {
break;
}
case "circle#addAll": {
if(circleManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "circle"), null);
return;
}
List<String> newIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<CircleOptions> optionList = new ArrayList<CircleOptions>();
Expand All @@ -947,6 +1014,10 @@ public void onError(@NonNull String message) {
break;
}
case "circle#removeAll": {
if(circleManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "circle"), null);
return;
}
final ArrayList<String> ids = call.argument("ids");
CircleController circleController;

Expand All @@ -964,12 +1035,20 @@ public void onError(@NonNull String message) {
break;
}
case "circle#remove": {
if(circleManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "circle"), null);
return;
}
final String circleId = call.argument("circle");
removeCircle(circleId);
result.success(null);
break;
}
case "circle#update": {
if(circleManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "circle"), null);
return;
}
Log.e(TAG, "update circle");
final String circleId = call.argument("circle");
final CircleController circle = circle(circleId);
Expand All @@ -979,6 +1058,10 @@ public void onError(@NonNull String message) {
break;
}
case "circle#getGeometry": {
if(circleManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "circle"), null);
return;
}
final String circleId = call.argument("circle");
final CircleController circle = circle(circleId);
final LatLng circleLatLng = circle.getGeometry();
Expand All @@ -989,6 +1072,10 @@ public void onError(@NonNull String message) {
break;
}
case "fill#add": {
if(fillManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "fill"), null);
return;
}
final FillBuilder fillBuilder = newFillBuilder();
Convert.interpretFillOptions(call.argument("options"), fillBuilder);
final Fill fill = fillBuilder.build();
Expand All @@ -999,6 +1086,10 @@ public void onError(@NonNull String message) {
}

case "fill#addAll": {
if(fillManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "fill"), null);
return;
}
List<String> newIds = new ArrayList<String>();
final List<Object> options = call.argument("options");
List<FillOptions> optionList = new ArrayList<FillOptions>();
Expand All @@ -1023,6 +1114,10 @@ public void onError(@NonNull String message) {
break;
}
case "fill#removeAll": {
if(fillManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "fill"), null);
return;
}
final ArrayList<String> ids = call.argument("ids");
FillController fillController;

Expand All @@ -1040,12 +1135,20 @@ public void onError(@NonNull String message) {
break;
}
case "fill#remove": {
if(fillManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "fill"), null);
return;
}
final String fillId = call.argument("fill");
removeFill(fillId);
result.success(null);
break;
}
case "fill#update": {
if(fillManager == null){
result.error(annotationManagerNotCreatedErrorCode, String.format(annotationManagerNotCreatedErrorCode, "fill"), null);
return;
}
final String fillId = call.argument("fill");
final FillController fill = fill(fillId);
Convert.interpretFillOptions(call.argument("options"), fill);
Expand Down
1 change: 1 addition & 0 deletions example/lib/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LayerState extends State {
target: center,
zoom: 11.0,
),
annotationOrder: const [],
);
}

Expand Down
Loading

0 comments on commit 272eea2

Please sign in to comment.