|
@@ -1,5 +1,5 @@
|
|
import React, { useEffect } from 'react';
|
|
import React, { useEffect } from 'react';
|
|
-import { StyleSheet, Text, Dimensions } from 'react-native';
|
|
|
|
|
|
+import { StyleSheet, Text, Dimensions, View } from 'react-native';
|
|
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
|
|
import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated';
|
|
import { Colors } from 'src/theme';
|
|
import { Colors } from 'src/theme';
|
|
|
|
|
|
@@ -39,29 +39,15 @@ const SCALE_STEPS_IN_FEET = [
|
|
interface ScaleBarProps {
|
|
interface ScaleBarProps {
|
|
zoom: number;
|
|
zoom: number;
|
|
latitude: number;
|
|
latitude: number;
|
|
- isVisible: boolean;
|
|
|
|
bottom?: any;
|
|
bottom?: any;
|
|
}
|
|
}
|
|
|
|
|
|
-const ScaleBar: React.FC<ScaleBarProps> = ({ zoom, latitude, isVisible, bottom = '21%' }) => {
|
|
|
|
|
|
+const ScaleBar: React.FC<ScaleBarProps> = ({ zoom, latitude, bottom = '21%' }) => {
|
|
const metricWidth = useSharedValue(0);
|
|
const metricWidth = useSharedValue(0);
|
|
const imperialWidth = useSharedValue(0);
|
|
const imperialWidth = useSharedValue(0);
|
|
const metricText = useSharedValue('');
|
|
const metricText = useSharedValue('');
|
|
const imperialText = useSharedValue('');
|
|
const imperialText = useSharedValue('');
|
|
const screenWidth = Dimensions.get('window').width;
|
|
const screenWidth = Dimensions.get('window').width;
|
|
- const opacity = useSharedValue(isVisible ? 1 : 0);
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (isVisible) {
|
|
|
|
- opacity.value = withTiming(1, { duration: 100 });
|
|
|
|
- } else {
|
|
|
|
- opacity.value = withTiming(0, { duration: 1500 });
|
|
|
|
- }
|
|
|
|
- }, [isVisible]);
|
|
|
|
-
|
|
|
|
- const animatedStyle = useAnimatedStyle(() => ({
|
|
|
|
- opacity: opacity.value
|
|
|
|
- }));
|
|
|
|
|
|
|
|
const getResolutionFromZoomAndLatitude = (zoom: number, latitude: number) =>
|
|
const getResolutionFromZoomAndLatitude = (zoom: number, latitude: number) =>
|
|
(TILE_SIZE_METERS_AT_0_ZOOM * Math.cos((latitude * Math.PI) / 180)) / Math.pow(2, zoom);
|
|
(TILE_SIZE_METERS_AT_0_ZOOM * Math.cos((latitude * Math.PI) / 180)) / Math.pow(2, zoom);
|
|
@@ -117,7 +103,7 @@ const ScaleBar: React.FC<ScaleBarProps> = ({ zoom, latitude, isVisible, bottom =
|
|
if (!metricText.value || !imperialText.value) return null;
|
|
if (!metricText.value || !imperialText.value) return null;
|
|
|
|
|
|
return (
|
|
return (
|
|
- <Animated.View style={[styles.container, { bottom }, animatedStyle]}>
|
|
|
|
|
|
+ <View style={[styles.container, { bottom }]}>
|
|
<Text style={[styles.text, { bottom: 0 }]}>{metricText.value}</Text>
|
|
<Text style={[styles.text, { bottom: 0 }]}>{metricText.value}</Text>
|
|
|
|
|
|
<Animated.View style={[styles.scaleBar, animatedCombinedStyle]}>
|
|
<Animated.View style={[styles.scaleBar, animatedCombinedStyle]}>
|
|
@@ -126,7 +112,7 @@ const ScaleBar: React.FC<ScaleBarProps> = ({ zoom, latitude, isVisible, bottom =
|
|
</Animated.View>
|
|
</Animated.View>
|
|
|
|
|
|
<Text style={[styles.text, { top: 0 }]}>{imperialText.value}</Text>
|
|
<Text style={[styles.text, { top: 0 }]}>{imperialText.value}</Text>
|
|
- </Animated.View>
|
|
|
|
|
|
+ </View>
|
|
);
|
|
);
|
|
};
|
|
};
|
|
|
|
|
|
@@ -152,7 +138,7 @@ const styles = StyleSheet.create({
|
|
fontSize: 10,
|
|
fontSize: 10,
|
|
fontWeight: '500',
|
|
fontWeight: '500',
|
|
textAlign: 'center',
|
|
textAlign: 'center',
|
|
- color: Colors.TEXT_GRAY,
|
|
|
|
|
|
+ color: Colors.DARK_BLUE,
|
|
marginVertical: 4,
|
|
marginVertical: 4,
|
|
position: 'absolute',
|
|
position: 'absolute',
|
|
left: 0
|
|
left: 0
|