Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 22 additions & 31 deletions src/views/Map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useLayoutEffect } from 'react';
import React, {useEffect, useState, useLayoutEffect } from 'react';
import MapView, { Circle, PROVIDER_GOOGLE, } from 'react-native-maps';
import Constants from 'expo-constants';
import { Text, Container, View, Icon } from 'native-base';
Expand All @@ -8,7 +8,6 @@ import { User, WeatherContainer, LightBeacon, NavigationLine, NauticalWarning, D
import { digiTrafficService, firebaseService, finnshTransportService } from '../services';
import { Distance } from '../utilities';
import { mapStyles } from '../styles';
import Speedometer from 'react-native-speedometer-chart';

const apiURL = 'https://pfa.foreca.com';

Expand Down Expand Up @@ -65,8 +64,8 @@ const Map = ({ navigation }) => {
const proximityAlert = Distance.isDistanceLessThen(updateVessel,
lastLatitude, lastLongitude, alertRadius);

if (proximityAlert) {
if (!vesselsInProximity.some(vesselInProximity => vesselInProximity.id === updateVessel.id)) {
if ( proximityAlert ){
if ( !vesselsInProximity.some( vesselInProximity => vesselInProximity.id === updateVessel.id) ) {
setVesselsInProximity([...vesselsInProximity, updateVessel]);
}
} else {
Expand Down Expand Up @@ -131,13 +130,13 @@ const Map = ({ navigation }) => {
})
}

const updateLightBeacons = (latestLatitude, latestLongitude) => {
finnshTransportService.updateLightBeacons(latestLongitude, latestLatitude)
.then(lightBeacons => {
if (lightBeacons && lightBeacons.length > 0) {
setLightBeacons(lightBeacons);
}
})
const updateLightBeacons = (latestLatitude, latestLongitude) => {
finnshTransportService.updateLightBeacons(latestLongitude,latestLatitude)
.then( lightBeacons => {
if ( lightBeacons && lightBeacons.length > 0 ){
setLightBeacons(lightBeacons);
}
})
}

const updateSurroundingDigiTrafficVessels = (latestLatitude, latestLongitude) => {
Expand Down Expand Up @@ -212,7 +211,7 @@ const Map = ({ navigation }) => {
<TouchableHighlight
activeOpacity={0.6}
underlayColor='#ffc13b'
style={{ margin: 10, padding: 5 }}
style={{ margin: 10, padding: 5}}
onPress={() => { toggleSwitch() }}>
<View style={{ flex: 1, flexDirection: 'row' }}>
<Text style={{ marginRight: 5, marginTop: 2, fontSize: 20 }}>Mode</Text>
Expand Down Expand Up @@ -247,8 +246,8 @@ const Map = ({ navigation }) => {
}
}, [isLocationUpdateFirstTime]);

useEffect(() => {
if (isVesselsFirstLoad) {
useEffect( () => {
if ( isVesselsFirstLoad ){
const vesselsInProximity = vessels.filter(vessel => {
return Distance.isDistanceLessThen(vessel, lastLatitude,
lastLongitude, alertRadius);
Expand All @@ -260,7 +259,7 @@ const Map = ({ navigation }) => {
}, [isVesselsFirstLoad]);

useEffect(() => {
if (vesselsInProximity.length > 0) {
if ( vesselsInProximity.length > 0 ){
setIsCollisionDetected(true);
} else {
setIsCollisionDetected(false);
Expand Down Expand Up @@ -296,7 +295,7 @@ const Map = ({ navigation }) => {
/>

<OtherUsers
vessels={vessels}
vessels={vessels}
/>

<LightBeacon
Expand Down Expand Up @@ -326,25 +325,17 @@ const Map = ({ navigation }) => {
radius={alertRadius * 1000}
fillColor={'rgba(255, 0, 0, 0.2)'}
strokeColor="rgba(0,0,0,0.5)"
/>}
/> }

</MapView>
{/* TODO move following code to new component SpeedMeter*/}
<View style={styles.speedContainer}>
<Speedometer
value={(lastSpeed * METER_TO_KNOT_CONSTANT).toFixed(3)}
totalValue={35}
size={150}
outerColor="#ff6e40"
internalColor="#ffc13b"
showText
text={(lastSpeed * METER_TO_KILOMETER_CONSTANT).toFixed(3)}
textStyle={{ color: '#1e3d59' }}
showLabels
labelStyle={{ color: '#ff6e40' }}
labelFormatter={number => `${ number } knot`}
percentStyle={{ color: '#ff6e40' }}
/>
<Text style={styles.bubble}>
{(lastSpeed * METER_TO_KILOMETER_CONSTANT).toFixed(1)} Km/h
</Text>
<Text style={styles.bubble}>
{(lastSpeed * METER_TO_KNOT_CONSTANT).toFixed(1)} Knots
</Text>
</View>
</View>
</Container>
Expand Down