Skip to content

Commit

Permalink
refactor(location overview): use ownPositionMarker for own position…
Browse files Browse the repository at this point in the history
… on map

SVA-298
  • Loading branch information
donni106 committed Oct 25, 2021
1 parent cc0b035 commit 2a479f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/components/map/LocationOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { LocationObject } from 'expo-location';
import React, { useCallback, useContext, useState } from 'react';
import { useQuery } from 'react-apollo';
import { ActivityIndicator, ScrollView, View } from 'react-native';
import { MapMarker, WebviewLeafletMessage } from 'react-native-webview-leaflet';
import {
AnimationType,
INFINITE_ANIMATION_ITERATIONS,
MapMarker,
WebviewLeafletMessage
} from 'react-native-webview-leaflet';

import { colors, texts } from '../../config';
import { graphqlFetchPolicy } from '../../helpers';
Expand Down Expand Up @@ -98,15 +103,20 @@ export const LocationOverview = ({

const mapMarkers = mapToMapMarkers(overviewData);

position &&
mapMarkers?.push({
icon: ownLocation(colors.accent),
iconAnchor: ownLocationIconAnchor,
position: {
lat: position.coords.latitude,
lng: position.coords.longitude
}
});
const ownPositionMarker = position && {
icon: ownLocation(colors.accent),
size: ownLocationIconAnchor,
position: {
lat: position.coords.latitude,
lng: position.coords.longitude
},
animation: {
type: AnimationType.BOUNCE,
duration: 1,
delay: 0,
iterationCount: INFINITE_ANIMATION_ITERATIONS
}
};

if (!mapMarkers?.length) {
return (
Expand All @@ -120,7 +130,11 @@ export const LocationOverview = ({
<SafeAreaViewFlex>
<ScrollView>
<WrapperWithOrientation>
<WebViewMap locations={mapMarkers} onMessageReceived={onMessageReceived} />
<WebViewMap
locations={mapMarkers}
ownPositionMarker={ownPositionMarker}
onMessageReceived={onMessageReceived}
/>
<View>
{!selectedPointOfInterest && (
<Wrapper>
Expand Down
4 changes: 4 additions & 0 deletions src/components/map/WebViewMap.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { useCallback } from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
import { MapMarker, WebViewLeaflet, WebviewLeafletMessage } from 'react-native-webview-leaflet';
import { OwnPositionMarker } from 'react-native-webview-leaflet/models';

import { colors } from '../../config';
import { imageHeight, imageWidth } from '../../helpers';

type Props = {
locations?: MapMarker[];
ownPositionMarker?: OwnPositionMarker;
mapCenterPosition?: {
lat: number;
lng: number;
Expand All @@ -18,6 +20,7 @@ type Props = {

export const WebViewMap = ({
locations,
ownPositionMarker,
mapCenterPosition,
onMessageReceived,
style,
Expand All @@ -44,6 +47,7 @@ export const WebViewMap = ({
}
]}
mapMarkers={locations}
ownPositionMarker={ownPositionMarker}
mapCenterPosition={mapCenterPosition ?? locations?.[0]?.position}
zoom={zoom}
/>
Expand Down

0 comments on commit 2a479f1

Please sign in to comment.