Work around iOS 3rd party browser download (#418)
- use FileReader.readAsDataURL (for iOS Chromium) - add alternative Download from Server for now until proven in Prod and fixed in iOS Firefox (no i18n) - replace cloud icons as client-side now
This commit is contained in:
parent
1d26949770
commit
0fc60c1821
5 changed files with 47 additions and 18 deletions
|
|
@ -27,9 +27,12 @@ BR.Export = L.Class.extend({
|
|||
|
||||
this.exportButton.on('click', L.bind(this._generateTrackname, this));
|
||||
L.DomUtil.get('submitExport').onclick = L.bind(this._export, this);
|
||||
L.DomUtil.get('serverExport').onclick = L.bind(this._exportServer, this);
|
||||
|
||||
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
|
||||
|
||||
$('#export').on('show.bs.modal', this._warnStraightLine.bind(this));
|
||||
|
||||
this.update([]);
|
||||
},
|
||||
|
||||
|
|
@ -44,6 +47,16 @@ BR.Export = L.Class.extend({
|
|||
}
|
||||
},
|
||||
|
||||
_warnStraightLine: function () {
|
||||
const hasBeeline = BR.Routing.hasBeeline(this.segments);
|
||||
document.getElementById('export-beeline-warning').hidden = !hasBeeline;
|
||||
let title = 'Download from server (deprecated)';
|
||||
if (hasBeeline) {
|
||||
title = '[Warning: straight lines not supported] ' + title;
|
||||
}
|
||||
document.getElementById('serverExport').title = title;
|
||||
},
|
||||
|
||||
_getMimeType: function (format) {
|
||||
const mimeTypeMap = {
|
||||
gpx: 'application/gpx+xml',
|
||||
|
|
@ -64,7 +77,11 @@ BR.Export = L.Class.extend({
|
|||
link.click();
|
||||
},
|
||||
|
||||
_export: function (e) {
|
||||
_exportServer: function (e) {
|
||||
this._export(e, true);
|
||||
},
|
||||
|
||||
_export: function (e, server = false) {
|
||||
var exportForm = document.forms['export'];
|
||||
var format = exportForm['format'].value || $('#export-format input:radio:checked').val();
|
||||
var name = exportForm['trackname'].value;
|
||||
|
|
@ -73,7 +90,7 @@ BR.Export = L.Class.extend({
|
|||
|
||||
e.preventDefault();
|
||||
|
||||
if (BR.Browser.download) {
|
||||
if (!server && BR.Browser.download) {
|
||||
const track = this._formatTrack(format, name, includeWaypoints);
|
||||
const fileName = (name || 'brouter') + '.' + format;
|
||||
|
||||
|
|
@ -81,9 +98,10 @@ BR.Export = L.Class.extend({
|
|||
const blob = new Blob([track], {
|
||||
type: mimeType + ';charset=utf-8',
|
||||
});
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
|
||||
this._triggerDownload(objectUrl, fileName);
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => this._triggerDownload(reader.result, fileName);
|
||||
reader.readAsDataURL(blob);
|
||||
} else {
|
||||
var serverUrl = this.router.getUrl(
|
||||
this.latLngs,
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ BR.TrackStats = L.Class.extend({
|
|||
$('#stats-container').show();
|
||||
$('#stats-info').hide();
|
||||
|
||||
const hasBeeline = segments.filter((line) => line?._routing?.beeline).length > 0;
|
||||
document.getElementById('beeline-warning').hidden = !hasBeeline;
|
||||
document.getElementById('beeline-warning').hidden = !BR.Routing.hasBeeline(segments);
|
||||
|
||||
var stats = this.calcStats(polyline, segments),
|
||||
length1 = L.Util.formatNum(stats.trackLength / 1000, 1).toLocaleString(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue