diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt index 95398fb6c..321e3e82a 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt @@ -1305,12 +1305,15 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie } var mScaleBarSettings = OrnamentSettings(enabled = false) - + var mScaleBarIsMetricUnits = false fun setReactScaleBarEnabled(scaleBarEnabled: Boolean) { mScaleBarSettings.enabled = scaleBarEnabled changes.add(Property.SCALEBAR) } - + fun setReactScaleBarIsMetricUnits(isMetricUnits: Boolean) { + mScaleBarIsMetricUnits = isMetricUnits + changes.add(Property.SCALEBAR) + } fun setReactScaleBarViewMargins(scaleBarMargins: ReadableMap) { mScaleBarSettings.margins = scaleBarMargins changes.add(Property.SCALEBAR) @@ -1328,6 +1331,7 @@ open class RNMBXMapView(private val mContext: Context, var mManager: RNMBXMapVie private fun applyScaleBar() { mapView.scalebar.updateSettings { + isMetricUnits = mScaleBarIsMetricUnits updateOrnament("scaleBar", mScaleBarSettings, this.toGenericOrnamentSettings()) } workaroundToRelayoutChildOfMapView() diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt index 98febe73a..f8eb75a29 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapViewManager.kt @@ -280,6 +280,11 @@ open class RNMBXMapViewManager(context: ReactApplicationContext, val viewTagReso mapView.setReactScaleBarEnabled(scaleBarEnabled.asBoolean()) } + @ReactProp(name = "scaleBarIsMetricUnits") + override fun setScaleBarIsMetricUnits(mapView: RNMBXMapView, isMetricUnits: Dynamic) { + mapView.setReactScaleBarIsMetricUnits(isMetricUnits.asBoolean()) + } + @ReactProp(name = "scaleBarViewMargins") override fun setScaleBarViewMargins(mapView: RNMBXMapView, scaleBarMargins: Dynamic) { mapView.setReactScaleBarViewMargins(scaleBarMargins.asMap()) diff --git a/android/src/main/java/com/rnmapbox/rnmbx/location/LocationManager.kt b/android/src/main/java/com/rnmapbox/rnmbx/location/LocationManager.kt index daa77e534..babba4386 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/location/LocationManager.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/location/LocationManager.kt @@ -150,7 +150,7 @@ class LocationManager private constructor(private val context: Context) : Locati fun destroy() { dispose(); - nStarts = -1000; + nStarts = 0; } //// @@ -274,4 +274,4 @@ class LocationManager private constructor(private val context: Context) : Locati init { buildEngineRequest() } -} \ No newline at end of file +} diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java index 63e6d3d15..c168ff9fb 100644 --- a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerDelegate.java @@ -52,6 +52,9 @@ public void setProperty(T view, String propName, @Nullable Object value) { case "scaleBarEnabled": mViewManager.setScaleBarEnabled(view, new DynamicFromObject(value)); break; + case "scaleBarIsMetricUnits": + mViewManager.setScaleBarIsMetricUnits(view, new DynamicFromObject(value)); + break; case "scaleBarPosition": mViewManager.setScaleBarPosition(view, new DynamicFromObject(value)); break; diff --git a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java index d6c1139a3..3488af29e 100644 --- a/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java +++ b/android/src/main/old-arch/com/facebook/react/viewmanagers/RNMBXMapViewManagerInterface.java @@ -23,6 +23,7 @@ public interface RNMBXMapViewManagerInterface { void setCompassViewPosition(T view, Dynamic value); void setCompassViewMargins(T view, Dynamic value); void setScaleBarEnabled(T view, Dynamic value); + void setScaleBarIsMetricUnits(T view, Dynamic value); void setScaleBarPosition(T view, Dynamic value); void setZoomEnabled(T view, Dynamic value); void setScrollEnabled(T view, Dynamic value); diff --git a/example/src/examples/Map/Ornaments.tsx b/example/src/examples/Map/Ornaments.tsx index 1b181568f..f3c34645e 100755 --- a/example/src/examples/Map/Ornaments.tsx +++ b/example/src/examples/Map/Ornaments.tsx @@ -37,8 +37,10 @@ type OrnamentButtonsProps = { ornamentType: OrnamentType; visibility: Record; position: Record; + isMetricUnits?: boolean; onPressVisibility: (ornamentType: OrnamentType) => void; onPressPosition: (ornamentType: OrnamentType) => void; + onPressIsMetricUnits?: () => void; }; const OrnamentButtons = ({ @@ -47,6 +49,8 @@ const OrnamentButtons = ({ position, onPressVisibility, onPressPosition, + isMetricUnits, + onPressIsMetricUnits, }: OrnamentButtonsProps) => ( <>