Skip to content

Commit

Permalink
fix regression in background layer loading from URL
Browse files Browse the repository at this point in the history
fixes #3820
  • Loading branch information
tyrasd committed Feb 6, 2017
1 parent 2120ab4 commit ff4bf25
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions modules/svg/gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,32 @@ export function svgGpx(projection, context, dispatch) {
}


function getExtension(file) {
if (_.isUndefined(file)) {
function getExtension(fileName) {
if (_.isUndefined(fileName)) {
return '';
}

var lastDotIndex = file.name.lastIndexOf('.');
var lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex < 0) {
return '';
}

return file.name.substr(lastDotIndex);
return fileName.substr(lastDotIndex);
}


function parseSaveAndZoom(extension, data) {
if (extension === '.gpx') {
drawGpx.geojson(toGeoJSON.gpx(toDom(data))).fitZoom();
}
else if (extension === '.kml') {
drawGpx.geojson(toGeoJSON.kml(toDom(data))).fitZoom();
}
else if (extension === '.geojson' || extension === '.json') {
drawGpx.geojson(JSON.parse(data)).fitZoom();
switch (extension) {
default:
drawGpx.geojson(toGeoJSON.gpx(toDom(data))).fitZoom();
break;
case '.kml':
drawGpx.geojson(toGeoJSON.kml(toDom(data))).fitZoom();
break;
case '.geojson':
case '.json':
drawGpx.geojson(JSON.parse(data)).fitZoom();
break;
}
}

Expand Down Expand Up @@ -180,7 +183,7 @@ export function svgGpx(projection, context, dispatch) {
reader = new FileReader();

reader.onload = (function(file) {
var extension = getExtension(file);
var extension = getExtension(file.name);

return function (e) {
parseSaveAndZoom(extension, e.target.result);
Expand Down

1 comment on commit ff4bf25

@bhousel
Copy link
Member

@bhousel bhousel commented on ff4bf25 Feb 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @tyrasd! I'll do a quick test and release a patch today if it's good..

Please sign in to comment.