Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation 'com.github.pedrovgs:renderers:3.3.3'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.11.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-scalebar-v9:0.4.0'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
implementation 'com.karumi:dexter:5.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.maps.UiSettings;
import com.mapbox.pluginscalebar.ScaleBarOptions;
import com.mapbox.pluginscalebar.ScaleBarPlugin;
import com.pedrogomez.renderers.RVRendererAdapter;

import java.util.ArrayList;
Expand Down Expand Up @@ -239,8 +241,25 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
.zoom(ZOOM_LEVEL)
.build();
mapBoxMap.setCameraPosition(cameraPosition);
});

ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);
int color = isDarkTheme ? R.color.bottom_bar_light : R.color.bottom_bar_dark;
//Default text size for scalebar params
final float SIZE = new TextView(getContext()).getTextSize() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of glanced over this because I thought I already saw review comments but I would caution against this.

Resolve a dimen value that is appropriate here, you can use context.getResources().getDimensionPixelSize(R.dimen.some_dimen) and that will give you different sizes depending on the density of the screen. All of these should be like that and the math should be avoided. Constructing a textview to find out the default value of text size is putting the donkey before the cart, a little bit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!! I understand, will do that.

//these values are chosen to keep scalebar size comparable to other text depending upon the screen size and device resolution
final float SCALEBAR_HEIGHT = (float) (SIZE / 3.5);
final float SCALEBAR_BORDER_WIDTH = SIZE / 10;
final float SCALEBAR_MARGIN = SIZE / 2;
ScaleBarOptions scaleBarOptions = new ScaleBarOptions(getContext())
.setTextColor(color)
.setTextSize(SIZE)
.setBarHeight(SCALEBAR_HEIGHT)
.setBorderWidth(SCALEBAR_BORDER_WIDTH)
.setMarginTop(SCALEBAR_MARGIN)
.setMarginLeft(SCALEBAR_MARGIN)
.setTextBarMargin(SCALEBAR_MARGIN);
scaleBarPlugin.create(scaleBarOptions);
});
});
}

Expand Down