refact: use shorthand method and property syntax

This commit is contained in:
Simon Legner 2024-10-14 21:11:28 +02:00 committed by Gautier P
parent babd154596
commit 76f31aeb2b
44 changed files with 520 additions and 514 deletions

View file

@ -23,7 +23,7 @@ BR.Routing = L.Routing.extend({
// width as base number, multiplied by number of digits + one for padding
iconSize: [6, 18],
offset: 5000,
textFunction: function (distance) {
textFunction(distance) {
return distance / 1000;
},
},
@ -42,13 +42,13 @@ BR.Routing = L.Routing.extend({
},
},
initialize: function (profile, options) {
initialize(profile, options) {
L.Routing.prototype.initialize.call(this, options);
this.profile = profile;
},
onAdd: function (map) {
onAdd(map) {
this.options.tooltips.waypoint = i18next.t('map.route-tooltip-waypoint');
this.options.tooltips.segment = i18next.t('map.route-tooltip-segment');
@ -178,16 +178,19 @@ BR.Routing = L.Routing.extend({
this._show();
}
}
var hide = function () {
if (!this._hidden && this._parent._waypoints._first) {
this._hide();
}
}.bind(this._draw);
function hideOverControl(e) {
hide();
// prevent showing trailer when clicking state buttons (causes event that propagates to map)
L.DomEvent.stopPropagation(e);
}
this._draw.on('enabled', function () {
this._map.on('mouseout', hide, this);
this._map.on('mouseover', show, this);
@ -246,7 +249,7 @@ BR.Routing = L.Routing.extend({
return container;
},
_addSegmentCasing: function (e) {
_addSegmentCasing(e) {
// extend layer style to inherit beeline dashArray
const casingStyle = Object.assign({}, e.layer.options, this.options.styles.trackCasing);
const casing = L.polyline(e.layer.getLatLngs(), Object.assign({}, casingStyle, { interactive: false }));
@ -255,11 +258,11 @@ BR.Routing = L.Routing.extend({
this._segments.bringToFront();
},
_removeSegmentCasing: function (e) {
_removeSegmentCasing(e) {
this._segmentsCasing.removeLayer(e.layer._casing);
},
setOpacity: function (opacity) {
setOpacity(opacity) {
// Due to the second Polyline layer for casing, the combined opacity is less
// transparent than with a single layer and the slider is non-linear. The
// inverted formula is used to get the same result as with a single layer.
@ -286,11 +289,11 @@ BR.Routing = L.Routing.extend({
}
},
_setMarkerOpacity: function (e) {
_setMarkerOpacity(e) {
e.layer.setOpacity(this.options.icons.opacity);
},
_removeMarkerEvents: function (marker) {
_removeMarkerEvents(marker) {
marker.off('mouseover', this._fireWaypointEvent, this);
marker.off('mouseout', this._fireWaypointEvent, this);
marker.off('dragstart', this._fireWaypointEvent, this);
@ -299,7 +302,7 @@ BR.Routing = L.Routing.extend({
marker.off('click', this._fireWaypointEvent, this);
},
clear: function () {
clear() {
var drawEnabled = this._draw._enabled;
var current = this._waypoints._first;
@ -326,7 +329,7 @@ BR.Routing = L.Routing.extend({
}
},
setWaypoints: function (latLngs, beelineFlags, cb) {
setWaypoints(latLngs, beelineFlags, cb) {
var i;
var callbackCount = 0;
var firstErr;
@ -367,7 +370,7 @@ BR.Routing = L.Routing.extend({
// patch to fix error when line is null or error line
// (when called while still segments to calculate, e.g. permalink or fast drawing)
toPolyline: function () {
toPolyline() {
var latLngs = [];
this._eachSegment(function (m1, m2, line) {
@ -381,7 +384,7 @@ BR.Routing = L.Routing.extend({
return L.polyline(latLngs);
},
_routeSegment: function (m1, m2, cb) {
_routeSegment(m1, m2, cb) {
var loadingTrailer;
// change segment color before request to indicate recalculation (mark old)
@ -413,7 +416,7 @@ BR.Routing = L.Routing.extend({
);
},
getSegments: function () {
getSegments() {
var segments = [];
this._eachSegment(function (m1, m2, line) {
@ -427,7 +430,7 @@ BR.Routing = L.Routing.extend({
return segments;
},
_keydownListener: function (e) {
_keydownListener(e) {
if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
@ -446,17 +449,17 @@ BR.Routing = L.Routing.extend({
}
},
_keyupListener: function (e) {
_keyupListener(e) {
if (e.keyCode === this.options.shortcut.draw.beelineModifier) {
this._draw._setTrailerStyle(false);
}
},
isDrawing: function () {
isDrawing() {
return this._draw._enabled;
},
reverse: function () {
reverse() {
const waypoints = this.getWaypoints();
const beelineFlags = this.getBeelineFlags();
waypoints.reverse();
@ -465,19 +468,19 @@ BR.Routing = L.Routing.extend({
this.setWaypoints(waypoints, beelineFlags);
},
deleteLastPoint: function () {
deleteLastPoint() {
if ((lastPoint = this.getLast())) {
this.removeWaypoint(lastPoint, function (err, data) {});
}
},
_removeDistanceMarkers: function () {
_removeDistanceMarkers() {
if (this._map && this._distanceMarkers) {
this._map.removeLayer(this._distanceMarkers);
}
},
_updateDistanceMarkers: function (e) {
_updateDistanceMarkers(e) {
this._removeDistanceMarkers();
if (this._map) {
@ -487,7 +490,7 @@ BR.Routing = L.Routing.extend({
}
},
_distance: function (latLng1, latLng2) {
_distance(latLng1, latLng2) {
//return Math.round(latLng1.distanceTo(latLng2));
const [ilon1, ilat1] = btools.util.CheapRuler.toIntegerLngLat([latLng1.lng, latLng1.lat]);
const [ilon2, ilat2] = btools.util.CheapRuler.toIntegerLngLat([latLng2.lng, latLng2.lat]);
@ -495,7 +498,7 @@ BR.Routing = L.Routing.extend({
return btools.util.CheapRuler.calcDistance(ilon1, ilat1, ilon2, ilat2);
},
_computeKinematic: function (distance, deltaHeight, costFactor) {
_computeKinematic(distance, deltaHeight, costFactor) {
const rc = new BR.RoutingContext(this.profile);
rc.expctxWay = new BR.BExpressionContextWay(undefined, costFactor);
const stdPath = new BR.StdPath();
@ -504,7 +507,7 @@ BR.Routing = L.Routing.extend({
return stdPath;
},
_getCostFactor: function (line) {
_getCostFactor(line) {
let costFactor;
if (line) {
const props = line.feature.properties;
@ -517,7 +520,7 @@ BR.Routing = L.Routing.extend({
return costFactor;
},
_interpolateBeelines: function (serialBeelines, before, after) {
_interpolateBeelines(serialBeelines, before, after) {
let altStart = before?.getLatLngs()[before.getLatLngs().length - 1].alt;
const altEnd = after?.getLatLngs()[0].alt ?? altStart;
altStart ?? (altStart = altEnd);
@ -562,7 +565,7 @@ BR.Routing = L.Routing.extend({
}
},
_updateBeelines: function () {
_updateBeelines() {
L.Routing.prototype._updateBeelines.call(this);
let serialBeelines = [];
@ -585,7 +588,7 @@ BR.Routing = L.Routing.extend({
}
},
createBeeline: function (latLng1, latLng2) {
createBeeline(latLng1, latLng2) {
const layer = L.Routing.prototype.createBeeline.call(this, latLng1, latLng2);
// remove alt from cloned LatLngs to show gap in elevation graph to indicate no data inbetween
delete layer.getLatLngs()[0].alt;