Closed hupe13 closed 2 years ago
Hi hupe,
I have not tested, but for the time being I recommend that you simply do so:
// Save a reference of default "_loadRoute" function (for later use)
var gpxGroupProto = L.GpxGroup.prototype;
var _loadRoute = gpxGroupProto._loadRoute;
// Customize default "L.GpxGroup" behaviour.
L.GpxGroup.include({
_loadRoute: function(geojson) {
if ( this.options.filename ) {
geojson.name = geojson.name.substr(0, geojson.name.lastIndexOf('.'));
}
if ( _loadRoute ) {
_loadRoute(geojson);
}
},
});
Reference: https://github.com/Raruto/leaflet-elevation/issues/32#issuecomment-568525359
@hupe13 are you ok with the proposed solution? can I close this?
I don't tested it. I'm using the modified version from leaflet-gpxgroup.js like this commit.
Ok @hupe13,
then for the moment I close it. Generally I prefer not to have hundreds of features (and the snippet I gave you should suffice), however if we have many requests about it in the future we can also re-evaluate them.
Have a nice day, Raruto
I looked into this again. I don't have to change _loadRoute
, I have to change addTrack
.
var gpxGroupProto = L.GpxGroup.prototype;
var addTrack = gpxGroupProto.addTrack;
L.GpxGroup.include({
addTrack: function(track) {
fetch(track)
.then(response => response.ok && response.text())
.then(text => this._elevation._parseFromString(text))
.then(geojson => {
if(geojson) {
geojson.name = geojson.name || (geojson[0] && geojson[0].properties.name) || track.split('/').pop().split('#')[0].split('?')[0];
geojson.name = this.options.filename ? track.split('/').pop().split('.').slice(0, -1).join('.') : geojson.name;
this._loadRoute(geojson);
}
});
},
})
Thank you very much.
See here. You can now set an option for filename:
filename: true,
to set the tracknames as basename of filenames.