@@ -1166,10 +1166,20 @@ ${props.text}`,
11661166 } ) ;
11671167 try {
11681168 let formatName ;
1169+ const existingFileNames = ( await Filesystem . readdir ( {
1170+ path : "" ,
1171+ directory : Directory . Documents ,
1172+ } ) ) . files . map ( file => file . name ) ;
11691173 if ( value === "json" ) {
11701174 formatName = "JSON" ;
1175+ let fileName = `${ route . name . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } .geojson` ;
1176+ let number = 0 ;
1177+ while ( existingFileNames . includes ( fileName ) ) {
1178+ number ++ ;
1179+ fileName = `${ route . name . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } _${ number } .geojson` ;
1180+ }
11711181 await Filesystem . writeFile ( {
1172- path : ` ${ route . name . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g , "_" ) } .geojson` ,
1182+ path : fileName ,
11731183 data : JSON . stringify ( this . #routeToGeojson( route ) ) ,
11741184 directory : Directory . Documents ,
11751185 encoding : Encoding . UTF8 ,
@@ -1186,8 +1196,14 @@ ${props.text}`,
11861196 }
11871197 } ) ;
11881198 const gpxString = new XMLSerializer ( ) . serializeToString ( gpx ) ;
1199+ let fileName = `${ route . name . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } .gpx` ;
1200+ let number = 0 ;
1201+ while ( existingFileNames . includes ( fileName ) ) {
1202+ number ++ ;
1203+ fileName = `${ route . name . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } _${ number } .gpx` ;
1204+ }
11891205 await Filesystem . writeFile ( {
1190- path : ` ${ route . name . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g , "_" ) } .gpx` ,
1206+ path : fileName ,
11911207 data : gpxString ,
11921208 directory : Directory . Documents ,
11931209 encoding : Encoding . UTF8 ,
@@ -1237,7 +1253,7 @@ ${props.text}`,
12371253 * Exporte le point de repère sous forme d'un ficheir geojson
12381254 * @param {* } route
12391255 */
1240- exportLandmark ( landmark ) {
1256+ async exportLandmark ( landmark ) {
12411257 let documentsName = "Documents" ;
12421258 if ( Capacitor . getPlatform ( ) === "ios" ) {
12431259 documentsName = "Fichiers" ;
@@ -1250,28 +1266,39 @@ ${props.text}`,
12501266 properties : landmark . properties ,
12511267 } ) ) ;
12521268 }
1253- Filesystem . writeFile ( {
1254- path : `${ landmark . properties . title . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } .geojson` ,
1255- data : JSON . stringify ( {
1256- type : "Feature" ,
1257- geometry : landmark . geometry ,
1258- properties : landmark . properties ,
1259- } ) ,
1269+ const existingFileNames = ( await Filesystem . readdir ( {
1270+ path : "" ,
12601271 directory : Directory . Documents ,
1261- encoding : Encoding . UTF8 ,
1262- } ) . then ( ( ) => {
1272+ } ) ) . files . map ( file => file . name ) ;
1273+ try {
1274+ let fileName = `${ landmark . properties . title . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } .geojson` ;
1275+ let number = 0 ;
1276+ while ( existingFileNames . includes ( fileName ) ) {
1277+ number ++ ;
1278+ fileName = `${ landmark . properties . title . replace ( / [ & / \\ # , + ( ) $ ~ % . ' " : * ? < > { } ] / g, "_" ) } _${ number } .geojson` ;
1279+ }
1280+ await Filesystem . writeFile ( {
1281+ path : fileName ,
1282+ data : JSON . stringify ( {
1283+ type : "Feature" ,
1284+ geometry : landmark . geometry ,
1285+ properties : landmark . properties ,
1286+ } ) ,
1287+ directory : Directory . Documents ,
1288+ encoding : Encoding . UTF8 ,
1289+ } ) ;
12631290 Toast . show ( {
12641291 text : `Fichier enregistré dans ${ documentsName } .` ,
12651292 duration : "long" ,
12661293 position : "bottom"
12671294 } ) ;
1268- } ) . catch ( ( ) => {
1295+ } catch {
12691296 Toast . show ( {
12701297 text : "Le point de repère n'a pas pu être savegardé." ,
12711298 duration : "long" ,
12721299 position : "bottom"
12731300 } ) ;
1274- } ) ;
1301+ }
12751302 }
12761303
12771304 /**
0 commit comments