Skip to content

Commit

Permalink
Rework gpx export
Browse files Browse the repository at this point in the history
gpx files were generated with https://github.com/tyrasd/togpx which was not
adding the initial xml node. Gpx export files are now created calling the ORS API
with format=gpx. Instructions may be included.

Closes #256
  • Loading branch information
TheGreatRefrigerator committed Sep 11, 2018
1 parent 62703d0 commit 3ede3aa
Show file tree
Hide file tree
Showing 18 changed files with 3,721 additions and 3,370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@ <h1 ng-bind-html="('DOWNLOAD_ROUTE' | translate)">
</label>
<div class="ui input">
<input ng-model="$ctrl.filename" required="" select-on-click="">
</input>
</div>
</div>
<div class="ui divider">
</div>
<div>
<label ng-bind-html="('FILE_FORMAT' | translate)">
</label>
<select ng-change="$ctrl.change_fileFormat($ctrl.selected_fileformat)" ng-model="$ctrl.selected_fileformat"
<select class="ui selection dropdown" ng-change="$ctrl.change_fileFormat($ctrl.selected_fileformat)"
ng-model="$ctrl.selected_fileformat"
ng-options="fileFormatOpt.text for fileFormatOpt in $ctrl.fileFormat">
</select>
</div>
<div ng-if="$ctrl.selected_fileformat.value == 'geojson'">
<label ng-bind-html="('ELEVATION' | translate)"></label>
<input type="checkbox" ng-model="$ctrl.elevation"/>
<div ng-if="$ctrl.geojsonOptShow">
<br>
<div class="ui checkbox">
<input type="checkbox" id="elevation" data-ng-model="$ctrl.elevation"
ng-click="$ctrl.elevation != $ctrl.elevation"/>
<label for="elevation" ng-bind-html="('ELEVATION' | translate)"></label>
</div>
</div>
<div ng-if="$ctrl.gpxOptShow">
<br>
<div class="ui checkbox">
<input type="checkbox" id="instructions" data-ng-model="$ctrl.instructions"
ng-click="$ctrl.instructions != $ctrl.instructions">
<label for="instructions" ng-bind-html="('INCLUDE_INSTRUCTIONS' | translate)"></label>
</div>
</div>
<div class="ui divider">
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ angular
function(orsExportFactory, orsRouteService) {
let ctrl = this;
ctrl.elevation = true;
ctrl.instructions = false;
ctrl.filename = "ors-export-linestring";
ctrl.gpxOptShow = true;
ctrl.tcxOptShow = false;
Expand Down Expand Up @@ -86,7 +87,8 @@ angular
};
ctrl.exportRoute = () => {
let options = {
elevation: ctrl.elevation
elevation: ctrl.elevation,
instructions: ctrl.instructions
};
let currentRoute = null;
if (ctrl.currentFileFormat == "rawjson") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ angular
"$scope",
"orsRouteService",
"orsSettingsFactory",
"orsRequestService",
"lists",
function($rootScope, $scope, orsRouteService, orsSettingsFactory, lists) {
function(
$rootScope,
$scope,
orsRouteService,
orsSettingsFactory,
orsRequestService,
lists
) {
let ctrl = this;
ctrl.profiles = lists.profiles;
/** use scope in order to share same template ng-include with summaries */
Expand Down
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<script src="node_modules/@angular/router/angular1/angular_1_router.js"></script>
<script src="node_modules/geojson/geojson.min.js"></script>
<script src="node_modules/togpx/togpx.js"></script>
<script src="node_modules/xml-js/dist/xml-js.min.js"></script>
<script src="node_modules/tokml/tokml.js"></script>
<script src="node_modules/leaflet-omnivore/leaflet-omnivore.min.js"></script>
<script src="node_modules/turf.js" type="text/javascript"></script>
Expand Down
76 changes: 61 additions & 15 deletions app/infrastructure/ors-importexport-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ angular
.module("orsApp.GeoFileHandler-service", ["ngFileSaver"])
/**
/*** Export Factory
**/
.factory("orsExportFactory", [
**/ .factory("orsExportFactory", [
"FileSaver",
"Blob",
"orsNamespaces",
(FileSaver, Blob, orsNamespaces) => {
"orsRequestService",
"orsSettingsFactory",
"orsUtilsService",
"orsRouteService",
(
FileSaver,
Blob,
orsNamespaces,
orsRequestService,
orsSettingsFactory,
orsUtilsService,
orsRouteService
) => {
var orsExportFactory = {};
/**
* Export any vector element on the map to GPX
Expand All @@ -27,12 +38,44 @@ angular
let exportData, geojsonData, extension;
extension = "." + format;
switch (format) {
/**
* To generate the gpx file the ORS API is called with format=gpx and current settings.
* Instructions can be included when needed.
*/
case "gpx":
geojsonData = L.polyline(geometry).toGeoJSON();
geojsonData.properties.name = filename; // togpx is looking for name tag https://www.npmjs.com/package/togpx#gpx
exportData = togpx(geojsonData, {
creator: "OpenRouteService.org"
});
let userOptions = orsSettingsFactory.getUserOptions();
let settings = orsSettingsFactory.getSettings();
let payload = orsUtilsService.routingPayload(settings, userOptions);
payload.format = "gpx";
if (!options.instructions) payload.instructions = false;
const request = orsRouteService.fetchRoute(payload);
orsRouteService.routingRequests.requests.push(request);
request.promise.then(
function(response) {
// parsing xml to js object using https://www.npmjs.com/package/xml-js
exportData = xml2js(response);
let metadata = exportData.elements[0].elements[0].elements;
metadata[0].elements[0].text = filename;
metadata[1].elements[0].text = options.instruction
? "This route and instructions were generated from maps.openrouteservice"
: "This route was generated from maps.openrouteservice";
// parsing back to xml string + saving
exportData = js2xml(exportData);
exportData = new Blob([exportData], {
type: "application/xml;charset=utf-8"
});
FileSaver.saveAs(exportData, filename + extension);
},
function(error) {
orsSettingsFactory.requestSubject.onNext(false);
alert("There was an error generating the gpx file: " + error);
}
);
// geojsonData = L.polyline(geometry).toGeoJSON();
// geojsonData.properties.name = filename; // togpx is looking for name tag https://www.npmjs.com/package/togpx#gpx
// exportData = togpx(geojsonData, {
// creator: "OpenRouteService.org"
// });
break;
case "kml":
geojsonData = L.polyline(geometry).toGeoJSON();
Expand Down Expand Up @@ -90,18 +133,21 @@ angular
break;
default:
}
exportData = new Blob([exportData], {
type: "application/xml;charset=utf-8"
});
FileSaver.saveAs(exportData, filename + extension);
// as gpx generation is async we have to save it upon returned promise
// therefore skipping saving for gpx here
if (format !== "gpx") {
exportData = new Blob([exportData], {
type: "application/xml;charset=utf-8"
});
FileSaver.saveAs(exportData, filename + extension);
}
};
return orsExportFactory;
}
])
/**
/*** Import Factory
**/
.factory("orsImportFactory", [
/*** Import Factory
**/ .factory("orsImportFactory", [
"orsNamespaces",
orsNamespaces => {
var orsImportFactory = {};
Expand Down
3 changes: 2 additions & 1 deletion app/languages/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,6 @@
"INFO_SUPPORT": "Unterstützen Sie openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice bietet kostenlose Dienstleistungen an und ist für einen Großteil seiner Finanzierung auf Spenden angewiesen. Wenn Sie die Weiterentwicklung von Features und Serverinfrastruktur unterstützen möchten, sind Spenden sehr willkommen.",
"LOCALE_HEIGHTGRAPH": "Höhenprofil",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/it-IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion app/languages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@
"INFO_SUPPORT": "Please Support openrouteservice.org",
"INFO_SUPPORT_TEXT": "Openrouteservice offers free services and relies on donations for a majority of its funding. If you would like to support the further development of features and server infrastructure donations are very welcome.",
"LOCALE_HEIGHTGRAPH": "Elevation profile",
"DEVELOPER_SETTINGS": "Developer Settings"
"DEVELOPER_SETTINGS": "Developer Settings",
"INCLUDE_INSTRUCTIONS": "Include Instructions"
}
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"clipboard": "^2.0.0"
},
"resolutions": {
"angular": "~1.5.10"
"angular": "~1.5.10",
"leaflet": ">= 1.3.1"
}
}

0 comments on commit 3ede3aa

Please sign in to comment.