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

@ -10,15 +10,16 @@ L.BRouter = L.Class.extend({
GROUP_SEPARATOR: '|',
ABORTED_ERROR: 'aborted',
CUSTOM_PREFIX: 'custom_',
SUPPORTED_BROUTER_VERSIONS: '< 1.7.0 || >=1.7.2', // compatibility string should be in npm package versioning format
isCustomProfile: function (profileName) {
SUPPORTED_BROUTER_VERSIONS: '< 1.7.0 || >=1.7.2',
// compatibility string should be in npm package versioning format
isCustomProfile(profileName) {
return profileName && profileName.substring(0, 7) === L.BRouter.CUSTOM_PREFIX;
},
},
options: {},
initialize: function (options) {
initialize(options) {
L.setOptions(this, options);
this.queue = async.queue(
@ -29,11 +30,11 @@ L.BRouter = L.Class.extend({
);
},
setOptions: function (options) {
setOptions(options) {
L.setOptions(this, options);
},
getUrlParams: function (latLngs, beelineFlags, pois, circlego, format) {
getUrlParams(latLngs, beelineFlags, pois, circlego, format) {
params = {};
if (this._getLonLatsString(latLngs) != null) params.lonlats = this._getLonLatsString(latLngs);
@ -75,7 +76,7 @@ L.BRouter = L.Class.extend({
return params;
},
parseUrlParams: function (params) {
parseUrlParams(params) {
var opts = {};
if (params.lonlats) {
opts.lonlats = this._parseLonLats(params.lonlats);
@ -116,7 +117,7 @@ L.BRouter = L.Class.extend({
return opts;
},
getUrl: function (latLngs, beelineFlags, pois, circlego, format, trackname, exportWaypoints) {
getUrl(latLngs, beelineFlags, pois, circlego, format, trackname, exportWaypoints) {
var urlParams = this.getUrlParams(latLngs, beelineFlags, pois, circlego, format);
var args = [];
if (urlParams.lonlats != null && urlParams.lonlats.length > 0)
@ -133,7 +134,7 @@ L.BRouter = L.Class.extend({
if (trackname)
args.push(
L.Util.template('trackname={trackname}', {
trackname: trackname,
trackname,
})
);
if (exportWaypoints) args.push('exportWaypoints=1');
@ -143,7 +144,7 @@ L.BRouter = L.Class.extend({
return (prepend_host ? BR.conf.host : '') + '/brouter?' + args.join('&');
},
getRoute: function (latLngs, cb) {
getRoute(latLngs, cb) {
var url = this.getUrl(latLngs, null, null, null, 'geojson'),
xhr = new XMLHttpRequest();
@ -164,7 +165,7 @@ L.BRouter = L.Class.extend({
xhr.send();
},
_handleRouteResponse: function (xhr, cb) {
_handleRouteResponse(xhr, cb) {
var layer, geojson;
if (
@ -193,7 +194,7 @@ L.BRouter = L.Class.extend({
},
versionCheckDone: false,
checkBRouterVersion: function (creator) {
checkBRouterVersion(creator) {
if (this.versionCheckDone) {
return;
}
@ -217,11 +218,11 @@ L.BRouter = L.Class.extend({
}
},
getRouteSegment: function (l1, l2, cb) {
getRouteSegment(l1, l2, cb) {
this.queue.push({ segment: [l1, l2] }, cb);
},
uploadProfile: function (profileId, profileText, cb) {
uploadProfile(profileId, profileText, cb) {
var url = L.BRouter.URL_PROFILE_UPLOAD;
xhr = new XMLHttpRequest();
@ -241,7 +242,7 @@ L.BRouter = L.Class.extend({
xhr.send(profileText);
},
_assignFeatures: function (segment) {
_assignFeatures(segment) {
if (segment.feature.properties.messages) {
var featureMessages = segment.feature.properties.messages,
segmentLatLngs = segment.getLatLngs(),
@ -268,14 +269,14 @@ L.BRouter = L.Class.extend({
return segment;
},
_getFeatureLatLng: function (message) {
_getFeatureLatLng(message) {
var lon = message[0] / 1000000,
lat = message[1] / 1000000;
return L.latLng(lat, lon);
},
_handleProfileResponse: function (xhr, cb) {
_handleProfileResponse(xhr, cb) {
var response;
if (xhr.status === 200 && xhr.responseText && xhr.responseText.length > 0) {
@ -286,7 +287,7 @@ L.BRouter = L.Class.extend({
}
},
_getLonLatsString: function (latLngs) {
_getLonLatsString(latLngs) {
var s = '';
for (var i = 0; i < latLngs.length; i++) {
s += this._formatLatLng(latLngs[i]);
@ -297,7 +298,7 @@ L.BRouter = L.Class.extend({
return s;
},
_parseLonLats: function (s) {
_parseLonLats(s) {
var groups,
numbers,
lonlats = [];
@ -316,7 +317,7 @@ L.BRouter = L.Class.extend({
return lonlats;
},
_getBeelineString: function (beelineFlags) {
_getBeelineString(beelineFlags) {
var indexes = [];
for (var i = 0; i < beelineFlags.length; i++) {
if (beelineFlags[i]) {
@ -326,7 +327,7 @@ L.BRouter = L.Class.extend({
return indexes.join(',');
},
_parseBeelines: function (s, lonlats) {
_parseBeelines(s, lonlats) {
if (!lonlats || lonlats.length < 2) return [];
const beelineFlags = new Array(lonlats.length - 1);
@ -337,7 +338,7 @@ L.BRouter = L.Class.extend({
return beelineFlags;
},
_getLonLatsNameString: function (latLngNames) {
_getLonLatsNameString(latLngNames) {
var s = '';
for (var i = 0; i < latLngNames.length; i++) {
s += this._formatLatLng(latLngNames[i].latlng);
@ -351,7 +352,7 @@ L.BRouter = L.Class.extend({
return s;
},
_parseLonLatNames: function (s) {
_parseLonLatNames(s) {
var groups,
part,
lonlatnames = [];
@ -370,7 +371,7 @@ L.BRouter = L.Class.extend({
return lonlatnames;
},
_getNogosString: function (nogos) {
_getNogosString(nogos) {
var s = '';
for (var i = 0, circle; i < nogos.length; i++) {
circle = nogos[i];
@ -393,7 +394,7 @@ L.BRouter = L.Class.extend({
return s;
},
_parseNogos: function (s) {
_parseNogos(s) {
var groups,
numbers,
nogos = [];
@ -419,7 +420,7 @@ L.BRouter = L.Class.extend({
return nogos;
},
_getNogosPolylinesString: function (nogos) {
_getNogosPolylinesString(nogos) {
var s = '';
for (var i = 0, polyline, vertices; i < nogos.length; i++) {
polyline = nogos[i];
@ -446,7 +447,7 @@ L.BRouter = L.Class.extend({
return s;
},
_parseNogosPolylines: function (s) {
_parseNogosPolylines(s) {
var groups,
numbers,
latlngs,
@ -466,14 +467,14 @@ L.BRouter = L.Class.extend({
if (j < numbers.length) {
nogoWeight = Number.parseFloat(numbers[j++]);
}
var options = L.extend(BR.NogoAreas.prototype.polylineOptions, { nogoWeight: nogoWeight });
var options = L.extend(BR.NogoAreas.prototype.polylineOptions, { nogoWeight });
nogos.push(L.polyline(latlngs, options));
}
}
return nogos;
},
_getNogosPolygonsString: function (nogos) {
_getNogosPolygonsString(nogos) {
var s = '';
for (var i = 0, polygon, vertices; i < nogos.length; i++) {
polygon = nogos[i];
@ -500,7 +501,7 @@ L.BRouter = L.Class.extend({
return s;
},
_parseNogosPolygons: function (s) {
_parseNogosPolygons(s) {
var groups,
numbers,
latlngs,
@ -520,13 +521,13 @@ L.BRouter = L.Class.extend({
if (j < numbers.length) {
nogoWeight = Number.parseFloat(numbers[j++]);
}
nogos.push(L.polygon(latlngs, { nogoWeight: nogoWeight }));
nogos.push(L.polygon(latlngs, { nogoWeight }));
}
}
return nogos;
},
_parseProfile: function (profile) {
_parseProfile(profile) {
if (BR.conf.profilesRename?.[profile]) {
return BR.conf.profilesRename[profile];
}
@ -535,7 +536,7 @@ L.BRouter = L.Class.extend({
},
// formats L.LatLng object as lng,lat string
_formatLatLng: function (latLng) {
_formatLatLng(latLng) {
var s = '';
s += L.Util.formatNum(latLng.lng ?? latLng[1], L.BRouter.PRECISION);
s += L.BRouter.NUMBER_SEPARATOR;