build profile option list dynamically from config.js
This commit is contained in:
parent
9279913d36
commit
0e77fc6c6e
4 changed files with 37 additions and 18 deletions
13
config.js
Normal file
13
config.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
BR.conf = {
|
||||||
|
profiles: [
|
||||||
|
'trekking',
|
||||||
|
'fastbike',
|
||||||
|
'shortest',
|
||||||
|
'all',
|
||||||
|
/* "does not contain expressions for context node" (?)
|
||||||
|
'softaccess',
|
||||||
|
*/
|
||||||
|
'moped',
|
||||||
|
'car-test'
|
||||||
|
]
|
||||||
|
};
|
||||||
15
index.html
15
index.html
|
|
@ -34,18 +34,8 @@
|
||||||
<table>
|
<table>
|
||||||
<tr><td>Profile:</td>
|
<tr><td>Profile:</td>
|
||||||
<td><select id="profile">
|
<td><select id="profile">
|
||||||
<!-- sample profiles -->
|
<option value="" disabled><custom></option>
|
||||||
<option value="" disabled><custom></custom></option>
|
<!-- profile option list built dynamically from config -->
|
||||||
<option value="trekking">trekking</option>
|
|
||||||
<option value="fastbike">fastbike</option>
|
|
||||||
<option value="safety">safety</option>
|
|
||||||
<option value="shortest">shortest</option>
|
|
||||||
<option value="trekking-ignore-cr">trekking-ignore-cr</option>
|
|
||||||
<option value="trekking-steep">trekking-steep</option>
|
|
||||||
<option value="trekking-noferries">trekking-noferries</option>
|
|
||||||
<option value="trekking-nosteps">trekking-nosteps</option>
|
|
||||||
<option value="moped">moped</option>
|
|
||||||
<option value="car-test">car-test</option>
|
|
||||||
</select></td></tr>
|
</select></td></tr>
|
||||||
<tr><td>Alternative:</td>
|
<tr><td>Alternative:</td>
|
||||||
<td><select id="alternative">
|
<td><select id="alternative">
|
||||||
|
|
@ -95,6 +85,7 @@
|
||||||
// global package prefix for BRouter web application
|
// global package prefix for BRouter web application
|
||||||
BR = {};
|
BR = {};
|
||||||
</script>
|
</script>
|
||||||
|
<script src="config.js"></script>
|
||||||
<script src="js/router/BRouter.js"></script>
|
<script src="js/router/BRouter.js"></script>
|
||||||
<!-- <script src="js/router/brouterCgi.js"></script> -->
|
<!-- <script src="js/router/brouterCgi.js"></script> -->
|
||||||
<script src="js/control/Control.js"></script>
|
<script src="js/control/Control.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,24 @@ BR.RoutingOptions = BR.Control.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
L.DomUtil.get('profile').onchange = this._getChangeHandler();
|
var select = L.DomUtil.get('profile'),
|
||||||
|
i,
|
||||||
|
option;
|
||||||
|
|
||||||
|
select.onchange = this._getChangeHandler();
|
||||||
L.DomUtil.get('alternative').onchange = this._getChangeHandler();
|
L.DomUtil.get('alternative').onchange = this._getChangeHandler();
|
||||||
|
|
||||||
|
// build option list from config
|
||||||
|
var profiles = BR.conf.profiles;
|
||||||
|
for (i = 0; i < profiles.length; i++) {
|
||||||
|
option = document.createElement("option");
|
||||||
|
option.value = profiles[i];
|
||||||
|
option.text = profiles[i];
|
||||||
|
select.add(option, null);
|
||||||
|
}
|
||||||
|
// <custom> option disabled, select next
|
||||||
|
select.options[1].selected = true;
|
||||||
|
|
||||||
return BR.Control.prototype.onAdd.call(this, map);
|
return BR.Control.prototype.onAdd.call(this, map);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
10
js/index.js
10
js/index.js
|
|
@ -106,10 +106,6 @@
|
||||||
nogos = new BR.NogoAreas();
|
nogos = new BR.NogoAreas();
|
||||||
nogos.on('update', updateRoute);
|
nogos.on('update', updateRoute);
|
||||||
|
|
||||||
// initial option settings
|
|
||||||
router.setOptions(nogos.getOptions());
|
|
||||||
router.setOptions(routingOptions.getOptions());
|
|
||||||
|
|
||||||
stats = new BR.TrackStats();
|
stats = new BR.TrackStats();
|
||||||
download = new BR.Download();
|
download = new BR.Download();
|
||||||
elevation = new BR.Elevation();
|
elevation = new BR.Elevation();
|
||||||
|
|
@ -173,7 +169,11 @@
|
||||||
|
|
||||||
nogos.addTo(map);
|
nogos.addTo(map);
|
||||||
routing.addTo(map);
|
routing.addTo(map);
|
||||||
|
|
||||||
|
// initial option settings (after controls are added and initialized with onAdd, before permalink)
|
||||||
|
router.setOptions(nogos.getOptions());
|
||||||
|
router.setOptions(routingOptions.getOptions());
|
||||||
|
|
||||||
map.addControl(new L.Control.Permalink({
|
map.addControl(new L.Control.Permalink({
|
||||||
text: 'Permalink',
|
text: 'Permalink',
|
||||||
position: 'bottomright',
|
position: 'bottomright',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue