profile upload (requires server update)
This commit is contained in:
parent
136a182539
commit
973d8bab75
8 changed files with 129 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ bower_components/Leaflet.Elevation/*
|
||||||
!bower_components/Leaflet.Elevation/dist/
|
!bower_components/Leaflet.Elevation/dist/
|
||||||
!bower_components/Leaflet.Elevation/src/
|
!bower_components/Leaflet.Elevation/src/
|
||||||
nbproject/
|
nbproject/
|
||||||
|
.idea/
|
||||||
|
|
|
||||||
|
|
@ -100,26 +100,53 @@ td {
|
||||||
|
|
||||||
.leaflet-leftpane {
|
.leaflet-leftpane {
|
||||||
left: 5px;
|
left: 5px;
|
||||||
top: 7px;
|
top: 7px;
|
||||||
bottom: 7px;
|
bottom: 7px;
|
||||||
|
|
||||||
/*
|
position: absolute;
|
||||||
height: 100%;
|
z-index: 1000;
|
||||||
display:table;
|
pointer-events: none;
|
||||||
*/
|
|
||||||
position: absolute;
|
|
||||||
z-index: 1000;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.leaflet-leftpane .leaflet-control {
|
.leaflet-leftpane .leaflet-control {
|
||||||
margin: 3px 5px;
|
margin: 3px 5px;
|
||||||
width: 370px;
|
width: 370px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO hack to maximize last div, further table-row tests, check out flex box */
|
/* Profile Control */
|
||||||
|
|
||||||
.leaflet-leftpane .leaflet-control:last-child {
|
.leaflet-leftpane .leaflet-control:last-child {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 432px;
|
top: 432px;
|
||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#profile_upload input {
|
||||||
|
position: absolute;
|
||||||
|
top: 6px;
|
||||||
|
right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* http://snook.ca/archives/html_and_css/absolute-position-textarea */
|
||||||
|
#textarea_container {
|
||||||
|
position: absolute;
|
||||||
|
top: 32px;
|
||||||
|
bottom: 6px;
|
||||||
|
left: 8px;
|
||||||
|
right: 8px;
|
||||||
|
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
font-size: 10px;
|
||||||
|
font-family: "Courier New", Courier, monospace;
|
||||||
|
line-height: 1.2em;
|
||||||
|
|
||||||
|
background-color: rgba(255,255,255,0);
|
||||||
|
}
|
||||||
|
textarea:focus {
|
||||||
|
background-color: rgba(255,255,255,255);
|
||||||
|
}
|
||||||
|
|
|
||||||
15
index.html
15
index.html
|
|
@ -25,9 +25,9 @@
|
||||||
<div class="title"><span class="title-name">BRouter web</span> <sup class="version">alpha1</sup></div>
|
<div class="title"><span class="title-name">BRouter web</span> <sup class="version">alpha1</sup></div>
|
||||||
<div class="header-text">
|
<div class="header-text">
|
||||||
'q' to cancel drawing, 'd' to enable drawing<br>
|
'q' to cancel drawing, 'd' to enable drawing<br>
|
||||||
Web client for <a href="http://brouter.de/brouter" target="_blank">BRouter</a> ·
|
Web client for <a href="http://brouter.de/brouter" target="_blank">BRouter</a> ·
|
||||||
<a href="https://github.com/nrenner/brouter-web#readme" target="_blank">about</a> ·
|
<a href="https://github.com/nrenner/brouter-web#readme" target="_blank">about</a> ·
|
||||||
<a href="https://github.com/nrenner/brouter-web" target="_blank">GitHub</a> ·
|
<a href="https://github.com/nrenner/brouter-web" target="_blank">GitHub</a> ·
|
||||||
<a href="http://groups.google.com/group/osm-android-bikerouting" target="_blank">contact</a><br>
|
<a href="http://groups.google.com/group/osm-android-bikerouting" target="_blank">contact</a><br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
<tr><td>Profile:</td>
|
<tr><td>Profile:</td>
|
||||||
<td><select id="profile">
|
<td><select id="profile">
|
||||||
<!-- sample profiles -->
|
<!-- sample profiles -->
|
||||||
|
<option value="" disabled><custom></custom></option>
|
||||||
<option value="trekking">trekking</option>
|
<option value="trekking">trekking</option>
|
||||||
<option value="fastbike">fastbike</option>
|
<option value="fastbike">fastbike</option>
|
||||||
<option value="safety">safety</option>
|
<option value="safety">safety</option>
|
||||||
|
|
@ -57,6 +58,14 @@
|
||||||
</td></tr>
|
</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="profile_div" class="hidden">
|
||||||
|
<form id="profile_upload" name="profile_upload">
|
||||||
|
<input type="submit" value="Upload" />
|
||||||
|
<div id="textarea_container">
|
||||||
|
<textarea type="text" name="profile" spellcheck="false" wrap="off" maxlength="100000" placeholder="... paste your custom routing profile here ..."></textarea>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet-src.js"></script>
|
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet-src.js"></script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,23 @@
|
||||||
BR.Profile = BR.Control.extend({
|
BR.Profile = BR.Control.extend({
|
||||||
options: {
|
options: {
|
||||||
heading: ''
|
heading: 'Profile',
|
||||||
|
divId: 'profile_div'
|
||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
var container = BR.Control.prototype.onAdd.call(this, map);
|
L.DomUtil.get('profile_upload').onsubmit = L.bind(this._submit, this)
|
||||||
container.innerHTML = " ";
|
|
||||||
return container;
|
return BR.Control.prototype.onAdd.call(this, map);
|
||||||
|
},
|
||||||
|
|
||||||
|
_submit: function(evt) {
|
||||||
|
var form = evt.target || evt.srcElement,
|
||||||
|
profile = document.profile_upload.profile.value;
|
||||||
|
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
this.fire('update', { profileText: profile });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BR.Profile.include(L.Mixin.Events);
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,39 @@ BR.RoutingOptions = BR.Control.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
setOptions: function(options) {
|
setOptions: function(options) {
|
||||||
if (options.profile) {
|
var select,
|
||||||
L.DomUtil.get('profile').value = options.profile;
|
profile = options.profile;
|
||||||
|
|
||||||
|
if (profile) {
|
||||||
|
select = L.DomUtil.get('profile');
|
||||||
|
select.value = profile;
|
||||||
|
|
||||||
|
// profile got not selected = not in option values -> custom profile passed with permalink
|
||||||
|
if (select.value != profile) {
|
||||||
|
this.setCustomProfile(profile, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (options.alternative) {
|
if (options.alternative) {
|
||||||
L.DomUtil.get('alternative').value = options.alternative;
|
L.DomUtil.get('alternative').value = options.alternative;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setCustomProfile: function(profile, noUpdate) {
|
||||||
|
var select,
|
||||||
|
option;
|
||||||
|
|
||||||
|
select = L.DomUtil.get('profile');
|
||||||
|
option = select.options[0]
|
||||||
|
option.value = profile;
|
||||||
|
select.value = profile;
|
||||||
|
option.disabled = false;
|
||||||
|
|
||||||
|
if (!noUpdate) {
|
||||||
|
this.fire('update', {options: this.getOptions()});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_getChangeHandler: function() {
|
_getChangeHandler: function() {
|
||||||
return L.bind(function(evt) {
|
return L.bind(function(evt) {
|
||||||
this.fire('update', {options: this.getOptions()});
|
this.fire('update', {options: this.getOptions()});
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@
|
||||||
routingOptions.on('update', updateRoute);
|
routingOptions.on('update', updateRoute);
|
||||||
|
|
||||||
nogos = new BR.NogoAreas();
|
nogos = new BR.NogoAreas();
|
||||||
nogos.on('update', updateRoute);
|
nogos.on('update', updateRoute);
|
||||||
|
|
||||||
// initial option settings
|
// initial option settings
|
||||||
router.setOptions(nogos.getOptions());
|
router.setOptions(nogos.getOptions());
|
||||||
|
|
@ -113,6 +113,11 @@
|
||||||
download = new BR.Download();
|
download = new BR.Download();
|
||||||
elevation = new BR.Elevation();
|
elevation = new BR.Elevation();
|
||||||
profile = new BR.Profile();
|
profile = new BR.Profile();
|
||||||
|
profile.on('update', function(evt) {
|
||||||
|
router.uploadProfile(evt.profileText, function(profile) {
|
||||||
|
routingOptions.setCustomProfile(profile);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
routing = new BR.Routing({routing: {
|
routing = new BR.Routing({routing: {
|
||||||
router: L.bind(router.getRouteSegment, router)
|
router: L.bind(router.getRouteSegment, router)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ L.Control.Permalink.include({
|
||||||
this.options.routing.on('waypoint:click', function(evt) {
|
this.options.routing.on('waypoint:click', function(evt) {
|
||||||
var r = evt.marker._routing;
|
var r = evt.marker._routing;
|
||||||
if (!r.prevMarker && ! r.nextMarker) {
|
if (!r.prevMarker && ! r.nextMarker) {
|
||||||
console.log('delete last');
|
|
||||||
this._update_routing(evt);
|
this._update_routing(evt);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
|
||||||
|
BR.HOST = 'http://localhost:17777';
|
||||||
|
|
||||||
L.BRouter = L.Class.extend({
|
L.BRouter = L.Class.extend({
|
||||||
statics: {
|
statics: {
|
||||||
// http://localhost:17777/brouter?lonlats=1.1,1.2|2.1,2.2|3.1,3.2|4.1,4.2&nogos=-1.1,-1.2,1|-2.1,-2.2,2&profile=shortest&alternativeidx=1&format=kml
|
// /brouter?lonlats=1.1,1.2|2.1,2.2|3.1,3.2|4.1,4.2&nogos=-1.1,-1.2,1|-2.1,-2.2,2&profile=shortest&alternativeidx=1&format=kml
|
||||||
URL_TEMPLATE: 'http://localhost:17777/brouter?lonlats={lonlats}&nogos={nogos}&profile={profile}&alternativeidx={alternativeidx}&format={format}',
|
URL_TEMPLATE: BR.HOST + '/brouter?lonlats={lonlats}&nogos={nogos}&profile={profile}&alternativeidx={alternativeidx}&format={format}',
|
||||||
|
URL_PROFILE_UPLOAD: BR.HOST + '/brouter/profile',
|
||||||
PRECISION: 6,
|
PRECISION: 6,
|
||||||
NUMBER_SEPARATOR: ',',
|
NUMBER_SEPARATOR: ',',
|
||||||
GROUP_SEPARATOR: '|'
|
GROUP_SEPARATOR: '|'
|
||||||
|
|
@ -88,6 +92,26 @@ L.BRouter = L.Class.extend({
|
||||||
return this.getRoute([l1, l2], cb);
|
return this.getRoute([l1, l2], cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
uploadProfile: function(profileText, cb) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', L.BRouter.URL_PROFILE_UPLOAD, true);
|
||||||
|
xhr.onload = L.bind(this._handleProfileResponse, this, xhr, cb);
|
||||||
|
|
||||||
|
// send profile text only, as text/plain;charset=UTF-8
|
||||||
|
xhr.send(profileText);
|
||||||
|
},
|
||||||
|
|
||||||
|
_handleProfileResponse: function(xhr, cb) {
|
||||||
|
var profile;
|
||||||
|
|
||||||
|
if (xhr.status === 200 && xhr.responseText && xhr.responseText.length > 0) {
|
||||||
|
// e.g. profileid=1400498280259
|
||||||
|
profile = xhr.responseText.split('=')[1];
|
||||||
|
|
||||||
|
cb(profile);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_getLonLatsString: function(latLngs) {
|
_getLonLatsString: function(latLngs) {
|
||||||
var s = '';
|
var s = '';
|
||||||
for (var i = 0; i < latLngs.length; i++) {
|
for (var i = 0; i < latLngs.length; i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue