Commit 95257f86 authored by Clouard Regis's avatar Clouard Regis
Browse files

Fix bug on import/export GPX

parent 20d3cade
......@@ -19,18 +19,18 @@ function removeDownloadButton(div, button) {
}
function clearDownloadButton(div) {
while (div.hasChildNodes()){
while (div.hasChildNodes()) {
div.firstChild.remove();
}
}
function downloadFile(filename, contents) {
let oldHeader = "<gpx version=\"1.0\">"
if (contents.startsWith(oldHeader)) {
contents = contents.substring(oldHeader.length);
const localHeader = "<gpx version=\"1.0\">"
if (contents.startsWith(localHeader)) {
contents = contents.substring(localHeader.length);
let header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><gpx version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"Vikazimut\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">";
contents = header + contents;
}
let header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><gpx version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"Vikazimut\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">";
contents = header + contents;
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(contents));
element.setAttribute('download', filename);
......
......@@ -86,8 +86,10 @@ class GpxImport
$track->setName($this->nickname);
$track->setFormat($this->format);
$gpxContent = str_replace(array("\n", "\r"), '', (string)$this->loadedGpx->asXML());
$posStrGpx = strpos($gpxContent, "<gpx");
$track->setTrace(substr($gpxContent, $posStrGpx));
$posStrGpx = strpos($gpxContent, "<trk>");
$gpxContent = substr($gpxContent, $posStrGpx);
$gpxContent = "<gpx version=\"1.0\">" . $gpxContent;
$track->setTrace($gpxContent);
$track->setTotalTime($this->extractTotalTime());
$track->setControlPoints($this->extractControlPoints(simplexml_load_string($courseRepository->find($this->idCourse)->getXml())));
$track->setCourse($courseRepository->find($this->idCourse));
......@@ -227,9 +229,11 @@ class GpxImport
{
try {
$this->loadedGpx = simplexml_load_file($this->gpx->getPathname());
return true;
} catch (Exception $e) {
$this->error = "invalid Gpx file";
return false;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment