Merge remote-tracking branch 'upstream/master' into heightgraph-transpiled

This commit is contained in:
alexcojocaru 2020-12-21 21:23:04 -08:00
commit 3c1f5d0d6d
62 changed files with 4486 additions and 3554 deletions

View file

@ -4,7 +4,7 @@
Licensed under the MIT license.
*/
(function() {
(function () {
var mapContext;
function verifyTouchStyle(mapContext) {
@ -34,6 +34,7 @@
drawButton,
deleteRouteButton,
pois,
circlego,
urlHash;
// By default bootstrap-select use glyphicons
@ -41,14 +42,14 @@
iconBase: 'fa',
tickIcon: 'fa-check',
// don't overlap with footer
windowPadding: [0, 0, 40, 0]
windowPadding: [0, 0, 40, 0],
});
search = new BR.Search();
map.addControl(search);
$('#map .leaflet-control-geocoder > button')[0].title = i18next.t('keyboard.generic-shortcut', {
action: '$t(map.geocoder)',
key: 'F'
key: 'F',
});
router = L.bRouter(); //brouterCgi dummyRouter
@ -58,55 +59,67 @@
{
stateName: 'deactivate-draw',
icon: 'fa-pencil active',
onClick: function(control) {
onClick: function (control) {
routing.draw(false);
control.state('activate-draw');
},
title: i18next.t('keyboard.generic-shortcut', {
action: '$t(map.draw-route-stop)',
key: '$t(keyboard.escape)'
})
key: '$t(keyboard.escape)',
}),
},
{
stateName: 'activate-draw',
icon: 'fa-pencil',
onClick: function(control) {
onClick: function (control) {
routing.draw(true);
control.state('deactivate-draw');
},
title: i18next.t('keyboard.generic-shortcut', { action: '$t(map.draw-route-start)', key: 'D' })
}
]
title: i18next.t('keyboard.generic-shortcut', {
action: '$t(map.draw-route-start)',
key: 'D',
}),
},
],
});
var reverseRouteButton = L.easyButton(
'fa-random',
function() {
function () {
routing.reverse();
},
i18next.t('keyboard.generic-shortcut', { action: '$t(map.reverse-route)', key: 'R' })
i18next.t('keyboard.generic-shortcut', {
action: '$t(map.reverse-route)',
key: 'R',
})
);
var deletePointButton = L.easyButton(
'<span><i class="fa fa-caret-left"></i><i class="fa fa-map-marker" style="margin-left: 1px; color: gray;"></i></span>',
function() {
function () {
routing.deleteLastPoint();
},
i18next.t('keyboard.generic-shortcut', { action: '$t(map.delete-last-point)', key: 'Z' })
i18next.t('keyboard.generic-shortcut', {
action: '$t(map.delete-last-point)',
key: 'Z',
})
);
deleteRouteButton = L.easyButton(
'fa-trash-o',
function() {
function () {
clearRoute();
},
i18next.t('keyboard.generic-shortcut', { action: '$t(map.clear-route)', key: '$t(keyboard.backspace)' })
i18next.t('keyboard.generic-shortcut', {
action: '$t(map.clear-route)',
key: '$t(keyboard.backspace)',
})
);
L.DomEvent.addListener(
document,
'keydown',
function(e) {
function (e) {
if (BR.Util.keyboardShortcutsAllowed(e) && !$('.modal.show').length) {
if (e.keyCode === 8) {
// char code for 'backspace'
@ -128,19 +141,19 @@
inputOptions: [
{
text: i18next.t('map.delete-route'),
value: 'route'
value: 'route',
},
{
text: i18next.t('map.delete-nogo-areas'),
value: 'nogo'
value: 'nogo',
},
{
text: i18next.t('map.delete-pois'),
value: 'pois'
}
value: 'pois',
},
],
value: ['route'],
callback: function(result) {
callback: function (result) {
if (result !== null) {
if (result.indexOf('route') !== -1) {
routing.clear();
@ -154,7 +167,7 @@
onUpdate();
urlHash.onMapMove();
}
}
},
});
}
@ -177,14 +190,17 @@
routingOptions = new BR.RoutingOptions();
routingOptions.on('update', updateRoute);
routingOptions.on('update', function(evt) {
routingOptions.on('update', function (evt) {
profile.update(evt.options);
});
BR.NogoAreas.MSG_BUTTON = i18next.t('keyboard.generic-shortcut', { action: '$t(map.nogo.draw)', key: 'N' });
BR.NogoAreas.MSG_BUTTON = i18next.t('keyboard.generic-shortcut', {
action: '$t(map.nogo.draw)',
key: 'N',
});
BR.NogoAreas.MSG_BUTTON_CANCEL = i18next.t('keyboard.generic-shortcut', {
action: '$t(map.nogo.cancel)',
key: '$t(keyboard.escape)'
key: '$t(keyboard.escape)',
});
BR.NogoAreas.MSG_CREATE = i18next.t('map.nogo.click-drag');
BR.NogoAreas.MSG_DISABLED = i18next.t('map.nogo.edit');
@ -202,14 +218,14 @@
elevation = new BR.Heightgraph();
profile = new BR.Profile();
profile.on('update', function(evt) {
profile.on('update', function (evt) {
BR.message.hide();
var profileId = routingOptions.getCustomProfile();
router.uploadProfile(profileId, evt.profileText, function(err, profileId) {
router.uploadProfile(profileId, evt.profileText, function (err, profileId) {
if (!err) {
routingOptions.setCustomProfile(profileId, true);
updateRoute({
options: routingOptions.getOptions()
options: routingOptions.getOptions(),
});
} else {
profile.message.showError(err);
@ -224,40 +240,38 @@
}
});
});
profile.on('clear', function(evt) {
profile.on('clear', function (evt) {
profile.message.hide();
routingOptions.setCustomProfile(null);
});
trackMessages = new BR.TrackMessages(map, {
requestUpdate: requestUpdate
requestUpdate: requestUpdate,
});
trackAnalysis = new BR.TrackAnalysis(map, {
requestUpdate: requestUpdate
requestUpdate: requestUpdate,
});
routingPathQuality = new BR.RoutingPathQuality(map, layersControl);
routing = new BR.Routing({
routing: {
router: L.bind(router.getRouteSegment, router)
router: L.bind(router.getRouteSegment, router),
},
styles: BR.conf.routingStyles
styles: BR.conf.routingStyles,
});
pois = new BR.PoiMarkers({
routing: routing
});
pois = new BR.PoiMarkers(routing);
exportRoute = new BR.Export(router, pois);
routing.on('routing:routeWaypointEnd routing:setWaypointsEnd', function(evt) {
routing.on('routing:routeWaypointEnd routing:setWaypointsEnd', function (evt) {
search.clear();
onUpdate(evt && evt.err);
});
map.on('routing:draw-start', function() {
map.on('routing:draw-start', function () {
drawButton.state('deactivate-draw');
});
map.on('routing:draw-end', function() {
map.on('routing:draw-end', function () {
drawButton.state('activate-draw');
});
@ -298,15 +312,34 @@
listeningTabs: {
tab_profile: profile,
tab_data: trackMessages,
tab_analysis: trackAnalysis
}
tab_analysis: trackAnalysis,
},
}).addTo(map);
if (BR.conf.transit) {
sidebar.showPanel('tab_itinerary');
}
nogos.addTo(map);
L.easyBar([drawButton, reverseRouteButton, nogos.getButton(), deletePointButton, deleteRouteButton]).addTo(map);
var circlegoRadius = null;
var lang = i18next.languages.length && i18next.languages[0];
if (lang.startsWith('fr')) {
circlegoRadius = 20000;
}
if (circlegoRadius != null) {
circlego = new BR.CircleGoArea(routing, nogos, pois);
circlego.options.radius = circlegoRadius;
pois.circlego = circlego;
circlego.addTo(map);
}
var buttons = [drawButton, reverseRouteButton, nogos.getButton()];
if (circlegoRadius) buttons.push(circlego.getButton());
buttons.push(deletePointButton, deleteRouteButton);
L.easyBar(buttons).addTo(map);
nogos.preventRoutePointOnCreate(routing);
if (BR.keys.strava) {
@ -323,9 +356,12 @@
map.addControl(
new BR.OpacitySliderControl({
id: 'route',
title: i18next.t('map.opacity-slider-shortcut', { action: '$t(map.opacity-slider)', key: 'M' }),
title: i18next.t('map.opacity-slider-shortcut', {
action: '$t(map.opacity-slider)',
key: 'M',
}),
muteKeyCode: 77, // m
callback: L.bind(routing.setOpacity, routing)
callback: L.bind(routing.setOpacity, routing),
})
);
@ -340,8 +376,8 @@
layersControl.loadActiveLayers();
}
var onHashChangeCb = function(url) {
var url2params = function(s) {
var onHashChangeCb = function (url) {
var url2params = function (s) {
s = s.replace(/;/g, '|');
var p = {};
var sep = '&';
@ -367,13 +403,16 @@
routing.clear();
routing.setWaypoints(opts.lonlats);
}
if (opts.pois) {
pois.setMarkers(opts.pois);
}
if (circlego && opts.circlego) {
circlego.options.radius = opts.circlego[2];
circlego.setCircle([opts.circlego[0], opts.circlego[1]], opts.polylines != null);
}
};
var onInvalidHashChangeCb = function(params) {
var onInvalidHashChangeCb = function (params) {
params = params.replace('zoom=', 'map=');
params = params.replace('&lat=', '/');
params = params.replace('&lon=', '/');
@ -384,8 +423,10 @@
// do not initialize immediately
urlHash = new L.Hash(null, null);
// this callback is used to append anything in URL after L.Hash wrote #map=zoom/lat/lng/layer
urlHash.additionalCb = function() {
var url = router.getUrl(routing.getWaypoints(), pois.getMarkers(), null).substr('brouter?'.length + 1);
urlHash.additionalCb = function () {
var url = router
.getUrl(routing.getWaypoints(), pois.getMarkers(), circlego ? circlego.getCircle() : null, null)
.substr('brouter?'.length + 1);
// by default brouter use | as separator. To make URL more human-readable, we remplace them with ; for users
url = url.replace(/\|/g, ';');
@ -395,12 +436,12 @@
urlHash.onHashChangeCb = onHashChangeCb;
urlHash.onInvalidHashChangeCb = onInvalidHashChangeCb;
urlHash.init(map, {
layersControl: layersControl
layersControl: layersControl,
});
// activate configured default base layer or first if no hash,
// only after hash init, by using the same delay
setTimeout(function() {
setTimeout(function () {
layersControl.activateDefaultBaseLayer();
}, urlHash.changeDefer);
@ -412,7 +453,7 @@
// delete last waypoint
routing.on(
'waypoint:click',
function(evt) {
function (evt) {
var r = evt.marker._routing;
if (!r.prevMarker && !r.nextMarker) {
urlHash.onMapMove();
@ -422,7 +463,7 @@
);
}
i18next.on('languageChanged', function(detectedLanguage) {
i18next.on('languageChanged', function (detectedLanguage) {
// detected + fallbacks, e.g. ["de-DE", "de", "en"]
for (i = 0; i < i18next.languages.length; i++) {
var language = i18next.languages[i];
@ -445,14 +486,14 @@
{
fallbackLng: 'en',
backend: {
loadPath: 'dist/locales/{{lng}}.json'
}
loadPath: 'dist/locales/{{lng}}.json',
},
},
function(err, t) {
function (err, t) {
jqueryI18next.init(i18next, $, { useOptionsAttr: true });
$('html').localize();
$('#aboutLinks').localize({
privacyPolicyUrl: BR.conf.privacyPolicyUrl || 'https://brouter.de/privacypolicy.html'
privacyPolicyUrl: BR.conf.privacyPolicyUrl || 'https://brouter.de/privacypolicy.html',
});
mapContext = BR.Map.initMap();