Skip to content

Commit

Permalink
Merge pull request sap-labs-france#579 from sap-labs-france/map
Browse files Browse the repository at this point in the history
Improved map
  • Loading branch information
LucasBrazi06 authored Dec 6, 2021
2 parents 953a70d + bb4033e commit c4f7928
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/components/map/ClusterMap.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import MapView from 'react-native-map-clustering';
import MapCluster from './cluster/MapCluster';
import ClusterComponent from './cluster/ClusterComponent';
import { Region } from 'react-native-maps';
import ChargingStation from '../../types/ChargingStation';
import Site from '../../types/Site';
Expand Down Expand Up @@ -48,11 +48,11 @@ export default class ClusterMap<T extends Localizable> extends React.Component<P
showsCompass={false}
showsUserLocation={true}
zoomControlEnabled={false}
radius={this.computeRadius(initialRegion.latitudeDelta)}
toolbarEnabled={false}
spiralEnabled={true}
radius={5}
tracksViewChanges={false}
renderCluster={(cluster) => <MapCluster cluster={cluster} />}
renderCluster={(cluster) => <ClusterComponent key={cluster.id} cluster={cluster} />}
spiderLineColor={commonColors.textColor}
mapType={satelliteMap ? 'satellite' : 'standard'}
initialRegion={initialRegion}
Expand All @@ -66,4 +66,13 @@ export default class ClusterMap<T extends Localizable> extends React.Component<P
</View>
)
}

private computeRadius(latitudeDelta: number): number {
if(latitudeDelta <= 0.0005) {
return 5
} else if(latitudeDelta <= 0.001 ) {
return 20
}
return 30
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import React from 'react';
import { Marker } from 'react-native-maps';
import { View } from 'native-base';
import { Text } from 'react-native';
import computeStyleSheet from './MapClusterStyle';
import computeStyleSheet from './ClusterComponentStyle';

export interface Props {
cluster: any;
}

interface State {}

export default class MapCluster extends React.Component<Props, State> {
export default class ClusterComponent extends React.Component<Props, State> {

public render() {
const style = computeStyleSheet();
const { geometry, onPress, id, properties } = this.props?.cluster;
return (
<Marker onPress={onPress} tracksViewChanges={false} key={id} coordinate={{longitude: geometry.coordinates[0], latitude: geometry.coordinates[1]}}>
<View style={style.cluster}><Text>{properties?.point_count}</Text></View>
<View style={style.cluster}><Text style={style.text}>{properties?.point_count}</Text></View>
</Marker>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
borderWidth: 2,
borderColor: commonColor.mapClusterBorder,
zIndex: 1
},
text: {
fontSize: '15@s',
color: commonColor.textColor
}
});
const portraitStyles = {};
Expand Down
2 changes: 1 addition & 1 deletion src/provider/CentralServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export default class CentralServerProvider {
headers: this.buildSecuredHeaders(),
params
});
return result.data;
return result?.data;
}

public async saveUserMobileToken(params: { id: string; mobileToken: string; mobileOS: string }): Promise<ActionResponse> {
Expand Down
4 changes: 2 additions & 2 deletions src/screens/charging-stations/list/ChargingStations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Container, Icon, Spinner, View } from 'native-base';
import React from 'react';
import {
BackHandler, Image, ImageStyle,
NativeEventSubscription,
Platform,
ScrollView, TouchableOpacity,
} from 'react-native';
Expand Down Expand Up @@ -475,7 +474,8 @@ export default class ChargingStations extends BaseAutoRefreshScreen<Props, State
satelliteMap={satelliteMap}
renderMarker={(chargingStation, index) => (
<Marker
key={`${chargingStation.id}${index}${chargingStation.chargingStationURL}`}
key={chargingStation.id}
identifier={chargingStation.id}
tracksViewChanges={false}
coordinate={{ longitude: chargingStation.coordinates[0], latitude: chargingStation.coordinates[1] }}
title={chargingStation.id}
Expand Down

0 comments on commit c4f7928

Please sign in to comment.