Skip to content

Fixes #2238 scalebar added in map #3511

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

Merged
merged 7 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -196,6 +198,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private boolean isVisibleToUser;
private MapboxMap.OnCameraMoveListener cameraMoveListener;
private fr.free.nrw.commons.location.LatLng lastFocusLocation;
private ScaleBarPlugin scaleBarPlugin;
private ScaleBarOptions scaleBarOptions;


@Override
Expand Down Expand Up @@ -239,6 +243,29 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
.zoom(ZOOM_LEVEL)
.build();
mapBoxMap.setCameraPosition(cameraPosition);
scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);

int color = isDarkTheme?R.color.bottom_bar_light:R.color.bottom_bar_dark;

final float SIZE = new TextView(getContext()).getTextSize()-1; //Default text size for scalebar params
final float SCALEBAR_HEIGHT = (float) (SIZE/3.5); //these values are chosen to keep scalebar size comparable to other text depending upon the screen size and device resolution
final float SCALEBAR_BORDER_WIDTH = SIZE/10;
final float SCALEBAR_MARGIN = SIZE/2;
final int REFRESH_INTERVAL = 15; //minimum refresh time in millisec

scaleBarOptions = new ScaleBarOptions(getContext())
.setTextColor(color)
.setTextSize(SIZE)
.setBarHeight(SCALEBAR_HEIGHT)
.setBorderWidth(SCALEBAR_BORDER_WIDTH)
.setMetricUnit(true)
.setRefreshInterval(REFRESH_INTERVAL)
.setMarginTop(SCALEBAR_MARGIN)
.setMarginLeft(SCALEBAR_MARGIN)
.setTextBarMargin(SCALEBAR_MARGIN);


scaleBarPlugin.create(scaleBarOptions);
});

});
Expand Down