refact: use shorthand method and property syntax
This commit is contained in:
parent
babd154596
commit
76f31aeb2b
44 changed files with 520 additions and 514 deletions
|
|
@ -15,16 +15,16 @@ BR.ClickTolerantBoxZoom = L.Map.BoxZoom.extend({
|
|||
// already signals dragging to map and thus prevents click
|
||||
_preMoved: false,
|
||||
|
||||
moved: function () {
|
||||
moved() {
|
||||
return this._preMoved || this._moved;
|
||||
},
|
||||
|
||||
_resetState: function () {
|
||||
_resetState() {
|
||||
L.Map.BoxZoom.prototype._resetState.call(this);
|
||||
this._preMoved = false;
|
||||
},
|
||||
|
||||
_onMouseMove: function (e) {
|
||||
_onMouseMove(e) {
|
||||
if (!this._moved) {
|
||||
const point = this._map.mouseEventToContainerPoint(e);
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ BR.ClickTolerantBoxZoom = L.Map.BoxZoom.extend({
|
|||
L.Map.BoxZoom.prototype._onMouseMove.call(this, e);
|
||||
},
|
||||
|
||||
_onMouseUp: function (e) {
|
||||
_onMouseUp(e) {
|
||||
L.Map.BoxZoom.prototype._onMouseUp.call(this, e);
|
||||
|
||||
if (!this._moved && this._preMoved) {
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@
|
|||
* Only load Maplibre bundles when layer is actually added, using dynamic imports
|
||||
*/
|
||||
BR.MaplibreGlLazyLoader = L.Layer.extend({
|
||||
initialize: function (options) {
|
||||
initialize(options) {
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
onAdd: function (map) {
|
||||
onAdd(map) {
|
||||
if (!('maplibreGL' in L)) {
|
||||
this._load();
|
||||
} else {
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
onRemove: function (map) {
|
||||
onRemove(map) {
|
||||
if (this.glLayer) {
|
||||
this._map.removeLayer(this.glLayer);
|
||||
}
|
||||
|
|
@ -55,12 +55,12 @@
|
|||
},
|
||||
|
||||
// needed when overlay, also requires `position: absolute` (see css)
|
||||
setZIndex: function (zIndex) {
|
||||
setZIndex(zIndex) {
|
||||
this.options.zIndex = zIndex;
|
||||
return this;
|
||||
},
|
||||
|
||||
setOpacity: function (opacity) {
|
||||
setOpacity(opacity) {
|
||||
if (this.glLayer) {
|
||||
const glMap = this.glLayer.getMaplibreMap();
|
||||
if (glMap.getLayer('hillshading')) {
|
||||
|
|
@ -71,14 +71,14 @@
|
|||
}
|
||||
},
|
||||
|
||||
_load: async function () {
|
||||
async _load() {
|
||||
await importPolyfill('./maplibre-gl.js');
|
||||
await importPolyfill('./leaflet-maplibre-gl.js');
|
||||
|
||||
this._addGlLayer();
|
||||
},
|
||||
|
||||
_addGlLayer: function () {
|
||||
_addGlLayer() {
|
||||
this.glLayer = L.maplibreGL(this.options);
|
||||
// see LayersConfig.createLayer
|
||||
this.glLayer.getAttribution = function () {
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
this._updateZIndex();
|
||||
},
|
||||
|
||||
_updateZIndex: function () {
|
||||
_updateZIndex() {
|
||||
if (this.glLayer && this.glLayer.getContainer() && this.options.zIndex != null) {
|
||||
this.glLayer.getContainer().style.zIndex = this.options.zIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ BR.Track = {
|
|||
*
|
||||
* @returns {Object} to pass as `options` parameter to `L.geoJson`
|
||||
*/
|
||||
getGeoJsonOptions: function (layersControl, filterPois = false) {
|
||||
getGeoJsonOptions(layersControl, filterPois = false) {
|
||||
// https://github.com/mapbox/simplestyle-spec/tree/master/1.1.0
|
||||
const styleMapping = [
|
||||
['stroke', 'color'],
|
||||
|
|
@ -20,7 +20,7 @@ BR.Track = {
|
|||
['fill-opacity', 'fillOpacity'],
|
||||
];
|
||||
return {
|
||||
style: function (geoJsonFeature) {
|
||||
style(geoJsonFeature) {
|
||||
var currentLayerId = layersControl?.getActiveBaseLayer().layer.id;
|
||||
const featureStyle = {
|
||||
color: currentLayerId === 'cyclosm' ? 'yellow' : 'blue',
|
||||
|
|
@ -34,14 +34,14 @@ BR.Track = {
|
|||
return featureStyle;
|
||||
},
|
||||
interactive: false,
|
||||
filter: function (geoJsonFeature) {
|
||||
filter(geoJsonFeature) {
|
||||
if (filterPois) {
|
||||
// remove POIs, added separately, see `addPoiMarkers`
|
||||
return !BR.Track.isPoiPoint(geoJsonFeature);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
pointToLayer: function (geoJsonPoint, latlng) {
|
||||
pointToLayer(geoJsonPoint, latlng) {
|
||||
// route waypoint (type=from/via/to)
|
||||
return L.marker(latlng, {
|
||||
interactive: false,
|
||||
|
|
@ -60,7 +60,7 @@ BR.Track = {
|
|||
* @param {BR.PoiMarkers} pois POI control instance
|
||||
* @param {Object} geoJson GeoJSON object
|
||||
*/
|
||||
addPoiMarkers: function (pois, geoJson) {
|
||||
addPoiMarkers(pois, geoJson) {
|
||||
turf.featureEach(geoJson, function (feature, idx) {
|
||||
if (BR.Track.isPoiPoint(feature)) {
|
||||
var coord = turf.getCoord(feature);
|
||||
|
|
@ -80,7 +80,7 @@ BR.Track = {
|
|||
*
|
||||
* @param {Object} geoJsonPointFeature GeoJSON Point feature
|
||||
*/
|
||||
isRouteWaypoint: function (geoJsonPointFeature) {
|
||||
isRouteWaypoint(geoJsonPointFeature) {
|
||||
var props = geoJsonPointFeature.properties;
|
||||
if (props && props.type) {
|
||||
var wptType = props.type;
|
||||
|
|
@ -96,7 +96,7 @@ BR.Track = {
|
|||
*
|
||||
* @param {Object} geoJsonFeature GeoJSON feature
|
||||
*/
|
||||
isPoiPoint: function (geoJsonFeature) {
|
||||
isPoiPoint(geoJsonFeature) {
|
||||
return turf.getType(geoJsonFeature) === 'Point' && !BR.Track.isRouteWaypoint(geoJsonFeature);
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
BR.TrackEdges = L.Class.extend({
|
||||
statics: {
|
||||
getFeature: function (featureMessage) {
|
||||
getFeature(featureMessage) {
|
||||
//["Longitude", "Latitude", "Elevation", "Distance", "CostPerKm", "ElevCost", "TurnCost", "NodeCost", "InitialCost", "WayTags", "NodeTags"]
|
||||
return {
|
||||
cost: {
|
||||
|
|
@ -35,7 +35,7 @@ BR.TrackEdges = L.Class.extend({
|
|||
/**
|
||||
* @param {Array} segments
|
||||
*/
|
||||
initialize: function (segments) {
|
||||
initialize(segments) {
|
||||
this.edges = this.getTrackEdges(segments);
|
||||
},
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ BR.TrackEdges = L.Class.extend({
|
|||
*
|
||||
* @return {number[]}
|
||||
*/
|
||||
getTrackEdges: function (segments) {
|
||||
getTrackEdges(segments) {
|
||||
var messages,
|
||||
segLatLngs,
|
||||
length,
|
||||
|
|
@ -88,7 +88,7 @@ BR.TrackEdges = L.Class.extend({
|
|||
return edges;
|
||||
},
|
||||
|
||||
getMessageLatLng: function (message) {
|
||||
getMessageLatLng(message) {
|
||||
var lon = message[0] / 1000000,
|
||||
lat = message[1] / 1000000;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue