diff --git a/js/control/RoutingOptions.js b/js/control/RoutingOptions.js index d755f18..aaba48d 100644 --- a/js/control/RoutingOptions.js +++ b/js/control/RoutingOptions.js @@ -52,6 +52,17 @@ BR.RoutingOptions = BR.Control.extend({ } }, + getCustomProfile: function() { + var select = L.DomUtil.get('profile'), + option = select.options[0], + profile = null; + + if (!option.disabled) { + profile = option.value; + } + return profile; + }, + _getChangeHandler: function() { return L.bind(function(evt) { this.fire('update', {options: this.getOptions()}); diff --git a/js/index.js b/js/index.js index 3aa4988..0859bb3 100644 --- a/js/index.js +++ b/js/index.js @@ -114,7 +114,8 @@ elevation = new BR.Elevation(); profile = new BR.Profile(); profile.on('update', function(evt) { - router.uploadProfile(evt.profileText, function(profile) { + var profileId = routingOptions.getCustomProfile(); + router.uploadProfile(profileId, evt.profileText, function(profile) { routingOptions.setCustomProfile(profile); }); }); diff --git a/js/router/BRouter.js b/js/router/BRouter.js index c17c34f..add2628 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -92,9 +92,16 @@ L.BRouter = L.Class.extend({ return this.getRoute([l1, l2], cb); }, - uploadProfile: function(profileText, cb) { - var xhr = new XMLHttpRequest(); - xhr.open('POST', L.BRouter.URL_PROFILE_UPLOAD, true); + uploadProfile: function(profileId, profileText, cb) { + var url = L.BRouter.URL_PROFILE_UPLOAD; + xhr = new XMLHttpRequest(); + + // reuse existing profile file + if (profileId) { + url += '/' + profileId; + } + + xhr.open('POST', url, true); xhr.onload = L.bind(this._handleProfileResponse, this, xhr, cb); // send profile text only, as text/plain;charset=UTF-8