fix(dae): navigation control buttons
This commit is contained in:
parent
58bdb3898b
commit
a6c3dc2641
1 changed files with 87 additions and 32 deletions
|
|
@ -14,8 +14,13 @@ import Drawer from "react-native-drawer";
|
||||||
import MapView from "~/containers/Map/MapView";
|
import MapView from "~/containers/Map/MapView";
|
||||||
import Camera from "~/containers/Map/Camera";
|
import Camera from "~/containers/Map/Camera";
|
||||||
import LastKnownLocationMarker from "~/containers/Map/LastKnownLocationMarker";
|
import LastKnownLocationMarker from "~/containers/Map/LastKnownLocationMarker";
|
||||||
import { DEFAULT_ZOOM_LEVEL } from "~/containers/Map/constants";
|
import { BoundType } from "~/containers/Map/constants";
|
||||||
import StepZoomButtonGroup from "~/containers/Map/StepZoomButtonGroup";
|
import StepZoomButtonGroup from "~/containers/Map/StepZoomButtonGroup";
|
||||||
|
import useMapInit from "~/containers/Map/useMapInit";
|
||||||
|
import TargetButton from "~/containers/Map/TargetButton";
|
||||||
|
import ToggleColorSchemeButton from "~/containers/Map/ToggleColorSchemeButton";
|
||||||
|
import MapLinksPopupIconButton from "~/containers/MapLinksPopup/IconButton";
|
||||||
|
import MapLinksPopup from "~/containers/MapLinksPopup";
|
||||||
|
|
||||||
import Text from "~/components/Text";
|
import Text from "~/components/Text";
|
||||||
import IconTouchTarget from "~/components/IconTouchTarget";
|
import IconTouchTarget from "~/components/IconTouchTarget";
|
||||||
|
|
@ -49,20 +54,52 @@ export default React.memo(function DAEItemCarte() {
|
||||||
const { hasInternetConnection } = useNetworkState(["hasInternetConnection"]);
|
const { hasInternetConnection } = useNetworkState(["hasInternetConnection"]);
|
||||||
const { coords, isLastKnown, lastKnownTimestamp } = useLocation();
|
const { coords, isLastKnown, lastKnownTimestamp } = useLocation();
|
||||||
|
|
||||||
const mapRef = useRef();
|
|
||||||
const cameraRef = useRef();
|
|
||||||
const [cameraKey, setCameraKey] = useState(1);
|
|
||||||
const [zoomLevel, setZoomLevel] = useState(DEFAULT_ZOOM_LEVEL);
|
|
||||||
const abortControllerRef = useRef(null);
|
|
||||||
|
|
||||||
const refreshCamera = useCallback(() => {
|
|
||||||
setCameraKey(`${Date.now()}`);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const hasUserCoords =
|
const hasUserCoords =
|
||||||
coords && coords.latitude !== null && coords.longitude !== null;
|
coords && coords.latitude !== null && coords.longitude !== null;
|
||||||
const hasDefibCoords = defib && defib.latitude && defib.longitude;
|
const hasDefibCoords = defib && defib.latitude && defib.longitude;
|
||||||
|
|
||||||
|
const userCoords = useMemo(
|
||||||
|
() =>
|
||||||
|
hasUserCoords
|
||||||
|
? { latitude: coords.latitude, longitude: coords.longitude }
|
||||||
|
: null,
|
||||||
|
[hasUserCoords, coords],
|
||||||
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
mapRef,
|
||||||
|
cameraRef,
|
||||||
|
setDetached,
|
||||||
|
followUserLocation,
|
||||||
|
followUserMode,
|
||||||
|
followPitch,
|
||||||
|
zoomLevel,
|
||||||
|
boundType,
|
||||||
|
setBoundType,
|
||||||
|
setZoomLevel,
|
||||||
|
detached,
|
||||||
|
cameraKey,
|
||||||
|
setCameraKey,
|
||||||
|
refreshCamera,
|
||||||
|
} = useMapInit({
|
||||||
|
initialBoundType: BoundType.NAVIGATION,
|
||||||
|
userCoords,
|
||||||
|
});
|
||||||
|
|
||||||
|
const abortControllerRef = useRef(null);
|
||||||
|
|
||||||
|
const onRegionDidChange = useCallback(
|
||||||
|
(event) => {
|
||||||
|
const { isUserInteraction } = event.properties;
|
||||||
|
if (isUserInteraction) {
|
||||||
|
setDetached(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[setDetached],
|
||||||
|
);
|
||||||
|
|
||||||
|
const [externalGeoIsVisible, setExternalGeoIsVisible] = useState(false);
|
||||||
|
|
||||||
const [routeCoords, setRouteCoords] = useState(null);
|
const [routeCoords, setRouteCoords] = useState(null);
|
||||||
const [routeError, setRouteError] = useState(null);
|
const [routeError, setRouteError] = useState(null);
|
||||||
const [loadingRoute, setLoadingRoute] = useState(false);
|
const [loadingRoute, setLoadingRoute] = useState(false);
|
||||||
|
|
@ -231,17 +268,6 @@ export default React.memo(function DAEItemCarte() {
|
||||||
};
|
};
|
||||||
}, [routeCoords]);
|
}, [routeCoords]);
|
||||||
|
|
||||||
// Camera bounds to show both user + defib
|
|
||||||
const bounds = useMemo(() => {
|
|
||||||
if (!hasUserCoords || !hasDefibCoords) return null;
|
|
||||||
const lats = [coords.latitude, defib.latitude];
|
|
||||||
const lons = [coords.longitude, defib.longitude];
|
|
||||||
return {
|
|
||||||
ne: [Math.max(...lons), Math.max(...lats)],
|
|
||||||
sw: [Math.min(...lons), Math.min(...lats)],
|
|
||||||
};
|
|
||||||
}, [hasUserCoords, hasDefibCoords, coords, defib]);
|
|
||||||
|
|
||||||
const profileDefaultMode = profileDefaultModes[profile];
|
const profileDefaultMode = profileDefaultModes[profile];
|
||||||
|
|
||||||
if (!defib) return null;
|
if (!defib) return null;
|
||||||
|
|
@ -324,6 +350,7 @@ export default React.memo(function DAEItemCarte() {
|
||||||
|
|
||||||
<MapView
|
<MapView
|
||||||
mapRef={mapRef}
|
mapRef={mapRef}
|
||||||
|
onRegionDidChange={onRegionDidChange}
|
||||||
compassViewPosition={1}
|
compassViewPosition={1}
|
||||||
compassViewMargin={{ x: 10, y: 10 }}
|
compassViewMargin={{ x: 10, y: 10 }}
|
||||||
>
|
>
|
||||||
|
|
@ -332,16 +359,11 @@ export default React.memo(function DAEItemCarte() {
|
||||||
setCameraKey={setCameraKey}
|
setCameraKey={setCameraKey}
|
||||||
refreshCamera={refreshCamera}
|
refreshCamera={refreshCamera}
|
||||||
cameraRef={cameraRef}
|
cameraRef={cameraRef}
|
||||||
followUserLocation={!bounds}
|
followUserLocation={followUserLocation}
|
||||||
followUserMode={
|
followUserMode={followUserMode}
|
||||||
bounds
|
followPitch={followPitch}
|
||||||
? Maplibre.UserTrackingMode.None
|
|
||||||
: Maplibre.UserTrackingMode.Follow
|
|
||||||
}
|
|
||||||
followPitch={0}
|
|
||||||
zoomLevel={zoomLevel}
|
zoomLevel={zoomLevel}
|
||||||
bounds={bounds}
|
detached={detached}
|
||||||
detached={false}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Route line */}
|
{/* Route line */}
|
||||||
|
|
@ -411,7 +433,40 @@ export default React.memo(function DAEItemCarte() {
|
||||||
</View>
|
</View>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
<StepZoomButtonGroup mapRef={mapRef} setZoomLevel={setZoomLevel} />
|
<View
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
bottom: 38,
|
||||||
|
left: 4,
|
||||||
|
borderRadius: 4,
|
||||||
|
overflow: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MapLinksPopupIconButton setIsVisible={setExternalGeoIsVisible} />
|
||||||
|
</View>
|
||||||
|
{(detached || boundType !== BoundType.NAVIGATION) && (
|
||||||
|
<TargetButton
|
||||||
|
userCoords={userCoords}
|
||||||
|
cameraRef={cameraRef}
|
||||||
|
boundType={boundType}
|
||||||
|
setBoundType={setBoundType}
|
||||||
|
refreshCamera={refreshCamera}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<ToggleColorSchemeButton containerStyle={{ left: 4, bottom: 75 }} />
|
||||||
|
<StepZoomButtonGroup
|
||||||
|
mapRef={mapRef}
|
||||||
|
cameraRef={cameraRef}
|
||||||
|
setZoomLevel={setZoomLevel}
|
||||||
|
/>
|
||||||
|
<MapLinksPopup
|
||||||
|
isVisible={externalGeoIsVisible}
|
||||||
|
setIsVisible={setExternalGeoIsVisible}
|
||||||
|
options={{
|
||||||
|
longitude: defib?.longitude,
|
||||||
|
latitude: defib?.latitude,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Route error */}
|
{/* Route error */}
|
||||||
{routeError && !loadingRoute && (
|
{routeError && !loadingRoute && (
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue