Supporting multiple tracks.
This commit is contained in:
parent
0c615ee00c
commit
a212841c6c
File diff suppressed because it is too large
Load Diff
|
@ -20,6 +20,7 @@ import {
|
||||||
|
|
||||||
import GpxImport from './gpx-import';
|
import GpxImport from './gpx-import';
|
||||||
import Track from './track';
|
import Track from './track';
|
||||||
|
import Tracks from './tracks';
|
||||||
|
|
||||||
const Map: react.FC<{}> = (props: {}) => {
|
const Map: react.FC<{}> = (props: {}) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
@ -44,7 +45,7 @@ const Map: react.FC<{}> = (props: {}) => {
|
||||||
<Slippy>
|
<Slippy>
|
||||||
<Whiteboard>
|
<Whiteboard>
|
||||||
<CurrentLocation />
|
<CurrentLocation />
|
||||||
<Track />
|
<Tracks />
|
||||||
</Whiteboard>
|
</Whiteboard>
|
||||||
</Slippy>
|
</Slippy>
|
||||||
<Layer>
|
<Layer>
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
import React, { Fragment } from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { useSelector } from 'react-redux';
|
|
||||||
import { lat2tile, lon2tile } from '../../lib/geo';
|
import { lat2tile, lon2tile } from '../../lib/geo';
|
||||||
import { zoom0 } from '../../store/map';
|
import { zoom0 } from '../../store/map';
|
||||||
|
|
||||||
const Track: React.FC<{}> = () => {
|
const Track: React.FC<{ track: any }> = (props) => {
|
||||||
const track = useSelector((state: { tracks: any }) => state.tracks.tracks.$0);
|
const trkseg = props.track.trk[0].trkseg[0];
|
||||||
|
|
||||||
if (track) {
|
|
||||||
const trkseg = track.trk[0].trkseg[0];
|
|
||||||
|
|
||||||
const d = trkseg.trkpt.reduce(
|
const d = trkseg.trkpt.reduce(
|
||||||
(previous: string, current: any, index: number) => {
|
(previous: string, current: any, index: number) => {
|
||||||
|
@ -21,10 +17,7 @@ const Track: React.FC<{}> = () => {
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
return <path d={d} className='track'/>;
|
return <path d={d} className='track' />;
|
||||||
}
|
|
||||||
|
|
||||||
return <Fragment />;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Track;
|
export default Track;
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import React, { Fragment, useEffect } from 'react';
|
||||||
|
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
|
|
||||||
|
import { Drivers, Storage } from '@ionic/storage';
|
||||||
|
import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';
|
||||||
|
|
||||||
|
import Track from './track';
|
||||||
|
|
||||||
|
var store: Storage;
|
||||||
|
|
||||||
|
const Tracks: React.FC<{}> = () => {
|
||||||
|
useEffect(() => {
|
||||||
|
store = new Storage({
|
||||||
|
driverOrder: [
|
||||||
|
CordovaSQLiteDriver._driver,
|
||||||
|
Drivers.IndexedDB,
|
||||||
|
Drivers.LocalStorage,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
store
|
||||||
|
.defineDriver(CordovaSQLiteDriver)
|
||||||
|
.then(() => console.log('CordovaSQLiteDriver registered'));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const tracks = useSelector((state: { tracks: any }) => state.tracks.tracks);
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
{Object.keys(tracks).map((key: any) => (
|
||||||
|
<Track key={key} track={tracks[key]} />
|
||||||
|
))}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Tracks;
|
|
@ -10,7 +10,7 @@ import {
|
||||||
tile2long,
|
tile2long,
|
||||||
} from '../lib/geo';
|
} from '../lib/geo';
|
||||||
|
|
||||||
export const zoom0 = 10;
|
export const zoom0 = 18;
|
||||||
|
|
||||||
// Top level properties (the other properties can be derived from them)
|
// Top level properties (the other properties can be derived from them)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ ion-button.get-location {
|
||||||
|
|
||||||
.track {
|
.track {
|
||||||
fill: transparent;
|
fill: transparent;
|
||||||
stroke-width: 2px;
|
stroke-width: 4px;
|
||||||
stroke: green;
|
stroke: green;
|
||||||
vector-effect: non-scaling-stroke;
|
vector-effect: non-scaling-stroke;
|
||||||
}
|
}
|
Loading…
Reference in New Issue