This commit is contained in:
Ren Juan 2021-08-20 08:41:16 +00:00
parent 5ebbf6bc20
commit 16b5d0d30d
8 changed files with 46 additions and 117 deletions

View File

@ -1,16 +1,15 @@
import 'react-native-gesture-handler'; import 'react-native-gesture-handler';
import { StatusBar } from 'expo-status-bar'; import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Platform, Text, View, Switch, StyleSheet } from 'react-native'; import { Text } from 'react-native';
import * as Location from 'expo-location'; import * as Location from 'expo-location';
import { SafeAreaProvider } from 'react-native-safe-area-context'; import { SafeAreaProvider } from 'react-native-safe-area-context';
import useCachedResources from './hooks/useCachedResources'; import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme'; import useColorScheme from './hooks/useColorScheme';
import Navigation from './navigation'; import Navigation from './navigation';
import { GT2 } from './GT2';
export var debug:boolean = false; export var debug:boolean = true;
export var expoGeoState:any; export var expoGeoState:any;
export var tripInProgress:boolean = true;
export default function App() { export default function App() {
const isLoadingComplete = useCachedResources(); const isLoadingComplete = useCachedResources();
@ -60,5 +59,3 @@ export default function App() {
); );
} }
} }
export function toggleTripInProgress() {tripInProgress = !tripInProgress;}

View File

@ -1,77 +1,27 @@
/** Class for handling coordinates original by Linus Helgesson */
export class Coordinate {
mLatitude:number = 0.0;
mLongitude:number = 0.0;
mResults:any = [0, 0];
PI_OVER_180:number = 0.017453292519943295769236907684886;
EARTH_RADIUS:number = 6371009;
/* Generated from Java with JSweet 3.0.0 - http://www.jsweet.org */ constructor (longitude:number, latitude:number) {
/**
* Constructor taking a longitude and a latitude
*
* @param {number} longitude
* @param {number} latitude
* @class
* @author Linus Helgesson
*/
var Coordinate = /** @class */ (function () {
function Coordinate(longitude, latitude) {
if (((typeof longitude === 'number') || longitude === null) && ((typeof latitude === 'number') || latitude === null)) {
var __args = arguments;
this.mLongitude = 0;
this.mLatitude = 0;
this.mResults = [0, 0];
this.mLongitude = longitude; this.mLongitude = longitude;
this.mLatitude = latitude; this.mLatitude = latitude;
}
else if (longitude === undefined && latitude === undefined) {
var __args = arguments;
this.mLongitude = 0;
this.mLatitude = 0;
this.mResults = [0, 0];
}
else
throw new Error('invalid overload');
} }
getLongitude() { return this.mLongitude; }
setLongitude(longitude:number) { this.mLongitude = longitude; }
getLatitude() { return this.mLatitude; }
setLatitude(latitude:number) { this.mLatitude = latitude; }
/** /**
* Get the longitude part of this coordinate * Calculates a bounding box of a certain size arund a coordinate.This function takes a size in meters as
*
* @return {number} The longitude part of this coordinate
*/
Coordinate.prototype.getLongitude = function () {
return this.mLongitude;
};
/**
* Set the longitude part of this coordinate
*
* @param {number} longitude The longitude part of this coordinate
*/
Coordinate.prototype.setLongitude = function (longitude) {
this.mLongitude = longitude;
};
/**
* Get the latitude part of this coordinate
*
* @return {number} The latitude part of this coordinate
*/
Coordinate.prototype.getLatitude = function () {
return this.mLatitude;
};
/**
* Set the latitude part of this coordinate
*
* @param {number} latitude The latitude part of this coordinate
*/
Coordinate.prototype.setLatitude = function (latitude) {
this.mLatitude = latitude;
};
/**
* Calculates a bounding box of a certain size arund a coordinate. This is mainly used for a quick check
* in the database for cameras that are close to a coordinate. This function takes a size ion meters as
* a parameter and returns an array of two Coordinate objects. The first Coordinate is the upper left corner * a parameter and returns an array of two Coordinate objects. The first Coordinate is the upper left corner
* while the last coordinate is the bottom right corner. * while the last coordinate is the bottom right corner.er than the second.
*
* @param {number} side The length of the square side in meters
*
* @return {Coordinate[]} Two cordinates where the first is smaller than the second.
*/ */
Coordinate.prototype.getBoundingBox = function (side: number) { getBoundingBox(side: number) {
var ret = [null, null]; var ret:any = [Coordinate, Coordinate];
var degLatM:number , degLatM:number, degLongM:number, deltaLat:number, deltaLong:number; var degLatM:number , degLatM:number, degLongM:number, deltaLat:number, deltaLong:number;
@ -87,18 +37,12 @@
}; };
/** /**
* Calculates the distance between two Coordinate objects using the Spherical law of cosines found at: * Calculates the distance between two Coordinate objects using the Spherical law of cosines found at:
*
* http://www.movable-type.co.uk/scripts/latlong.html
*
* @param coordinate The coordinate to measure the distance to.
* @return {number} the distance in meters
* @param {Coordinate} dest
*/ */
Coordinate.prototype.distanceTo = function (dest) { distanceTo(dest:Coordinate) {
Coordinate.computeDistanceAndBearing(this.mLatitude, this.mLongitude, dest.getLatitude(), dest.getLongitude(), this.mResults); this.computeDistanceAndBearing(this.mLatitude, this.mLongitude, dest.getLatitude(), dest.getLongitude(), this.mResults);
return this.mResults[0]; return this.mResults[0];
}; };
/*private*/ Coordinate.computeDistanceAndBearing = function (lat1, lon1, lat2, lon2, results) { computeDistanceAndBearing(lat1:number, lon1:number, lat2:number, lon2:number, results:any) {
var MAXITERS = 20; var MAXITERS = 20;
lat1 *= Math.PI / 180.0; lat1 *= Math.PI / 180.0;
lat2 *= Math.PI / 180.0; lat2 *= Math.PI / 180.0;
@ -168,8 +112,8 @@
} }
} }
}; };
Coordinate.PI_OVER_180 = 0.017453292;
Coordinate.EARTH_RADIUS = 6371009; }
return Coordinate;
}());
Coordinate["__class"] = "Coordinate";

View File

@ -1,8 +1,8 @@
{ {
"expo": { "expo": {
"name": "Ejectable", "name": "Green Travel Carbon Calculator",
"slug": "Ejectable", "slug": "Ejectable",
"version": "1.0.0", "version": "2.0.0",
"orientation": "portrait", "orientation": "portrait",
"icon": "./assets/images/icon.png", "icon": "./assets/images/icon.png",
"scheme": "myapp", "scheme": "myapp",

View File

@ -70,7 +70,7 @@ function SplashNavigator() {
); );
} }
const TripStack = createStackNavigator<TripParamList>(); export const TripStack = createStackNavigator<TripParamList>();
function TripNavigator() { function TripNavigator() {
return ( return (

View File

@ -14,17 +14,17 @@ export default {
screens: { screens: {
Splash: { Splash: {
screens: { screens: {
SplashScreen: 'one', SplashScreen: 'home',
}, },
}, },
Trip: { Trip: {
screens: { screens: {
TripScreen: 'two', TripScreen: 'trip',
}, },
}, },
Settings: { Settings: {
screens: { screens: {
SettingsScreen: 'three', SettingsScreen: 'settings',
}, },
}, },
}, },

View File

@ -13006,9 +13006,9 @@
} }
}, },
"react-devtools-core": { "react-devtools-core": {
"version": "4.15.0", "version": "4.16.0",
"resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-4.15.0.tgz", "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-4.16.0.tgz",
"integrity": "sha512-Y1NwrWSKRg4TtwcES2upzXFDmccAW9jrGQG2D8EGQrZhK+0hmuhgFnSdKpFc3z04CSeDT5t83RMXcmX5TkR1dA==", "integrity": "sha512-fqyVbp+wVVey6O4uVBk5s3J/vTiPludp7lulr6a8asTBm7DIA0vLBbjmAOLCnOlkWcgdy4mjsqOgNCbu8uICWw==",
"requires": { "requires": {
"shell-quote": "^1.6.1", "shell-quote": "^1.6.1",
"ws": "^7" "ws": "^7"

View File

@ -1,14 +1,9 @@
import * as React from 'react'; import * as React from 'react';
import { Component } from 'react';
import { Button, StyleSheet, Alert } from 'react-native'; import { Button, StyleSheet, Alert } from 'react-native';
import { Text, View } from '../components/Themed'; import { Text, View } from '../components/Themed';
import { ScreenInfo2 } from '../components/ScreenInfo'; import { ScreenInfo2 } from '../components/ScreenInfo';
import { geocodeAsync } from 'expo-location'; import { thisTrip } from '../GT2';
import * as GT2 from '../App'; import { TripStack } from '../navigation/BottomTabNavigator';
import * as Nav from '../navigation/BottomTabNavigator';
import Navigation from '../navigation';
var elapsed:number, lat:number, long:number, ds:number, v:number;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
tripText: { tripText: {
@ -43,16 +38,8 @@ const styles = StyleSheet.create({
function startTrip() { function startTrip() {
GT2.toggleTripInProgress(); thisTrip.start();
elapsed = 0.0;
lat = 0.0;
long = 0.0;
ds = 0.0;
v = 0.0;
Alert.alert('Trip Started'); Alert.alert('Trip Started');
} }
@ -63,13 +50,14 @@ function pauseTrip() {
function endTrip() { function endTrip() {
GT2.toggleTripInProgress(); thisTrip.end();
Alert.alert('Trip Ended'); Alert.alert('Trip Ended');
} }
export default function TripScreen() { export default function TripScreen() {
if (!GT2.tripInProgress)
if (!thisTrip.inProgress)
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.title}>Trip Control</Text> <Text style={styles.title}>Trip Control</Text>
@ -112,9 +100,9 @@ export default function TripScreen() {
</View> </View>
<View> <View>
<Text style={styles.tripText}> <Text style={styles.tripText}>
{'Elapsed: '}{elapsed}{'\n'} {'Elapsed - '}{thisTrip.elapsed}{' seconds\n'}
{'Geo: '}{lat}{long}{'\n'} {'Geo: '}{'lat: '}{thisTrip.loc.mLatitude}{' long: '}{thisTrip.loc.mLatitude}{'\n'}
{'Vector: '}{ds}{v}{'\n'} {'Vector: '}{'distance: '}{thisTrip.distance}{' velocity: '}{thisTrip.v}{'\n'}
</Text> </Text>
</View> </View>
</View> </View>

View File

@ -1,4 +1,4 @@
{ {
"extends": "expo/tsconfig.base", "extends": "expo/tsconfig.base",
"compilerOptions": { "compilerOptions": {
"strict": true "strict": true