Accepting GPX from osmand.

This commit is contained in:
Eric van der Vlist 2023-02-04 18:22:05 +01:00
parent fcaa3b95a0
commit 38a6230565
7 changed files with 93 additions and 36 deletions

View File

@ -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"/>

9
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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) => {

View File

@ -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,28 +59,47 @@ const GpxImportSingleFile: Component<Props> = ({ gpxFile }) => {
setGpxId(currentGpxId()); setGpxId(currentGpxId());
}); });
const gpxReader = new FileReader(); const parseGpx = (content: string) => {
gpxReader.readAsText(gpxFile); const gpx = GPX.parse(content);
console.log({ caller: 'GpxImportSingleFile / JSON', gpxFile, gpx });
setStatsAndGpx({ gpx, stats: analyzeGpx(gpx) });
};
gpxReader.addEventListener( if (typeof gpxFile === 'string') {
'load', CapacitorFileSystem.requestPermissions().then((permissionStatus) => {
async () => {
// this will then display a text gpxfile
console.log({ console.log({
caller: 'GpxImportSingleFile / XML', caller: 'GpxImportSingleFile / content',
gpxFile, permissionStatus,
result: gpxReader.result,
}); });
const gpx = GPX.parse(gpxReader.result); });
console.log({ caller: 'GpxImportSingleFile / JSON', gpxFile, gpx }); CapacitorFileSystem.readFile({
setStatsAndGpx({ gpx, stats: analyzeGpx(gpx) }); path: gpxFile,
// if (gpx) { encoding: Encoding.UTF8,
// const startTime = new Date(findStartTime(gpx)!); }).then((content) => {
// } console.log({
}, caller: 'GpxImportSingleFile / content',
false gpxFile,
); content,
});
parseGpx(content.data);
});
} else {
const gpxReader = new FileReader();
gpxReader.readAsText(gpxFile);
gpxReader.addEventListener(
'load',
async () => {
// this will then display a text gpxfile
console.log({
caller: 'GpxImportSingleFile / XML',
gpxFile,
result: gpxReader.result,
});
parseGpx(gpxReader.result);
},
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,13 +110,19 @@ const GpxImportSingleFile: Component<Props> = ({ gpxFile }) => {
params: { params: {
id: gpxId(), id: gpxId(),
gpx: statsAndGpx()?.gpx, gpx: statsAndGpx()?.gpx,
tech: { tech:
lastModified: new Date(gpxFile.lastModified).toISOString(), typeof gpxFile === 'string'
importDate: new Date().toISOString(), ? {
name: gpxFile.name, importDate: new Date().toISOString(),
size: gpxFile.size, uri: gpxFile,
type: gpxFile.type, }
}, : {
lastModified: new Date(gpxFile.lastModified).toISOString(),
importDate: new Date().toISOString(),
name: gpxFile.name,
size: gpxFile.size,
type: gpxFile.type,
},
}, },
}); });
console.log({ console.log({

View File

@ -1 +1 @@
export { default } from './GpxImport'; export { default, importUrls } from './GpxImport';

View File

@ -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 });
const url = new URL(intent.data); if (intent.action === 'android.intent.action.VIEW') {
const q = url.search; const url = new URL(intent.data);
const [, lat, lon] = q.match(/q=([0-9.-]+),([0-9.-]+)/); const q = url.search;
console.log({ caller: 'Intent receiver', intent, url, lat, lon }); const [, lat, lon] = q.match(/q=([0-9.-]+),([0-9.-]+)/);
findLocation(navigate, [lon, lat]); console.log({ caller: 'Intent receiver', intent, url, lat, lon });
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({