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

@ -6,7 +6,7 @@ BR.BingLayer = L.BingLayer.extend({
' (<a target="_blank" href="https://go.microsoft.com/?linkid=9710837">TOU</a>)',
},
initialize: function (key, options) {
initialize(key, options) {
L.BingLayer.prototype.initialize.call(this, key, options);
this._logo = L.control({ position: 'bottomleft' });
@ -18,12 +18,12 @@ BR.BingLayer = L.BingLayer.extend({
};
},
onAdd: function (map) {
onAdd(map) {
L.BingLayer.prototype.onAdd.call(this, map);
map.addControl(this._logo);
},
onRemove: function (map) {
onRemove(map) {
L.BingLayer.prototype.onRemove.call(this, map);
map.removeControl(this._logo);
},

View file

@ -20,14 +20,14 @@ BR.CircleGoArea = L.Control.extend({
},
},
initialize: function (routing, nogos, pois, options) {
initialize(routing, nogos, pois, options) {
this.routing = routing;
this.nogos = nogos;
this.pois = pois;
L.setOptions(this, options);
},
onAdd: function (map) {
onAdd(map) {
var self = this;
this.map = map;
@ -38,7 +38,7 @@ BR.CircleGoArea = L.Control.extend({
{
stateName: 'activate-circlego',
icon: 'fa-circle-o',
onClick: function () {
onClick() {
self.draw(true);
},
title: i18next.t('keyboard.generic-shortcut', {
@ -49,7 +49,7 @@ BR.CircleGoArea = L.Control.extend({
{
stateName: 'deactivate-circlego',
icon: 'fa-circle-o active',
onClick: function () {
onClick() {
self.draw(false);
},
title: i18next.t('keyboard.generic-shortcut', {
@ -88,7 +88,7 @@ BR.CircleGoArea = L.Control.extend({
return container;
},
draw: function (enable) {
draw(enable) {
this.drawButton.state(enable ? 'deactivate-circlego' : 'activate-circlego');
if (enable) {
this.routing.draw(false);
@ -109,7 +109,7 @@ BR.CircleGoArea = L.Control.extend({
}
},
_keydownListener: function (e) {
_keydownListener(e) {
if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
@ -120,7 +120,7 @@ BR.CircleGoArea = L.Control.extend({
}
},
_getBoundary: function (center, adminLevel, adminLevelFallback) {
_getBoundary(center, adminLevel, adminLevelFallback) {
adminLevel = adminLevel || 8;
var query =
'[out:json]; is_in(' +
@ -165,7 +165,7 @@ BR.CircleGoArea = L.Control.extend({
);
},
_setBoundary: function (geoJson) {
_setBoundary(geoJson) {
// drop admin_centre nodes
geoJson.features = geoJson.features.filter(function (feature) {
return feature.geometry.type !== 'Point';
@ -173,7 +173,7 @@ BR.CircleGoArea = L.Control.extend({
var boundaryLine = turf.polygonToLine(geoJson.features[0]);
this.boundaryLayer = L.geoJson(boundaryLine, {
style: function (feature) {
style(feature) {
return {
weight: 1,
color: 'black',
@ -199,7 +199,7 @@ BR.CircleGoArea = L.Control.extend({
this.setOutsideArea(ring);
},
_getPolygonForPoint: function (center, featureCollection) {
_getPolygonForPoint(center, featureCollection) {
var polygon = null;
var point = turf.point(center);
@ -216,15 +216,15 @@ BR.CircleGoArea = L.Control.extend({
return polygon;
},
_getState: function (center) {
_getState(center) {
return this._getPolygonForPoint(center, this.states);
},
_getCountry: function (center) {
_getCountry(center) {
return this._getPolygonForPoint(center, this.countries);
},
_applyStateRules: function (center) {
_applyStateRules(center) {
var state = this._getState(center);
if (state) {
@ -255,7 +255,7 @@ BR.CircleGoArea = L.Control.extend({
}
},
_applyCountryRules: function (center) {
_applyCountryRules(center) {
var country = this._getCountry(center);
if (country) {
@ -294,7 +294,7 @@ BR.CircleGoArea = L.Control.extend({
},
// debugging
_logStates: function (states) {
_logStates(states) {
for (var i = 0; i < states.features.length; i++) {
var state = states.features[i];
console.log(
@ -304,12 +304,12 @@ BR.CircleGoArea = L.Control.extend({
},
// debugging
_addGeoJsonLayer: function (states, options) {
_addGeoJsonLayer(states, options) {
// delay, otherwise triggers premature hash update through mapmove
setTimeout(
L.bind(function () {
L.geoJson(states, {
style: function (feature) {
style(feature) {
return L.extend(
{
weight: 1,
@ -327,7 +327,7 @@ BR.CircleGoArea = L.Control.extend({
);
},
_loadStates: function () {
_loadStates() {
if (this.statesLoading) return;
this.statesLoading = true;
@ -349,7 +349,7 @@ BR.CircleGoArea = L.Control.extend({
);
},
_loadCountries: function () {
_loadCountries() {
BR.Util.getJson(
this.options.countriesUrl,
'countries',
@ -364,7 +364,7 @@ BR.CircleGoArea = L.Control.extend({
renderer: this.maskRenderer,
// use Leaflet.snogylop plugin here, turf.mask too slow (~4s) for some reason
invert: true,
style: function (feature) {
style(feature) {
return {
weight: 1,
color: 'darkgreen',
@ -388,25 +388,25 @@ BR.CircleGoArea = L.Control.extend({
);
},
_setNogo: function (ring) {
_setNogo(ring) {
this.nogoPolylines = L.geoJson(ring, BR.NogoAreas.prototype.polylineOptions);
this.nogos.addNogos(null, this.nogoPolylines.getLayers(), null);
},
_removeNogo: function () {
_removeNogo() {
if (this.nogoPolylines) {
this.nogos.removeNogos(null, this.nogoPolylines.getLayers(), null);
this.nogoPolylines = null;
}
},
_setNogoCircle: function (center) {
_setNogoCircle(center) {
var polygon = this.circleToPolygon(center, this.radius);
this._setNogo(polygon);
this.setOutsideArea(polygon);
},
setNogoRing: function (center) {
setNogoRing(center) {
this._clearLayers();
this._removeNogo();
@ -428,7 +428,7 @@ BR.CircleGoArea = L.Control.extend({
}
},
_lockOutsideArea: function () {
_lockOutsideArea() {
if (this.outsideArea) {
this.outsideArea.eachLayer(function (layer) {
layer._path.classList.add('circlego-outside');
@ -437,7 +437,7 @@ BR.CircleGoArea = L.Control.extend({
}
},
_unlockOutsideArea: function () {
_unlockOutsideArea() {
if (this.outsideArea) {
this.outsideArea.eachLayer(function (layer) {
layer._path.classList.remove('circlego-outside');
@ -446,12 +446,12 @@ BR.CircleGoArea = L.Control.extend({
}
},
setOutsideArea: function (ring) {
setOutsideArea(ring) {
var mask = turf.mask(turf.polygonize(ring));
this.outsideArea = L.geoJson(mask, {
renderer: this.maskRenderer,
style: function (feature) {
style(feature) {
return {
weight: 4,
color: 'black',
@ -466,11 +466,11 @@ BR.CircleGoArea = L.Control.extend({
this._lockOutsideArea();
},
onMapClick: function (e) {
onMapClick(e) {
this.setCircle([e.latlng.lng, e.latlng.lat]);
},
setOptions: function (opts) {
setOptions(opts) {
this.radius = opts.circlego[2];
if (opts.polylines) {
this.nogoPolylines = L.featureGroup(opts.polylines, BR.NogoAreas.prototype.polylineOptions);
@ -478,7 +478,7 @@ BR.CircleGoArea = L.Control.extend({
this.setCircle([opts.circlego[0], opts.circlego[1]], opts.polylines);
},
setCircle: function (center, polylines) {
setCircle(center, polylines) {
var marker = (this.marker = this._createMarker(center));
this.clear();
@ -503,7 +503,7 @@ BR.CircleGoArea = L.Control.extend({
this.draw(false);
},
_createMarker: function (center) {
_createMarker(center) {
var self = this;
var icon = (this.icon = L.VectorMarkers.icon({
icon: 'home',
@ -519,7 +519,7 @@ BR.CircleGoArea = L.Control.extend({
'<button id="remove-ringgo-marker" class="btn btn-secondary"><i class="fa fa-trash"></i></button>';
var marker = L.marker([center[1], center[0]], {
icon: icon,
icon,
draggable: true,
// prevent being on top of route markers
zIndexOffset: -500,
@ -547,7 +547,7 @@ BR.CircleGoArea = L.Control.extend({
return marker;
},
_onPopupOpen: function (popup, popupContent) {
_onPopupOpen(popup, popupContent) {
var exportName = '';
var html = '<p>';
if (this.radius) {
@ -580,7 +580,7 @@ BR.CircleGoArea = L.Control.extend({
if (this.nogoPolylines) {
var link = location.href.replace(/&polylines=[^&]*/, '');
var geoJson = this.nogoPolylines.toGeoJSON();
var gpx = togpx(geoJson, { metadata: { name: exportName, link: link } });
var gpx = togpx(geoJson, { metadata: { name: exportName, link } });
this._setDownloadUrl(gpx, 'application/gpx+xml', 'ringgo-download-gpx');
this._setDownloadUrl(
JSON.stringify(geoJson, null, 2),
@ -599,12 +599,12 @@ BR.CircleGoArea = L.Control.extend({
);
},
_onPopupClose: function (evt) {
_onPopupClose(evt) {
this._revokeDownloadUrl('ringgo-download-gpx');
this._revokeDownloadUrl('ringgo-download-geojson');
},
_setDownloadUrl: function (text, mimeType, elementId) {
_setDownloadUrl(text, mimeType, elementId) {
var blob = new Blob([text], {
type: mimeType + ';charset=utf-8',
});
@ -613,14 +613,14 @@ BR.CircleGoArea = L.Control.extend({
download.href = objectUrl;
},
_revokeDownloadUrl: function (elementId) {
_revokeDownloadUrl(elementId) {
var download = document.getElementById(elementId);
if (download) {
URL.revokeObjectURL(download.href);
}
},
_clearLayers: function () {
_clearLayers() {
if (this.outsideArea) {
this.map.removeLayer(this.outsideArea);
this.outsideArea = null;
@ -631,16 +631,16 @@ BR.CircleGoArea = L.Control.extend({
}
},
clear: function () {
clear() {
this.circleLayer.clearLayers();
this._clearLayers();
},
getButton: function () {
getButton() {
return this.drawButton;
},
getCircle: function () {
getCircle() {
var circle = this.circleLayer.getLayers().map(function (it) {
return it.getLatLng();
});
@ -651,15 +651,15 @@ BR.CircleGoArea = L.Control.extend({
}
},
toRadians: function (angleInDegrees) {
toRadians(angleInDegrees) {
return (angleInDegrees * Math.PI) / 180;
},
toDegrees: function (angleInRadians) {
toDegrees(angleInRadians) {
return (angleInRadians * 180) / Math.PI;
},
offset: function (c1, distance, bearing) {
offset(c1, distance, bearing) {
var lon1 = this.toRadians(c1[0]);
var lat1 = this.toRadians(c1[1]);
var dByR = distance / 6378137; // distance divided by 6378137 (radius of the earth) wgs84
@ -673,7 +673,7 @@ BR.CircleGoArea = L.Control.extend({
return [this.toDegrees(lon), this.toDegrees(lat)];
},
circleToPolygon: function (center, radius, numberOfSegments) {
circleToPolygon(center, radius, numberOfSegments) {
var n = numberOfSegments ? numberOfSegments : 64;
var inner = [];

View file

@ -151,7 +151,7 @@ BR.Heightgraph = function (map, layersControl, routing, pois) {
},
},
addBelow: function (map) {
addBelow(map) {
// waiting for https://github.com/MrMufflon/Leaflet.Elevation/pull/66
// this.width($('#map').outerWidth());
this.options.width = $('#content').outerWidth();
@ -163,6 +163,7 @@ BR.Heightgraph = function (map, layersControl, routing, pois) {
function setParent(el, newParent) {
newParent.appendChild(el);
}
this.addTo(map);
// move elevation graph outside of the map
@ -202,7 +203,7 @@ BR.Heightgraph = function (map, layersControl, routing, pois) {
this.update();
},
initCollapse: function (map) {
initCollapse(map) {
var self = this;
var onHide = function () {
$('#elevation-btn').removeClass('active');
@ -231,13 +232,13 @@ BR.Heightgraph = function (map, layersControl, routing, pois) {
});
},
_keydownListener: function (e) {
_keydownListener(e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.toggle) {
$('#elevation-btn').click();
}
},
update: function (track, layer) {
update(track, layer) {
// bring height indicator to front, because of track casing in BR.Routing
if (this._mouseHeightFocus) {
var g = this._mouseHeightFocus._groups[0][0].parentNode;
@ -290,7 +291,7 @@ BR.Heightgraph = function (map, layersControl, routing, pois) {
}
},
_createLegend: function () {
_createLegend() {
if (this._categories.length > 0) {
// find the min and the max gradients for the current profile
var minGradient = 16;

View file

@ -40,11 +40,11 @@ BR.NogoAreas = L.Control.extend({
smoothFactor: 0.5,
},
initialize: function () {
initialize() {
this._wasRouteDrawing = false;
},
onAdd: function (map) {
onAdd(map) {
var self = this;
$('#submitNogos').on('click', L.bind(this.uploadNogos, this));
@ -149,7 +149,7 @@ BR.NogoAreas = L.Control.extend({
return L.DomUtil.create('div');
},
_keydownListener: function (e) {
_keydownListener(e) {
if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
@ -170,17 +170,17 @@ BR.NogoAreas = L.Control.extend({
}
},
displayUploadError: function (message) {
displayUploadError(message) {
$('#nogoError').text(message ? message : '');
$('#nogoError').css('display', message ? 'block' : 'none');
},
onFileChanged: function (e) {
onFileChanged(e) {
if (!e.target.files[0]) return;
$(e.target).next('label').text(e.target.files[0].name);
},
uploadNogos: function () {
uploadNogos() {
var self = this;
var geoJSONPromise;
@ -253,7 +253,7 @@ BR.NogoAreas = L.Control.extend({
}
var geoJSON = L.geoJson(turf.featureCollection(cleanedGeoJSONFeatures), {
onEachFeature: function (feature, layer) {
onEachFeature(feature, layer) {
layer.options.nogoWeight = feature.properties.nogoWeight || nogoWeight;
if (feature.geometry.type === 'LineString') {
L.setOptions(layer, self.polylineOptions);
@ -266,7 +266,7 @@ BR.NogoAreas = L.Control.extend({
nogosPoints = nogosPoints.map(function (item) {
var radius = item.feature.properties.radius || nogoRadius;
if (radius > 0) {
return L.circle(item.getLatLng(), { radius: radius });
return L.circle(item.getLatLng(), { radius });
}
return null;
});
@ -303,7 +303,7 @@ BR.NogoAreas = L.Control.extend({
},
// prevent route waypoint added after circle create (map click after up)
preventRoutePointOnCreate: function (routing) {
preventRoutePointOnCreate(routing) {
this.editTools.on(
'editable:drawing:start',
function (e) {
@ -327,7 +327,7 @@ BR.NogoAreas = L.Control.extend({
);
},
getOptions: function () {
getOptions() {
return {
nogos: this.drawnItems.getLayers().filter(function (e) {
return e instanceof L.Circle;
@ -341,7 +341,7 @@ BR.NogoAreas = L.Control.extend({
};
},
setOptions: function (options) {
setOptions(options) {
var nogos = options.nogos;
var polylines = options.polylines;
var polygons = options.polygons;
@ -349,12 +349,12 @@ BR.NogoAreas = L.Control.extend({
this._addNogos(nogos, polylines, polygons);
},
addNogos: function (nogos, polylines, polygons) {
addNogos(nogos, polylines, polygons) {
this._addNogos(nogos, polylines, polygons);
this._fireUpdate();
},
_addNogos: function (nogos, polylines, polygons) {
_addNogos(nogos, polylines, polygons) {
if (nogos) {
for (var i = 0; i < nogos.length; i++) {
nogos[i].setStyle(this.style);
@ -375,7 +375,7 @@ BR.NogoAreas = L.Control.extend({
}
},
removeNogos: function (nogos, polylines, polygons) {
removeNogos(nogos, polylines, polygons) {
if (nogos) {
for (var i = 0; i < nogos.length; i++) {
this.drawnItems.removeLayer(nogos[i]);
@ -395,28 +395,28 @@ BR.NogoAreas = L.Control.extend({
this._fireUpdate();
},
_clear: function () {
_clear() {
this.drawnItems.clearLayers();
},
clear: function () {
clear() {
this._clear();
this._fireUpdate();
},
_fireUpdate: function () {
_fireUpdate() {
this.fire('update', { options: this.getOptions() });
},
getFeatureGroup: function () {
getFeatureGroup() {
return this.drawnItems;
},
getEditGroup: function () {
getEditGroup() {
return this.editTools.editLayer;
},
getButton: function () {
getButton() {
return this.button;
},
});
@ -430,7 +430,7 @@ BR.Editable = L.Editable.extend({
// Also, we generally disable the Tap handler in the map options for route dragging,
// see Map.js, so we always need to enable for drawing.
initialize: function (map, options) {
initialize(map, options) {
L.Editable.prototype.initialize.call(this, map, options);
if (!this.map.tap) {
@ -439,7 +439,7 @@ BR.Editable = L.Editable.extend({
}
},
registerForDrawing: function (editor) {
registerForDrawing(editor) {
this._tapEnabled = this.map.tap.enabled();
if (!this._tapEnabled) {
this.map.tap.enable();
@ -448,7 +448,7 @@ BR.Editable = L.Editable.extend({
L.Editable.prototype.registerForDrawing.call(this, editor);
},
unregisterForDrawing: function (editor) {
unregisterForDrawing(editor) {
if (!this._tapEnabled) {
this.map.tap.disable();
}
@ -456,7 +456,7 @@ BR.Editable = L.Editable.extend({
L.Editable.prototype.unregisterForDrawing.call(this, editor);
},
createVertexIcon: function (options) {
createVertexIcon(options) {
return BR.Browser.touch ? new L.Editable.TouchVertexIcon(options) : new L.Editable.VertexIcon(options);
},
});
@ -466,13 +466,13 @@ BR.EditingTooltip = L.Handler.extend({
closeTimeout: 2000,
},
initialize: function (map, editTools, button) {
initialize(map, editTools, button) {
this.map = map;
this.editTools = editTools;
this.button = button;
},
addHooks: function () {
addHooks() {
// hack: listen to EasyButton click (instead of editable:drawing:start),
// to get mouse position from event for initial tooltip location
L.DomEvent.addListener(this.button.button, 'click', this._addCreate, this);
@ -484,7 +484,7 @@ BR.EditingTooltip = L.Handler.extend({
this.editTools.on('editable:disable', this._disable, this);
},
removeHooks: function () {
removeHooks() {
L.DomEvent.removeListener(this.button.button, 'click', this._addCreate, this);
this.editTools.featuresLayer.off('layeradd', this._bind, this);
@ -494,7 +494,7 @@ BR.EditingTooltip = L.Handler.extend({
this.editTools.off('editable:disable', this._disable, this);
},
_bind: function (e) {
_bind(e) {
// Position tooltip at bottom of circle, less distracting than
// sticky with cursor or at center.
@ -517,7 +517,7 @@ BR.EditingTooltip = L.Handler.extend({
};
},
_addCreate: function (e) {
_addCreate(e) {
// button cancel
if (!this.editTools.drawing()) return;
@ -564,7 +564,7 @@ BR.EditingTooltip = L.Handler.extend({
}
},
_setCloseTimeout: function (layer) {
_setCloseTimeout(layer) {
var timeoutId = setTimeout(function () {
layer.closeTooltip();
}, this.options.closeTimeout);
@ -575,7 +575,7 @@ BR.EditingTooltip = L.Handler.extend({
});
},
_postCreate: function () {
_postCreate() {
// editing is disabled by another handler, tooltip won't stay open before
this.editTools.once(
'editable:disable',
@ -588,7 +588,7 @@ BR.EditingTooltip = L.Handler.extend({
);
},
_enable: function (e) {
_enable(e) {
e.layer.setTooltipContent(BR.NogoAreas.MSG_ENABLED);
this.editTools.once(
@ -600,42 +600,42 @@ BR.EditingTooltip = L.Handler.extend({
);
},
_disable: function (e) {
_disable(e) {
e.layer.setTooltipContent(BR.NogoAreas.MSG_DISABLED);
this._setCloseTimeout(e.layer);
},
});
BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
_computeDeleteLatLng: function () {
_computeDeleteLatLng() {
// While circle is not added to the map, _radius is not set.
var delta = (this.feature._radius || this.feature._mRadius) * Math.cos(Math.PI / 4),
point = this.map.project(this.feature._latlng);
return this.map.unproject([point.x - delta, point.y - delta]);
},
_updateDeleteLatLng: function () {
_updateDeleteLatLng() {
this._deleteLatLng.update(this._computeDeleteLatLng());
this._deleteLatLng.__vertex.update();
},
_addDeleteMarker: function () {
_addDeleteMarker() {
if (!this.enabled()) return;
this._deleteLatLng = this._computeDeleteLatLng();
return new BR.DeleteMarker(this._deleteLatLng, this);
},
_delete: function () {
_delete() {
this.disable();
this.tools.featuresLayer.removeLayer(this.feature);
},
delete: function () {
delete() {
this._delete();
this.fireAndForward('editable:deleted');
},
initialize: function (map, feature, options) {
initialize(map, feature, options) {
L.Editable.CircleEditor.prototype.initialize.call(this, map, feature, options);
this._deleteLatLng = this._computeDeleteLatLng();
@ -643,7 +643,7 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
this.editLayer = new L.FeatureGroup();
},
addHooks: function () {
addHooks() {
L.Editable.CircleEditor.prototype.addHooks.call(this);
if (this.feature) {
this._addDeleteMarker();
@ -651,12 +651,12 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
return this;
},
reset: function () {
reset() {
L.Editable.CircleEditor.prototype.reset.call(this);
this._addDeleteMarker();
},
onDrawingMouseDown: function (e) {
onDrawingMouseDown(e) {
this._deleteLatLng.update(e.latlng);
L.Editable.CircleEditor.prototype.onDrawingMouseDown.call(this, e);
},
@ -664,7 +664,7 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
// override to cancel/remove created circle when added by click instead of drag, because:
// - without resize, edit handles stacked on top of each other
// - makes event handling more complicated (editable:vertex:dragend not called)
onDrawingMouseUp: function (e) {
onDrawingMouseUp(e) {
if (this.feature.getRadius() > 0) {
this.commitDrawing(e);
} else {
@ -675,7 +675,7 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
L.Editable.PathEditor.prototype.onDrawingMouseUp.call(this, e);
},
onVertexMarkerDrag: function (e) {
onVertexMarkerDrag(e) {
this._updateDeleteLatLng();
L.Editable.CircleEditor.prototype.onVertexMarkerDrag.call(this, e);
},
@ -690,7 +690,7 @@ BR.DeleteMarker = L.Marker.extend({
}),
},
initialize: function (latlng, editor, options) {
initialize(latlng, editor, options) {
// derived from L.Editable.VertexMarker.initialize
// We don't use this._latlng, because on drag Leaflet replace it while
@ -707,18 +707,18 @@ BR.DeleteMarker = L.Marker.extend({
this.setZIndexOffset(editor.tools._lastZIndex);
},
onAdd: function (map) {
onAdd(map) {
L.Marker.prototype.onAdd.call(this, map);
this.on('click', this.onClick);
},
onRemove: function (map) {
onRemove(map) {
delete this.latlng.__vertex;
this.off('click', this.onClick);
L.Marker.prototype.onRemove.call(this, map);
},
onClick: function (e) {
onClick(e) {
this.editor.delete();
},
});

View file

@ -10,12 +10,12 @@ BR.PoiMarkers = L.Control.extend({
},
},
},
initialize: function (routing) {
initialize(routing) {
this.routing = routing;
this.circlego = null;
},
onAdd: function (map) {
onAdd(map) {
var self = this;
this.map = map;
@ -26,7 +26,7 @@ BR.PoiMarkers = L.Control.extend({
{
stateName: 'activate-poi',
icon: 'fa-hand-o-right',
onClick: function () {
onClick() {
self.draw(true);
},
title: i18next.t('keyboard.generic-shortcut', { action: '$t(map.draw-poi-start)', key: 'P' }),
@ -34,7 +34,7 @@ BR.PoiMarkers = L.Control.extend({
{
stateName: 'deactivate-poi',
icon: 'fa-hand-o-right active',
onClick: function () {
onClick() {
self.draw(false);
},
title: i18next.t('keyboard.generic-shortcut', {
@ -55,7 +55,7 @@ BR.PoiMarkers = L.Control.extend({
return container;
},
draw: function (enable) {
draw(enable) {
this.drawButton.state(enable ? 'deactivate-poi' : 'activate-poi');
if (enable) {
this.routing.draw(false);
@ -68,7 +68,7 @@ BR.PoiMarkers = L.Control.extend({
}
},
_keydownListener: function (e) {
_keydownListener(e) {
if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
@ -79,13 +79,13 @@ BR.PoiMarkers = L.Control.extend({
}
},
onMapClick: function (e) {
onMapClick(e) {
var self = this;
bootbox.prompt({
title: i18next.t('map.enter-poi-name'),
// allow empty name with client-side formatting
required: !BR.Browser.download,
callback: function (result) {
callback(result) {
if (result !== null) {
self.addMarker(e.latlng, result);
}
@ -93,7 +93,7 @@ BR.PoiMarkers = L.Control.extend({
});
},
addMarker: function (latlng, name) {
addMarker(latlng, name) {
var icon = L.VectorMarkers.icon({
icon: 'star',
markerColor: BR.conf.markerColors.poi,
@ -107,7 +107,7 @@ BR.PoiMarkers = L.Control.extend({
'<p><button id="remove-poi-marker" class="btn btn-secondary"><i class="fa fa-trash"></i></button></p>';
var self = this;
var marker = L.marker(latlng, { icon: icon, draggable: true, name: name })
var marker = L.marker(latlng, { icon, draggable: true, name })
.bindPopup(contentWithAction)
.on('dragend', function () {
self.fire('update');
@ -132,11 +132,11 @@ BR.PoiMarkers = L.Control.extend({
}
},
clear: function () {
clear() {
this.markersLayer.clearLayers();
},
setMarkers: function (latLngNames) {
setMarkers(latLngNames) {
this.clear();
if (!latLngNames) return;
@ -147,7 +147,7 @@ BR.PoiMarkers = L.Control.extend({
}
},
getMarkers: function () {
getMarkers() {
return this.markersLayer.getLayers().map(function (it) {
return {
latlng: it.getLatLng(),

View file

@ -20,7 +20,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
},
},
setDialogDraggable: function (jqDlgHeader) {
setDialogDraggable(jqDlgHeader) {
jqDlgHeader.on('mousedown', function (mousedownEvt) {
var $draggable = $(this);
var x = mousedownEvt.pageX - $draggable.offset().left,
@ -40,15 +40,15 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
});
},
getSimplifiedCoords: function (tolerance) {
getSimplifiedCoords(tolerance) {
var simplifiedLine = turf.simplify(this._trackPoints.geometry, {
tolerance: tolerance,
tolerance,
highQuality: true,
});
return simplifiedLine.coordinates;
},
refreshTestLayer: function () {
refreshTestLayer() {
this.onBusyChanged(true);
this._testLayer.clearLayers();
@ -73,7 +73,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
return true;
},
cleanup: function (e) {
cleanup(e) {
this._testLayer.clearLayers();
if (
this._trackLayer &&
@ -98,7 +98,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
};
},
setSliderRange: function () {
setSliderRange() {
$slider = $('#simplify_tolerance');
$slider.prop('min', -500);
var guessedTolerance = this.guessSimplifyTolerance(this._trackPoints);
@ -116,7 +116,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
this.refreshTestLayer();
},
onToleranceSlider: function (e) {
onToleranceSlider(e) {
var guess = parseFloat($(e.target).data('guess'));
var f = parseFloat(e.target.value);
var frac = parseFloat($(e.target).prop('max'));
@ -145,7 +145,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
}
},
findLowestTolerance: function (min, max, guess, frac) {
findLowestTolerance(min, max, guess, frac) {
if (Math.abs(max - min) <= 2) return max;
var meridian = Math.round((max + min) / 2);
@ -157,7 +157,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
else return this.findLowestTolerance(min, meridian, guess, frac);
},
onBusyChanged: function (isBusy) {
onBusyChanged(isBusy) {
if (typeof isBusy === undefined) {
isBusy = false;
}
@ -165,7 +165,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
else $('#loadedittrack #msg_busy').addClass('invisible');
},
onManualCollapse: function (e) {
onManualCollapse(e) {
//workaround for starting with closed collapse
if ($('#loadedittrack').is(':hidden')) return;
this._options.isTestMode = $(e.target).hasClass('show');
@ -176,7 +176,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
} else this.cleanup();
},
onAdd: function (map) {
onAdd(map) {
$('#loadedittrack').on(
'hidden.bs.modal',
function (e) {
@ -238,11 +238,11 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
return dummy;
},
onRemove: function (map) {
onRemove(map) {
// Nothing to do here
},
onFileChanged: function (e) {
onFileChanged(e) {
if (!e.target.files[0]) return;
$(e.target).next('label').text(e.target.files[0].name);
var testmode = this._options.isTestMode;
@ -254,7 +254,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
}
},
setLayerNameFromGeojson: function (geoJSON) {
setLayerNameFromGeojson(geoJSON) {
if (geoJSON.type == 'Feature' && geoJSON.properties && geoJSON.properties.name) {
this._layerName = geoJSON.properties.name;
return;
@ -270,7 +270,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
}
},
getOptions: function () {
getOptions() {
this._options.showTrackLayer = $('#cb_showtracklayer')[0].checked;
this._options.showPointAsPoi = $('#cb_showpois')[0].checked;
@ -278,7 +278,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
this._bounds = undefined;
},
convertTrackLocal: function () {
convertTrackLocal() {
if ($('#loadedittrackFile')[0].files.length == 0) return;
this.onBusyChanged(true);
@ -295,7 +295,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
reader.readAsText(trackFile);
},
addTrackOverlay: function (geoJSON) {
addTrackOverlay(geoJSON) {
this._trackLayer = L.geoJSON(geoJSON, BR.Track.getGeoJsonOptions(layersControl, true)).addTo(map);
layersControl.addOverlay(this._trackLayer, BR.Util.sanitizeHTMLContent(this._layerName));
@ -305,7 +305,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
if (this._bounds) map.fitBounds(this._bounds);
},
getLineStringsFromGeoJSON: function (geoJSON) {
getLineStringsFromGeoJSON(geoJSON) {
var allLinePoints = [];
var flat = turf.flatten(geoJSON);
turf.featureEach(flat, function (feature, idx) {
@ -321,13 +321,13 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
return linesGeoJSON;
},
guessSimplifyTolerance: function (trackPoints) {
guessSimplifyTolerance(trackPoints) {
var tolerance = trackPoints.length / 1000000;
if (tolerance > 0.8) tolerance = 0.8;
return tolerance;
},
addRoutingPoints: function (geoJSON) {
addRoutingPoints(geoJSON) {
if (this._options.simplifyTolerance < 0)
this._options.simplifyTolerance = this.guessSimplifyTolerance(this._trackPoints);
@ -361,7 +361,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
}
},
processFile: function (e) {
processFile(e) {
var res = e.target.result;
var geoJSON = null;
switch (this._options.format) {
@ -391,7 +391,7 @@ BR.routeLoader = function (map, layersControl, routing, pois) {
this.onBusyChanged(false);
},
keydownListener: function (e) {
keydownListener(e) {
if (
BR.Util.keyboardShortcutsAllowed(e) &&
e.keyCode === this._options.shortcut.open &&

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;

View file

@ -6,7 +6,7 @@ BR.RoutingPathQuality = L.Control.extend({
},
},
initialize: function (map, layersControl, options) {
initialize(map, layersControl, options) {
L.setOptions(this, options);
// hotline uses canvas and cannot be moved in front of the svg, so we create another pane
@ -35,9 +35,9 @@ BR.RoutingPathQuality = L.Control.extend({
1.0: '#ff0000', // red
},
outlineColor: 'dimgray',
renderer: renderer,
renderer,
},
valueFunction: function (latLng, prevLatLng) {
valueFunction(latLng, prevLatLng) {
var deltaAltitude = latLng.alt - prevLatLng.alt, // in m
distance = prevLatLng.distanceTo(latLng); // in m
if (distance === 0) {
@ -53,9 +53,9 @@ BR.RoutingPathQuality = L.Control.extend({
provider: new HotLineQualityProvider({
hotlineOptions: {
outlineColor: 'dimgray',
renderer: renderer,
renderer,
},
valueFunction: function (latLng) {
valueFunction(latLng) {
return latLng.alt;
},
}),
@ -65,7 +65,7 @@ BR.RoutingPathQuality = L.Control.extend({
icon: 'fa-road',
provider: new HotLineQualityProvider({
hotlineOptions: {
renderer: renderer,
renderer,
palette: {
// normal range
0.0: 'red',
@ -229,9 +229,9 @@ BR.RoutingPathQuality = L.Control.extend({
// disables line simplification, so short segments won't disappear on some zoom levels
smoothFactor: 0,
outlineColor: 'dimgray',
renderer: renderer,
renderer,
},
valueFunction: function (latLng) {
valueFunction(latLng) {
var feature = latLng.feature;
var cost = feature.cost.perKm;
var distance = feature.distance / 1000; // in km
@ -252,7 +252,7 @@ BR.RoutingPathQuality = L.Control.extend({
this._muted = false;
},
onAdd: function (map) {
onAdd(map) {
this._map = map;
map.on(
@ -311,28 +311,28 @@ BR.RoutingPathQuality = L.Control.extend({
}
this.routingPathButton = new L.easyButton({
states: states,
states,
}).addTo(map);
return new L.DomUtil.create('div');
},
_activate: function (btn) {
_activate(btn) {
this._active = true;
this._getIcon(btn).classList.add('active');
this._routingSegments.addTo(this._map);
},
_deactivate: function (btn) {
_deactivate(btn) {
this._active = false;
this._getIcon(btn).classList.remove('active');
this._map.removeLayer(this._routingSegments);
},
_getIcon: function (btn) {
_getIcon(btn) {
return btn.button.firstChild.firstChild;
},
update: function (track, layer) {
update(track, layer) {
var segments = [];
layer.eachLayer(function (layer) {
segments.push(layer);
@ -341,12 +341,12 @@ BR.RoutingPathQuality = L.Control.extend({
this._update(this.segments);
},
setProvider: function (provider) {
setProvider(provider) {
this.selectedProvider = provider;
this._update(this.segments);
},
_update: function (segments) {
_update(segments) {
this._routingSegments.clearLayers();
var layers = this.providers[this.selectedProvider].provider.computeLayers(segments);
if (layers) {
@ -356,7 +356,7 @@ BR.RoutingPathQuality = L.Control.extend({
}
},
_keydownListener: function (e) {
_keydownListener(e) {
if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
@ -369,7 +369,7 @@ BR.RoutingPathQuality = L.Control.extend({
}
},
_keyupListener: function (e) {
_keyupListener(e) {
if (BR.Util.keyboardShortcutsAllowed(e) && this._muted && e.keyCode === this.options.shortcut.muteKeyCode) {
this._muted = false;
this._activate(this.routingPathButton);
@ -378,12 +378,12 @@ BR.RoutingPathQuality = L.Control.extend({
});
var HotLineQualityProvider = L.Class.extend({
initialize: function (options) {
initialize(options) {
this.hotlineOptions = options.hotlineOptions;
this.valueFunction = options.valueFunction;
},
computeLayers: function (segments) {
computeLayers(segments) {
var layers = [];
if (segments) {
var segmentLatLngs = [];
@ -415,7 +415,7 @@ var HotLineQualityProvider = L.Class.extend({
return layers;
},
_computeLatLngVals: function (segment) {
_computeLatLngVals(segment) {
var latLngVals = [],
segmentLatLngs = segment.getLatLngs(),
segmentLength = segmentLatLngs.length;
@ -433,11 +433,11 @@ var HotLineQualityProvider = L.Class.extend({
return latLngVals;
},
_convertToArray: function (latLng, val) {
_convertToArray(latLng, val) {
return [latLng.lat, latLng.lng, val];
},
_calcMinMaxValues: function (lines, pct) {
_calcMinMaxValues(lines, pct) {
lines.sort(function (a, b) {
return a[2] - b[2];
});
@ -447,8 +447,8 @@ var HotLineQualityProvider = L.Class.extend({
max = min + 1;
}
return {
min: min,
max: max,
min,
max,
};
},
});

View file

@ -17,7 +17,7 @@ BR.Sidebar = L.Control.Sidebar.extend({
listeningTabs: {},
},
initialize: function (id, options) {
initialize(id, options) {
L.Control.Sidebar.prototype.initialize.call(this, id, options);
this.oldTab = null;
@ -25,7 +25,7 @@ BR.Sidebar = L.Control.Sidebar.extend({
L.DomEvent.addListener(document, 'keydown', this._keydownListener, this);
},
addTo: function (map) {
addTo(map) {
L.Control.Sidebar.prototype.addTo.call(this, map);
this.on('content', this._notifyOnContent, this);
@ -59,14 +59,14 @@ BR.Sidebar = L.Control.Sidebar.extend({
return this;
},
showPanel: function (id) {
showPanel(id) {
var tab = this._getTab(id);
tab.hidden = false;
return this;
},
_rememberTabState: function () {
_rememberTabState() {
if (BR.Util.localStorageAvailable()) {
this.on('content closing', this._storeActiveTab, this);
@ -85,42 +85,42 @@ BR.Sidebar = L.Control.Sidebar.extend({
}
},
_notifyShow: function (tab) {
_notifyShow(tab) {
if (tab && tab.show) {
tab.show();
}
},
_notifyHide: function (tab) {
_notifyHide(tab) {
if (tab && tab.hide) {
tab.hide();
}
},
_notifyOnContent: function (e) {
_notifyOnContent(e) {
var tab = this.options.listeningTabs[e.id];
this._notifyHide(this.oldTab);
this._notifyShow(tab);
this.oldTab = tab;
},
_notifyOnClose: function (e) {
_notifyOnClose(e) {
this._notifyHide(this.oldTab);
this.oldTab = null;
},
_notifyOnResize: function (e) {
_notifyOnResize(e) {
var tab = this.oldTab;
if (tab && tab.onResize) {
tab.onResize();
}
},
_storeActiveTab: function (e) {
_storeActiveTab(e) {
localStorage.setItem(this.storageId, e.id || '');
},
_keydownListener: function (e) {
_keydownListener(e) {
if (BR.Util.keyboardShortcutsAllowed(e) && e.keyCode === this.options.shortcut.toggleTabs) {
if ($('#sidebarTabs > ul > li[class=active]').length) {
// sidebar is currently open, close current tab

View file

@ -19,7 +19,7 @@ BR.tracksLoader = function (map, layersControl, routing, pois) {
},
},
_initContainer: function () {
_initContainer() {
var thisLoader = this.loader;
var fileInput;
@ -60,7 +60,7 @@ BR.tracksLoader = function (map, layersControl, routing, pois) {
return dummy;
},
_keydownListener: function (e) {
_keydownListener(e) {
if (
BR.Util.keyboardShortcutsAllowed(e) &&
e.keyCode === this.options.shortcut.open &&

View file

@ -24,7 +24,7 @@
*/
L.DistanceMarkers = L.LayerGroup.extend({
initialize: function (line, map, options) {
initialize(line, map, options) {
options = options || {};
var offset = options.offset || 1000;
var showAll = Math.min(map.getMaxZoom(), options.showAll || 12);
@ -69,7 +69,7 @@ L.DistanceMarkers = L.LayerGroup.extend({
// width as base number, one for padding + multiply by number of digits
var size = [iconSize[0] + iconSize[0] * ('' + text).length, iconSize[1]];
var icon = L.divIcon({ className: cssClass, html: text, iconSize: size });
var marker = L.marker(position.latLng, { title: text, icon: icon, interactive: false });
var marker = L.marker(position.latLng, { title: text, icon, interactive: false });
// visible only starting at a specific zoom level
var zoom = this._minimumZoomLevelForItem(i, showAll);
@ -106,7 +106,7 @@ L.DistanceMarkers = L.LayerGroup.extend({
updateMarkerVisibility();
},
setOpacity: function (opacity) {
setOpacity(opacity) {
var i,
keys = Object.keys(this._zoomLayers),
l = keys.length;
@ -119,7 +119,7 @@ L.DistanceMarkers = L.LayerGroup.extend({
}
},
_minimumZoomLevelForItem: function (item, showAllLevel) {
_minimumZoomLevelForItem(item, showAllLevel) {
var zoom = showAllLevel,
i = item;
while (i > 0 && i % 2 === 0) {

View file

@ -29,9 +29,9 @@
} else {
return {
center: new L.LatLng(lat, lon),
zoom: zoom,
layers: layers,
additional: additional,
zoom,
layers,
additional,
};
}
} else {
@ -65,7 +65,7 @@
parseHash: L.Hash.parseHash,
formatHash: L.Hash.formatHash,
init: function (map, options) {
init(map, options) {
this.map = map;
L.Util.setOptions(this, options);
@ -78,7 +78,7 @@
}
},
_parseLayers: function (layersParam, layerSeparator) {
_parseLayers(layersParam, layerSeparator) {
var layers = layersParam.split(layerSeparator).map(
L.bind(function (layerEncoded) {
var obj = null;
@ -95,7 +95,7 @@
return layers;
},
parseLayers: function (layersParam) {
parseLayers(layersParam) {
var countFoundLayers = function (count, obj) {
if (obj) {
count++;
@ -119,7 +119,7 @@
return layers;
},
activateLayers: function (layers) {
activateLayers(layers) {
var layersControl = this.options.layersControl;
var added = false;
@ -147,7 +147,7 @@
}
},
formatLayers: function () {
formatLayers() {
var objList = this.options.layersControl.getActiveLayers();
// exclude vector layers (loaded tracks), but not when id set (route quality coding)
objList = objList.filter(function (obj) {
@ -162,7 +162,7 @@
return layerList.join(this.options.layerSeparator);
},
removeFrom: function (map) {
removeFrom(map) {
if (this.changeTimeout) {
clearTimeout(this.changeTimeout);
}
@ -174,7 +174,7 @@
this.map = null;
},
onMapMove: function () {
onMapMove() {
// bail if we're moving the map (updating from a hash),
// or if the map is not yet loaded
@ -190,7 +190,7 @@
},
movingMap: false,
update: function () {
update() {
var hash = location.hash;
if (hash === this.lastHash) {
return;
@ -226,7 +226,7 @@
// defer hash change updates every 100ms
changeDefer: 100,
changeTimeout: null,
onHashChange: function () {
onHashChange() {
// throttle calls to update() so that they only happen every
// `changeDefer` ms
if (!this.changeTimeout) {
@ -240,7 +240,7 @@
isListening: false,
hashChangeInterval: null,
startListening: function () {
startListening() {
this.map.on('moveend layeradd layerremove', this.onMapMove, this);
if (HAS_HASHCHANGE) {
@ -252,7 +252,7 @@
this.isListening = true;
},
stopListening: function () {
stopListening() {
this.map.off('moveend layeradd layerremove', this.onMapMove, this);
if (HAS_HASHCHANGE) {
@ -263,7 +263,7 @@
this.isListening = false;
},
_keyByValue: function (obj, value) {
_keyByValue(obj, value) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] === value) {