Load profile content for selected profile
This commit is contained in:
parent
433d4c4b85
commit
93d0b7f7df
7 changed files with 109 additions and 10 deletions
30
README.md
30
README.md
|
|
@ -11,15 +11,15 @@ http://brouter.de/brouter-web/
|
||||||
|
|
||||||
As an alternative to the above online version, the standalone server of BRouter can also be run on your local desktop.
|
As an alternative to the above online version, the standalone server of BRouter can also be run on your local desktop.
|
||||||
|
|
||||||
### Install
|
### Install BRouter (server with routing engine)
|
||||||
|
|
||||||
1. download and unzip latest [BRouter revision](http://brouter.de/brouter/revisions.html)
|
1. download and unzip latest [BRouter revision](http://brouter.de/brouter/revisions.html)
|
||||||
e.g. for Linux (replace ``~/opt/`` with your preferred install dir and ``1_0_1`` with latest version):
|
e.g. for Linux (replace ``~/opt/`` with your preferred install dir and ``1_1`` with latest version):
|
||||||
|
|
||||||
mkdir ~/opt/brouter
|
mkdir ~/opt/brouter
|
||||||
cd ~/opt/brouter
|
cd ~/opt/brouter
|
||||||
wget http://brouter.de/brouter_bin/brouter_1_0_1.zip
|
wget http://brouter.de/brouter_bin/brouter_1_1.zip
|
||||||
unzip brouter_1_0_1.zip
|
unzip brouter_1_1.zip
|
||||||
chmod +x ./standalone/server.sh
|
chmod +x ./standalone/server.sh
|
||||||
mv segments3 segments2 # workaround until scripts are updated
|
mv segments3 segments2 # workaround until scripts are updated
|
||||||
fix line endings with ``fromdos`` or ``dos2unix`` (might need to be installed first)
|
fix line endings with ``fromdos`` or ``dos2unix`` (might need to be installed first)
|
||||||
|
|
@ -27,10 +27,28 @@ fix line endings with ``fromdos`` or ``dos2unix`` (might need to be installed fi
|
||||||
fromdos ./standalone/server.sh
|
fromdos ./standalone/server.sh
|
||||||
2. download one or more [data file(s)](http://brouter.de/brouter/segments3/) (rd5) into ``segments2`` dir
|
2. download one or more [data file(s)](http://brouter.de/brouter/segments3/) (rd5) into ``segments2`` dir
|
||||||
|
|
||||||
|
### Install BRouter-Web (client)
|
||||||
|
|
||||||
|
1. download BRouter-Web as subdirectory ``brouter-web`` of the ``brouter`` directory
|
||||||
|
|
||||||
|
wget https://github.com/nrenner/brouter-web/archive/master.zip
|
||||||
|
unzip master.zip
|
||||||
|
mv brouter-web-master brouter-web
|
||||||
|
|
||||||
|
2. configure URL to ``profiles2`` directory
|
||||||
|
set ``BR.conf.profilesUrl`` in [config.js](config.js), e.g. uncomment:
|
||||||
|
|
||||||
|
BR.conf.profilesUrl = 'http://localhost:8000/profiles2/';
|
||||||
|
|
||||||
### Run
|
### Run
|
||||||
|
|
||||||
1. start server in the ``standalone`` directory with ``./server.sh`` or ``server.cmd`` (Windows)
|
1. start BRouter server in the ``standalone`` directory with ``./server.sh`` or ``server.cmd`` (Windows)
|
||||||
2. open http://nrenner.github.io/brouter-web/
|
2. serve the ``brouter`` directory for BRouter-Web
|
||||||
|
This is needed for pre-loading the selected profile (unless you allowed local file access in the Browser). Depending on your setup (see [How to run things locally](https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally)), start a web server in the ``brouter`` directory, e.g.:
|
||||||
|
|
||||||
|
python -m SimpleHTTPServer
|
||||||
|
|
||||||
|
2. open http://localhost:8000/brouter-web/
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
];
|
];
|
||||||
|
|
||||||
BR.conf.host = 'http://h2096617.stratoserver.net:443';
|
BR.conf.host = 'http://h2096617.stratoserver.net:443';
|
||||||
|
BR.conf.profilesUrl = 'http://brouter.de/brouter/profiles2/';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
@ -41,6 +42,12 @@
|
||||||
|
|
||||||
BR.conf.host = 'http://localhost:17777';
|
BR.conf.host = 'http://localhost:17777';
|
||||||
|
|
||||||
|
// Pre-loading selected profile disabled locally. Needs brouter-web to run on a
|
||||||
|
// local web server with the profiles in a subdirectory or allowing file access
|
||||||
|
// in the Browser (security!), see
|
||||||
|
// https://github.com/mrdoob/three.js/wiki/How-to-run-things-locally
|
||||||
|
//BR.conf.profilesUrl = 'http://localhost:8000/profiles2/';
|
||||||
|
//BR.conf.profilesUrl = 'file://YOUR_PATH_TO/profiles2/';
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@
|
||||||
BR = {};
|
BR = {};
|
||||||
</script>
|
</script>
|
||||||
<script src="config.js"></script>
|
<script src="config.js"></script>
|
||||||
|
<script src="js/Util.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>
|
||||||
|
|
|
||||||
30
js/Util.js
Normal file
30
js/Util.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
BR.Util = {
|
||||||
|
|
||||||
|
get: function(url, cb) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhr.open('GET', url, true);
|
||||||
|
xhr.onload = function() {
|
||||||
|
if ((xhr.status === 200 || xhr.status === 0) && xhr.responseText) {
|
||||||
|
cb(null, xhr.responseText);
|
||||||
|
} else {
|
||||||
|
cb(BR.Util.getError(xhr));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.onerror = function() {
|
||||||
|
cb(BR.Util.getError(xhr));
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
|
},
|
||||||
|
|
||||||
|
getError: function(xhr) {
|
||||||
|
var msg = 'no response from server';
|
||||||
|
if (xhr.responseText) {
|
||||||
|
msg = xhr.responseText;
|
||||||
|
} else if (xhr.status || xhr.statusText) {
|
||||||
|
msg = xhr.status + ': ' + xhr.statusText;
|
||||||
|
}
|
||||||
|
return new Error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -1,22 +1,58 @@
|
||||||
BR.Profile = L.Class.extend({
|
BR.Profile = L.Class.extend({
|
||||||
|
cache: {},
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
L.DomUtil.get('upload').onclick = L.bind(this._upload, this);
|
L.DomUtil.get('upload').onclick = L.bind(this._upload, this);
|
||||||
L.DomUtil.get('clear').onclick = L.bind(this.clear, this);
|
L.DomUtil.get('clear').onclick = L.bind(this.clear, this);
|
||||||
|
|
||||||
|
this.ele = document.profile_upload.profile;
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function(evt) {
|
clear: function(evt) {
|
||||||
var button = evt.target || evt.srcElement;
|
var button = evt.target || evt.srcElement;
|
||||||
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
document.profile_upload.profile.value = null;
|
this.ele.value = null;
|
||||||
|
this.ele.defaultValue = this.ele.value;
|
||||||
|
|
||||||
this.fire('clear');
|
this.fire('clear');
|
||||||
button.blur();
|
button.blur();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
update: function(options) {
|
||||||
|
var profileName = options.profile,
|
||||||
|
profileUrl,
|
||||||
|
ele = this.ele,
|
||||||
|
dirty = ele.defaultValue !== ele.value;
|
||||||
|
|
||||||
|
this.profileName = profileName;
|
||||||
|
if (profileName && BR.conf.profilesUrl && (!ele.value || !dirty)) {
|
||||||
|
if (!(profileName in this.cache)) {
|
||||||
|
profileUrl = BR.conf.profilesUrl + profileName + '.brf';
|
||||||
|
BR.Util.get(profileUrl, L.bind(function(err, profileText) {
|
||||||
|
if (err) {
|
||||||
|
console.warn('Error getting profile from "' + profileUrl + '": ' + err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cache[profileName] = profileText;
|
||||||
|
|
||||||
|
// don't set when option has changed while loading
|
||||||
|
if (!this.profileName || this.profileName === profileName) {
|
||||||
|
ele.value = profileText;
|
||||||
|
ele.defaultValue = ele.value;
|
||||||
|
}
|
||||||
|
}, this));
|
||||||
|
} else {
|
||||||
|
ele.value = this.cache[profileName];
|
||||||
|
ele.defaultValue = ele.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_upload: function(evt) {
|
_upload: function(evt) {
|
||||||
var button = evt.target || evt.srcElement,
|
var button = evt.target || evt.srcElement,
|
||||||
profile = document.profile_upload.profile.value;
|
profile = this.ele.value;
|
||||||
|
|
||||||
$(button).button('uploading');
|
$(button).button('uploading');
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,9 @@
|
||||||
|
|
||||||
routingOptions = new BR.RoutingOptions();
|
routingOptions = new BR.RoutingOptions();
|
||||||
routingOptions.on('update', updateRoute);
|
routingOptions.on('update', updateRoute);
|
||||||
|
routingOptions.on('update', function(evt) {
|
||||||
|
profile.update(evt.options);
|
||||||
|
});
|
||||||
|
|
||||||
nogos = new BR.NogoAreas();
|
nogos = new BR.NogoAreas();
|
||||||
nogos.on('update', updateRoute);
|
nogos.on('update', updateRoute);
|
||||||
|
|
@ -229,6 +232,7 @@
|
||||||
// initial option settings (after controls are added and initialized with onAdd, before permalink)
|
// initial option settings (after controls are added and initialized with onAdd, before permalink)
|
||||||
router.setOptions(nogos.getOptions());
|
router.setOptions(nogos.getOptions());
|
||||||
router.setOptions(routingOptions.getOptions());
|
router.setOptions(routingOptions.getOptions());
|
||||||
|
profile.update(routingOptions.getOptions());
|
||||||
|
|
||||||
map.addControl(new L.Control.Permalink({
|
map.addControl(new L.Control.Permalink({
|
||||||
text: 'Permalink',
|
text: 'Permalink',
|
||||||
|
|
@ -237,7 +241,8 @@
|
||||||
routingOptions: routingOptions,
|
routingOptions: routingOptions,
|
||||||
nogos: nogos,
|
nogos: nogos,
|
||||||
router: router,
|
router: router,
|
||||||
routing: routing
|
routing: routing,
|
||||||
|
profile: profile
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,12 +87,14 @@ L.Control.Permalink.include({
|
||||||
var router = this.options.router,
|
var router = this.options.router,
|
||||||
routing = this.options.routing,
|
routing = this.options.routing,
|
||||||
routingOptions = this.options.routingOptions,
|
routingOptions = this.options.routingOptions,
|
||||||
nogos = this.options.nogos;
|
nogos = this.options.nogos,
|
||||||
|
profile = this.options.profile;
|
||||||
|
|
||||||
var opts = router.parseUrlParams(e.params);
|
var opts = router.parseUrlParams(e.params);
|
||||||
router.setOptions(opts);
|
router.setOptions(opts);
|
||||||
routingOptions.setOptions(opts);
|
routingOptions.setOptions(opts);
|
||||||
nogos.setOptions(opts);
|
nogos.setOptions(opts);
|
||||||
|
profile.update(opts);
|
||||||
|
|
||||||
if (opts.lonlats) {
|
if (opts.lonlats) {
|
||||||
routing.draw(false);
|
routing.draw(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue