Accepting GPX from osmand.
This commit is contained in:
parent
fcaa3b95a0
commit
38a6230565
|
@ -33,6 +33,12 @@
|
||||||
<data android:scheme="geo" />
|
<data android:scheme="geo" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="application/gpx+xml" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION"/>
|
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"@capacitor/android": "^4.6.1",
|
"@capacitor/android": "^4.6.1",
|
||||||
"@capacitor/browser": "^4.1.0",
|
"@capacitor/browser": "^4.1.0",
|
||||||
"@capacitor/core": "^4.6.1",
|
"@capacitor/core": "^4.6.1",
|
||||||
|
"@capacitor/filesystem": "^4.1.4",
|
||||||
"@capacitor/ios": "^4.6.1",
|
"@capacitor/ios": "^4.6.1",
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
||||||
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
||||||
|
@ -678,6 +679,14 @@
|
||||||
"tslib": "^2.1.0"
|
"tslib": "^2.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@capacitor/filesystem": {
|
||||||
|
"version": "4.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@capacitor/filesystem/-/filesystem-4.1.4.tgz",
|
||||||
|
"integrity": "sha512-ivko1RNK4hq63xhMacq8D6D97N5/SAafTsrmY/pghYrG6Cl2SEY0+IgRu7V9/VWeN3FSplyUPucjUTAFQxXN5g==",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@capacitor/core": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@capacitor/ios": {
|
"node_modules/@capacitor/ios": {
|
||||||
"version": "4.6.1",
|
"version": "4.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-4.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-4.6.1.tgz",
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
"@capacitor/android": "^4.6.1",
|
"@capacitor/android": "^4.6.1",
|
||||||
"@capacitor/browser": "^4.1.0",
|
"@capacitor/browser": "^4.1.0",
|
||||||
"@capacitor/core": "^4.6.1",
|
"@capacitor/core": "^4.6.1",
|
||||||
|
"@capacitor/filesystem": "^4.1.4",
|
||||||
"@capacitor/ios": "^4.6.1",
|
"@capacitor/ios": "^4.6.1",
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
||||||
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
||||||
|
|
|
@ -10,9 +10,13 @@ import { useI18n } from '@solid-primitives/i18n';
|
||||||
import { Box } from '@suid/material';
|
import { Box } from '@suid/material';
|
||||||
import GpxImportSingleFile from './GpxImportSingleFile';
|
import GpxImportSingleFile from './GpxImportSingleFile';
|
||||||
|
|
||||||
const GpxImport: Component = () => {
|
const [filesToImport, setFilesToImport] = createSignal<FileList | string[]>();
|
||||||
const [filesToImport, setFilesToImport] = createSignal<FileList>();
|
|
||||||
|
|
||||||
|
export const importUrls = (urls: string[]) => {
|
||||||
|
setFilesToImport(urls);
|
||||||
|
};
|
||||||
|
|
||||||
|
const GpxImport: Component = () => {
|
||||||
const [t] = useI18n();
|
const [t] = useI18n();
|
||||||
|
|
||||||
const onChangeHandler = (event: any) => {
|
const onChangeHandler = (event: any) => {
|
||||||
|
|
|
@ -15,6 +15,10 @@ import GPX from '../../lib/gpx-parser-builder/src/gpx';
|
||||||
import dispatch from '../../workers/dispatcher-main';
|
import dispatch from '../../workers/dispatcher-main';
|
||||||
import GpxChooser from '../gpx-chooser';
|
import GpxChooser from '../gpx-chooser';
|
||||||
import { currentGpxId } from '../gpx-dialog';
|
import { currentGpxId } from '../gpx-dialog';
|
||||||
|
import {
|
||||||
|
Filesystem as CapacitorFileSystem,
|
||||||
|
Encoding,
|
||||||
|
} from '@capacitor/filesystem';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
gpxFile: File;
|
gpxFile: File;
|
||||||
|
@ -55,9 +59,33 @@ const GpxImportSingleFile: Component<Props> = ({ gpxFile }) => {
|
||||||
setGpxId(currentGpxId());
|
setGpxId(currentGpxId());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const parseGpx = (content: string) => {
|
||||||
|
const gpx = GPX.parse(content);
|
||||||
|
console.log({ caller: 'GpxImportSingleFile / JSON', gpxFile, gpx });
|
||||||
|
setStatsAndGpx({ gpx, stats: analyzeGpx(gpx) });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof gpxFile === 'string') {
|
||||||
|
CapacitorFileSystem.requestPermissions().then((permissionStatus) => {
|
||||||
|
console.log({
|
||||||
|
caller: 'GpxImportSingleFile / content',
|
||||||
|
permissionStatus,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
CapacitorFileSystem.readFile({
|
||||||
|
path: gpxFile,
|
||||||
|
encoding: Encoding.UTF8,
|
||||||
|
}).then((content) => {
|
||||||
|
console.log({
|
||||||
|
caller: 'GpxImportSingleFile / content',
|
||||||
|
gpxFile,
|
||||||
|
content,
|
||||||
|
});
|
||||||
|
parseGpx(content.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
const gpxReader = new FileReader();
|
const gpxReader = new FileReader();
|
||||||
gpxReader.readAsText(gpxFile);
|
gpxReader.readAsText(gpxFile);
|
||||||
|
|
||||||
gpxReader.addEventListener(
|
gpxReader.addEventListener(
|
||||||
'load',
|
'load',
|
||||||
async () => {
|
async () => {
|
||||||
|
@ -67,16 +95,11 @@ const GpxImportSingleFile: Component<Props> = ({ gpxFile }) => {
|
||||||
gpxFile,
|
gpxFile,
|
||||||
result: gpxReader.result,
|
result: gpxReader.result,
|
||||||
});
|
});
|
||||||
const gpx = GPX.parse(gpxReader.result);
|
parseGpx(gpxReader.result);
|
||||||
console.log({ caller: 'GpxImportSingleFile / JSON', gpxFile, gpx });
|
|
||||||
setStatsAndGpx({ gpx, stats: analyzeGpx(gpx) });
|
|
||||||
// if (gpx) {
|
|
||||||
// const startTime = new Date(findStartTime(gpx)!);
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
}
|
||||||
const doImport = async () => {
|
const doImport = async () => {
|
||||||
setState('importing');
|
setState('importing');
|
||||||
// console.log({ caller: 'GpxImport / JSON', file, gpx });
|
// console.log({ caller: 'GpxImport / JSON', file, gpx });
|
||||||
|
@ -87,7 +110,13 @@ const GpxImportSingleFile: Component<Props> = ({ gpxFile }) => {
|
||||||
params: {
|
params: {
|
||||||
id: gpxId(),
|
id: gpxId(),
|
||||||
gpx: statsAndGpx()?.gpx,
|
gpx: statsAndGpx()?.gpx,
|
||||||
tech: {
|
tech:
|
||||||
|
typeof gpxFile === 'string'
|
||||||
|
? {
|
||||||
|
importDate: new Date().toISOString(),
|
||||||
|
uri: gpxFile,
|
||||||
|
}
|
||||||
|
: {
|
||||||
lastModified: new Date(gpxFile.lastModified).toISOString(),
|
lastModified: new Date(gpxFile.lastModified).toISOString(),
|
||||||
importDate: new Date().toISOString(),
|
importDate: new Date().toISOString(),
|
||||||
name: gpxFile.name,
|
name: gpxFile.name,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export { default } from './GpxImport';
|
export { default, importUrls } from './GpxImport';
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { Style, Icon } from 'ol/style';
|
||||||
import GetLocation, { getCurrentLocation } from '../get-location';
|
import GetLocation, { getCurrentLocation } from '../get-location';
|
||||||
import ShowLocationIcon from '../get-location/ShowLocationIcon.svg';
|
import ShowLocationIcon from '../get-location/ShowLocationIcon.svg';
|
||||||
import { Back, Forward } from '../back-forward';
|
import { Back, Forward } from '../back-forward';
|
||||||
import GpxImport from '../gpx-import';
|
import GpxImport, { importUrls } from '../gpx-import';
|
||||||
import AllGpxes from '../all-gpxes';
|
import AllGpxes from '../all-gpxes';
|
||||||
import MapTileProvider, { mapTileProviders } from '../map-tile-provider';
|
import MapTileProvider, { mapTileProviders } from '../map-tile-provider';
|
||||||
import Interaction from 'ol/interaction/Interaction';
|
import Interaction from 'ol/interaction/Interaction';
|
||||||
|
@ -78,7 +78,10 @@ const Map: Component = () => {
|
||||||
if (window.plugins) {
|
if (window.plugins) {
|
||||||
window.plugins.intentShim.registerBroadcastReceiver(
|
window.plugins.intentShim.registerBroadcastReceiver(
|
||||||
{
|
{
|
||||||
filterActions: ['android.intent.action.VIEW'],
|
filterActions: [
|
||||||
|
'android.intent.action.VIEW',
|
||||||
|
'android.intent.action.SEND',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
function (intent: any) {
|
function (intent: any) {
|
||||||
console.log({
|
console.log({
|
||||||
|
@ -89,11 +92,16 @@ const Map: Component = () => {
|
||||||
);
|
);
|
||||||
window.plugins.intentShim.onIntent(function (intent: any) {
|
window.plugins.intentShim.onIntent(function (intent: any) {
|
||||||
console.log({ caller: 'Intent receiver', intent });
|
console.log({ caller: 'Intent receiver', intent });
|
||||||
|
if (intent.action === 'android.intent.action.VIEW') {
|
||||||
const url = new URL(intent.data);
|
const url = new URL(intent.data);
|
||||||
const q = url.search;
|
const q = url.search;
|
||||||
const [, lat, lon] = q.match(/q=([0-9.-]+),([0-9.-]+)/);
|
const [, lat, lon] = q.match(/q=([0-9.-]+),([0-9.-]+)/);
|
||||||
console.log({ caller: 'Intent receiver', intent, url, lat, lon });
|
console.log({ caller: 'Intent receiver', intent, url, lat, lon });
|
||||||
findLocation(navigate, [lon, lat]);
|
findLocation(navigate, [lon, lat]);
|
||||||
|
} else if (intent.action === 'android.intent.action.SEND') {
|
||||||
|
const uri = intent.extras['android.intent.extra.STREAM'];
|
||||||
|
importUrls([uri]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log({
|
console.log({
|
||||||
|
|
Loading…
Reference in New Issue