Fix profile/alternative loading
This commit is contained in:
parent
5bd679a282
commit
595ac34d58
3 changed files with 28 additions and 20 deletions
|
|
@ -17,9 +17,10 @@ BR.RoutingOptions = BR.Control.extend({
|
||||||
return BR.Control.prototype.onAdd.call(this, map);
|
return BR.Control.prototype.onAdd.call(this, map);
|
||||||
},
|
},
|
||||||
|
|
||||||
getOptions: function() {
|
refreshUI: function() {
|
||||||
var profile = $('#profile option:selected'),
|
var profile = $('#profile option:selected'),
|
||||||
alternative = $('#alternative option:selected');
|
alternative = $('#alternative option:selected');
|
||||||
|
|
||||||
$('#stat-profile').html(profile.text() + ' (' + alternative.text() +')');
|
$('#stat-profile').html(profile.text() + ' (' + alternative.text() +')');
|
||||||
|
|
||||||
// we do not allow to select more than one profile and/or alternative at a time
|
// we do not allow to select more than one profile and/or alternative at a time
|
||||||
|
|
@ -36,8 +37,13 @@ BR.RoutingOptions = BR.Control.extend({
|
||||||
if (custom.value === "Custom") {
|
if (custom.value === "Custom") {
|
||||||
custom.disabled = true;
|
custom.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.selectpicker').selectpicker('refresh')
|
$('.selectpicker').selectpicker('refresh')
|
||||||
|
},
|
||||||
|
|
||||||
|
getOptions: function() {
|
||||||
|
var profile = $('#profile option:selected'),
|
||||||
|
alternative = $('#alternative option:selected');
|
||||||
|
this.refreshUI();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
profile: profile.val(),
|
profile: profile.val(),
|
||||||
|
|
@ -46,21 +52,19 @@ BR.RoutingOptions = BR.Control.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
setOptions: function(options) {
|
setOptions: function(options) {
|
||||||
var profiles_grp,
|
var values = [
|
||||||
profile = options.profile;
|
options.profile ? options.profile : $('#profile option:selected').val(),
|
||||||
|
options.alternative ? options.alternative : $('#alternative option:selected').val()
|
||||||
if (profile) {
|
];
|
||||||
profiles_grp = L.DomUtil.get('profile');
|
$('.selectpicker').selectpicker('val', values);
|
||||||
profiles_grp.value = profile;
|
this.refreshUI();
|
||||||
|
|
||||||
|
if (options.profile) {
|
||||||
// profile got not selected = not in option values -> custom profile passed with permalink
|
// profile got not selected = not in option values -> custom profile passed with permalink
|
||||||
if (profiles_grp.value != profile) {
|
if (L.DomUtil.get('profile').value != options.profile) {
|
||||||
this.setCustomProfile(profile, true);
|
this.setCustomProfile(options.profile, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.alternative) {
|
|
||||||
L.DomUtil.get('alternative').value = options.alternative;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setCustomProfile: function(profile, noUpdate) {
|
setCustomProfile: function(profile, noUpdate) {
|
||||||
|
|
|
||||||
|
|
@ -274,8 +274,8 @@
|
||||||
// do not initialize immediately
|
// do not initialize immediately
|
||||||
urlHash = new L.Hash(null, null);
|
urlHash = new L.Hash(null, null);
|
||||||
urlHash.additionalCb = function() {
|
urlHash.additionalCb = function() {
|
||||||
var url = router.getUrl(routing.getWaypoints(), null);
|
var url = router.getUrl(routing.getWaypoints(), null).substr('brouter?'.length+1);
|
||||||
return '&' + url.substr('brouter?'.length+1);
|
return url.length > 0 ? '&' + url : null;
|
||||||
};
|
};
|
||||||
urlHash.onHashChangeCb = onHashChangeCb;
|
urlHash.onHashChangeCb = onHashChangeCb;
|
||||||
urlHash.onInvalidHashChangeCb = onInvalidHashChangeCb;
|
urlHash.onInvalidHashChangeCb = onInvalidHashChangeCb;
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,17 @@ L.BRouter = L.Class.extend({
|
||||||
if (this.options.profile != null)
|
if (this.options.profile != null)
|
||||||
params.profile = this.options.profile;
|
params.profile = this.options.profile;
|
||||||
|
|
||||||
// do not put alternative in URL if it has its default value,
|
params.alternativeidx = this.options.alternative;
|
||||||
// but always set it if we want to generate route because Brouter API requires it.
|
|
||||||
if (this.options.alternative != 0 || format != null)
|
|
||||||
params.alternativeidx = this.options.alternative;
|
|
||||||
|
|
||||||
if (format != null)
|
if (format != null) {
|
||||||
params.format = format;
|
params.format = format;
|
||||||
|
} else {
|
||||||
|
// do not put values in URL if this is the default value (format===null)
|
||||||
|
if (params.profile === BR.conf.profiles[0])
|
||||||
|
delete params.profile;
|
||||||
|
if (params.alternativeidx == 0)
|
||||||
|
delete params.alternativeidx;
|
||||||
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue