initial commit

This commit is contained in:
Norbert Renner 2014-01-27 18:34:48 +01:00
parent 37980ff82b
commit 4cc16bccd0
17 changed files with 789 additions and 0 deletions

37
js/control/Control.js Normal file
View file

@ -0,0 +1,37 @@
BR.Control = L.Control.extend({
options: {
position: 'leftpane'
},
onAdd: function (map) {
var container = L.DomUtil.create('div', 'info'),
heading,
div;
if (this.options.heading) {
heading = L.DomUtil.create('div', 'heading', container);
heading.innerHTML = this.options.heading;
this._content = L.DomUtil.create('div', 'content', container);
} else {
this._content = container;
}
if (this.options.divId) {
div = L.DomUtil.get(this.options.divId);
L.DomUtil.removeClass(div, 'hidden');
this._content.appendChild(div);
}
var stop = L.DomEvent.stopPropagation;
L.DomEvent
.on(container, 'click', stop)
.on(container, 'mousedown', stop)
.on(container, 'dblclick', stop);
// disabled because links not working, remove?
//L.DomEvent.on(container, 'click', L.DomEvent.preventDefault);
return container;
}
});

20
js/control/Download.js Normal file
View file

@ -0,0 +1,20 @@
BR.Download = BR.Control.extend({
options: {
heading: 'Download'
},
onAdd: function (map) {
var container = BR.Control.prototype.onAdd.call(this, map);
return container;
},
update: function (urls) {
var html = '<div class="label">&nbsp;</div><div class="value">';
if (urls.gpx) {
html += '<a href="' + urls.gpx + '" download="brouter.gpx" target="_blank">GPX</a> &middot; ';
html += '<a href="' + urls.kml + '" download="brouter.kml" target="_blank">KML</a>';
}
html += '</div>'
this._content.innerHTML = html;
}
});

11
js/control/Profile.js Normal file
View file

@ -0,0 +1,11 @@
BR.Profile = BR.Control.extend({
options: {
heading: ''
},
onAdd: function (map) {
var container = BR.Control.prototype.onAdd.call(this, map);
container.innerHTML = "&nbsp;";
return container;
}
});

View file

@ -0,0 +1,28 @@
BR.RoutingOptions = BR.Control.extend({
options: {
heading: 'Options',
divId: 'route_options'
},
onAdd: function (map) {
L.DomUtil.get('profile').onchange = this._getChangeHandler();
L.DomUtil.get('alternative').onchange = this._getChangeHandler();
return BR.Control.prototype.onAdd.call(this, map);
},
getOptions: function() {
return {
profile: L.DomUtil.get('profile').value,
alternative: L.DomUtil.get('alternative').value
};
},
_getChangeHandler: function() {
return L.bind(function(evt) {
this.fire('update', {options: this.getOptions()});
}, this);
}
});
BR.RoutingOptions.include(L.Mixin.Events);

49
js/control/TrackStats.js Normal file
View file

@ -0,0 +1,49 @@
BR.TrackStats = BR.Control.extend({
options: {
heading: 'Route'
},
onAdd: function (map) {
var container = BR.Control.prototype.onAdd.call(this, map);
this.update();
return container;
},
update: function (polyline) {
var stats = this.calcStats(polyline),
html = '';
html += '<table id="stats">';
html += '<tr><td>Length: </td><td>' + L.Util.formatNum(stats.distance/1000,1) + '</td><td>km</td></tr>';
html += '<tr><td>Ascent: </td><td>' + Math.round(stats.elevationGain) + '</td><td>m</td></tr>';
html += '<tr><td>Descent: </td><td>' + Math.round(stats.elevationLoss) + '</td><td>m</td></tr>';
html += '</table>';
this._content.innerHTML = html;
},
calcStats: function(polyline) {
var stats = {
distance: 0,
elevationGain: 0,
elevationLoss: 0
};
var latLngs = polyline ? polyline.getLatLngs() : [];
for (var i = 0, current, next, eleDiff; i < latLngs.length - 1; i++) {
current = latLngs[i];
next = latLngs[i + 1];
stats.distance += current.distanceTo(next);
// from Leaflet.gpx plugin (writes to LatLng.meta.ele, LatLng now supports ele)
eleDiff = (next.ele || next.meta.ele) - (current.ele || current.meta.ele);
if (eleDiff > 0) {
stats.elevationGain += eleDiff;
} else {
stats.elevationLoss += Math.abs(eleDiff);
}
}
return stats;
}
});