Update prettier version

This commit is contained in:
Gautier P 2020-12-05 11:50:30 +01:00
parent c49b821db7
commit 25429b3c24
42 changed files with 2480 additions and 2490 deletions

View file

@ -3,9 +3,9 @@ BR.NogoAreas = L.Control.extend({
shortcut: {
draw: {
enable: 78, // char code for 'n'
disable: 27 // char code for 'ESC'
}
}
disable: 27, // char code for 'ESC'
},
},
},
statics: {
@ -16,7 +16,7 @@ BR.NogoAreas = L.Control.extend({
MSG_ENABLED:
'&square; = move / resize, <span class="fa fa-trash-o"></span> = delete,<br>click nogo to quit editing',
STATE_CREATE: 'no-go-create',
STATE_CANCEL: 'cancel-no-go-create'
STATE_CANCEL: 'cancel-no-go-create',
},
style: {
@ -25,27 +25,27 @@ BR.NogoAreas = L.Control.extend({
opacity: 0.5,
fillColor: null, //same as color by default
fillOpacity: 0.2,
dashArray: null
dashArray: null,
},
editStyle: {
color: '#fe57a1',
opacity: 0.6,
dashArray: '10, 10',
fillOpacity: 0.1
fillOpacity: 0.1,
},
initialize: function() {
initialize: function () {
this._wasRouteDrawing = false;
},
onAdd: function(map) {
onAdd: function (map) {
var self = this;
$('#submitNogos').on('click', L.bind(this.uploadNogos, this));
this.drawnItems = new L.FeatureGroup().addTo(map);
this.drawnItems.on('click', function(e) {
this.drawnItems.on('click', function (e) {
L.DomEvent.stop(e);
e.layer.toggleEdit();
});
@ -54,10 +54,10 @@ BR.NogoAreas = L.Control.extend({
circleEditorClass: BR.DeletableCircleEditor,
// FeatureGroup instead of LayerGroup to propagate events to members
editLayer: new L.FeatureGroup().addTo(map),
featuresLayer: this.drawnItems
featuresLayer: this.drawnItems,
}));
this.startDrawing = function(control) {
this.startDrawing = function (control) {
// initial radius of 0 to detect click, see DeletableCircleEditor.onDrawingMouseUp
var opts = L.extend({ radius: 0 }, self.style);
editTools.startCircle(null, opts);
@ -65,7 +65,7 @@ BR.NogoAreas = L.Control.extend({
control.state('cancel-no-go-create');
};
this.stopDrawing = function(control) {
this.stopDrawing = function (control) {
editTools.stopDrawing();
control.state('no-go-create');
};
@ -76,15 +76,15 @@ BR.NogoAreas = L.Control.extend({
stateName: BR.NogoAreas.STATE_CREATE,
icon: 'fa-ban',
title: BR.NogoAreas.MSG_BUTTON,
onClick: this.startDrawing
onClick: this.startDrawing,
},
{
stateName: BR.NogoAreas.STATE_CANCEL,
icon: 'fa-ban active',
title: BR.NogoAreas.MSG_BUTTON_CANCEL,
onClick: this.stopDrawing
}
]
onClick: this.stopDrawing,
},
],
});
// prevent instant re-activate when turning off button by both Pointer and Click
@ -95,11 +95,11 @@ BR.NogoAreas = L.Control.extend({
this.editTools.on(
'editable:drawing:end',
function(e) {
function (e) {
self.button.state(BR.NogoAreas.STATE_CREATE);
setTimeout(
L.bind(function() {
L.bind(function () {
// turn editing off after create; async to still fire 'editable:vertex:dragend'
e.layer.disableEdit();
}, this),
@ -111,7 +111,7 @@ BR.NogoAreas = L.Control.extend({
this.editTools.on(
'editable:vertex:dragend editable:deleted',
function(e) {
function (e) {
this._fireUpdate();
},
this
@ -119,14 +119,14 @@ BR.NogoAreas = L.Control.extend({
this.editTools.on(
'editable:enable',
function(e) {
function (e) {
e.layer.setStyle(this.editStyle);
},
this
);
this.editTools.on(
'editable:disable',
function(e) {
function (e) {
e.layer.setStyle(this.style);
},
this
@ -139,7 +139,7 @@ BR.NogoAreas = L.Control.extend({
return L.DomUtil.create('div');
},
_keydownListener: function(e) {
_keydownListener: function (e) {
if (!BR.Util.keyboardShortcutsAllowed(e)) {
return;
}
@ -153,12 +153,12 @@ BR.NogoAreas = L.Control.extend({
}
},
displayUploadError: function(message) {
displayUploadError: function (message) {
$('#nogoError').text(message ? message : '');
$('#nogoError').css('display', message ? 'block' : 'none');
},
uploadNogos: function() {
uploadNogos: function () {
var self = this;
var geoJSONPromise;
@ -170,21 +170,21 @@ BR.NogoAreas = L.Control.extend({
$('#nogoJSON').val(undefined);
} else if (nogoURL) {
// TODO: Handle {{bbox}}
geoJSONPromise = fetch(nogoURL).then(function(response) {
geoJSONPromise = fetch(nogoURL).then(function (response) {
response.json();
});
} else if (nogoFile) {
geoJSONPromise = new Promise(function(resolve, reject) {
geoJSONPromise = new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onload = function() {
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function() {
reader.onerror = function () {
self.displayUploadError('Could not load file: ' + reader.error.message);
};
reader.readAsText(nogoFile);
}).then(function(response) {
}).then(function (response) {
return JSON.parse(response);
});
} else {
@ -211,10 +211,10 @@ BR.NogoAreas = L.Control.extend({
return false;
}
geoJSONPromise.then(function(response) {
geoJSONPromise.then(function (response) {
// Iterate on features in order to discard features without geometry
var cleanedGeoJSONFeatures = [];
turf.flattenEach(response, function(feature) {
turf.flattenEach(response, function (feature) {
if (turf.getGeom(feature)) {
var maybeBufferedFeature = feature;
// Eventually buffer GeoJSON
@ -231,31 +231,31 @@ BR.NogoAreas = L.Control.extend({
}
var geoJSON = L.geoJson(turf.featureCollection(cleanedGeoJSONFeatures), {
onEachFeature: function(feature, layer) {
onEachFeature: function (feature, layer) {
layer.options.nogoWeight = feature.properties.nogoWeight || nogoWeight;
}
},
});
var nogosPoints = geoJSON.getLayers().filter(function(e) {
var nogosPoints = geoJSON.getLayers().filter(function (e) {
return e.feature.geometry.type === 'Point';
});
nogosPoints = nogosPoints.map(function(item) {
nogosPoints = nogosPoints.map(function (item) {
var radius = item.feature.properties.radius || nogoRadius;
if (radius > 0) {
return L.circle(item.getLatLng(), { radius: radius });
}
return null;
});
nogosPoints = nogosPoints.filter(function(e) {
nogosPoints = nogosPoints.filter(function (e) {
return e;
});
self.setOptions({
nogos: nogosPoints,
polygons: geoJSON.getLayers().filter(function(e) {
polygons: geoJSON.getLayers().filter(function (e) {
return e.feature.geometry.type === 'Polygon';
}),
polylines: geoJSON.getLayers().filter(function(e) {
polylines: geoJSON.getLayers().filter(function (e) {
return e.feature.geometry.type === 'LineString';
})
}),
});
self._fireUpdate();
self.displayUploadError(undefined);
@ -265,10 +265,10 @@ BR.NogoAreas = L.Control.extend({
},
// prevent route waypoint added after circle create (map click after up)
preventRoutePointOnCreate: function(routing) {
preventRoutePointOnCreate: function (routing) {
this.editTools.on(
'editable:drawing:start',
function(e) {
function (e) {
this._wasRouteDrawing = routing.isDrawing();
routing.draw(false);
},
@ -278,9 +278,9 @@ BR.NogoAreas = L.Control.extend({
// after create
this.editTools.on(
'editable:drawing:end',
function(e) {
function (e) {
if (this._wasRouteDrawing) {
setTimeout(function() {
setTimeout(function () {
routing.draw(true);
}, 0);
}
@ -289,21 +289,21 @@ BR.NogoAreas = L.Control.extend({
);
},
getOptions: function() {
getOptions: function () {
return {
nogos: this.drawnItems.getLayers().filter(function(e) {
nogos: this.drawnItems.getLayers().filter(function (e) {
return e instanceof L.Circle;
}),
polygons: this.drawnItems.getLayers().filter(function(e) {
polygons: this.drawnItems.getLayers().filter(function (e) {
return e instanceof L.Polygon;
}),
polylines: this.drawnItems.getLayers().filter(function(e) {
polylines: this.drawnItems.getLayers().filter(function (e) {
return e instanceof L.Polyline && !(e instanceof L.Polygon);
})
}),
};
},
setOptions: function(options) {
setOptions: function (options) {
var nogos = options.nogos;
var polylines = options.polylines;
var polygons = options.polygons;
@ -328,30 +328,30 @@ BR.NogoAreas = L.Control.extend({
}
},
_clear: function() {
_clear: function () {
this.drawnItems.clearLayers();
},
clear: function() {
clear: function () {
this._clear();
this._fireUpdate();
},
_fireUpdate: function() {
_fireUpdate: function () {
this.fire('update', { options: this.getOptions() });
},
getFeatureGroup: function() {
getFeatureGroup: function () {
return this.drawnItems;
},
getEditGroup: function() {
getEditGroup: function () {
return this.editTools.editLayer;
},
getButton: function() {
getButton: function () {
return this.button;
}
},
});
BR.NogoAreas.include(L.Evented.prototype);
@ -363,7 +363,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: function (map, options) {
L.Editable.prototype.initialize.call(this, map, options);
if (!this.map.tap) {
@ -372,7 +372,7 @@ BR.Editable = L.Editable.extend({
}
},
registerForDrawing: function(editor) {
registerForDrawing: function (editor) {
this._tapEnabled = this.map.tap.enabled();
if (!this._tapEnabled) {
this.map.tap.enable();
@ -381,7 +381,7 @@ BR.Editable = L.Editable.extend({
L.Editable.prototype.registerForDrawing.call(this, editor);
},
unregisterForDrawing: function(editor) {
unregisterForDrawing: function (editor) {
if (!this._tapEnabled) {
this.map.tap.disable();
}
@ -389,23 +389,23 @@ BR.Editable = L.Editable.extend({
L.Editable.prototype.unregisterForDrawing.call(this, editor);
},
createVertexIcon: function(options) {
createVertexIcon: function (options) {
return BR.Browser.touch ? new L.Editable.TouchVertexIcon(options) : new L.Editable.VertexIcon(options);
}
},
});
BR.EditingTooltip = L.Handler.extend({
options: {
closeTimeout: 2000
closeTimeout: 2000,
},
initialize: function(map, editTools, button) {
initialize: function (map, editTools, button) {
this.map = map;
this.editTools = editTools;
this.button = button;
},
addHooks: function() {
addHooks: function () {
// 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);
@ -417,7 +417,7 @@ BR.EditingTooltip = L.Handler.extend({
this.editTools.on('editable:disable', this._disable, this);
},
removeHooks: function() {
removeHooks: function () {
L.DomEvent.removeListener(this.button.button, 'click', this._addCreate, this);
this.editTools.featuresLayer.off('layeradd', this._bind, this);
@ -427,19 +427,19 @@ BR.EditingTooltip = L.Handler.extend({
this.editTools.off('editable:disable', this._disable, this);
},
_bind: function(e) {
_bind: function (e) {
// Position tooltip at bottom of circle, less distracting than
// sticky with cursor or at center.
var layer = e.layer;
layer.bindTooltip(BR.NogoAreas.MSG_DISABLED, {
direction: 'bottom',
className: 'editing-tooltip'
className: 'editing-tooltip',
});
// Override to set position to south instead of center (circle latlng);
// works better with zooming than updating offset to match radius
layer.openTooltip = function(layer, latlng) {
layer.openTooltip = function (layer, latlng) {
if (!latlng && layer instanceof L.Layer) {
latlng = L.latLng(
layer.getBounds().getSouth(),
@ -450,7 +450,7 @@ BR.EditingTooltip = L.Handler.extend({
};
},
_addCreate: function(e) {
_addCreate: function (e) {
// button cancel
if (!this.editTools.drawing()) return;
@ -461,21 +461,21 @@ BR.EditingTooltip = L.Handler.extend({
// offset wrong with 'auto' when switching direction
direction: 'right',
offset: L.point(5, 28),
className: 'editing-tooltip-create'
className: 'editing-tooltip-create',
});
// self-reference hack for _moveTooltip, as tooltip is not bound to layer
tooltip._tooltip = tooltip;
// simulate sticky feature (follow mouse) for map tooltip without layer
var onOffMove = function(e) {
var onOffMove = function (e) {
var onOff = e.type === 'tooltipclose' ? 'off' : 'on';
this._map[onOff]('mousemove', this._moveTooltip, this);
};
this.map.on('tooltipopen', onOffMove, tooltip);
this.map.on('tooltipclose', onOffMove, tooltip);
var onTooltipRemove = function(e) {
var onTooltipRemove = function (e) {
this.map.off('tooltipopen', onOffMove, e.tooltip);
this.map.off('tooltipclose', onOffMove, e.tooltip);
this.map.off('tooltipclose', onTooltipRemove, this);
@ -486,7 +486,7 @@ BR.EditingTooltip = L.Handler.extend({
tooltip.setTooltipContent(BR.NogoAreas.MSG_CREATE);
this.map.openTooltip(tooltip, initialLatLng);
var closeTooltip = function() {
var closeTooltip = function () {
this.map.closeTooltip(tooltip);
};
this.editTools.once('editable:editing editable:drawing:cancel', closeTooltip, this);
@ -497,22 +497,22 @@ BR.EditingTooltip = L.Handler.extend({
}
},
_setCloseTimeout: function(layer) {
var timeoutId = setTimeout(function() {
_setCloseTimeout: function (layer) {
var timeoutId = setTimeout(function () {
layer.closeTooltip();
}, this.options.closeTimeout);
// prevent timer to close tooltip that changed in the meantime
layer.once('tooltipopen', function(e) {
layer.once('tooltipopen', function (e) {
clearTimeout(timeoutId);
});
},
_postCreate: function() {
_postCreate: function () {
// editing is disabled by another handler, tooltip won't stay open before
this.editTools.once(
'editable:disable',
function(e) {
function (e) {
// show for a few seconds, as mouse often not hovering circle after create
e.layer.openTooltip(e.layer);
this._setCloseTimeout(e.layer);
@ -521,54 +521,54 @@ BR.EditingTooltip = L.Handler.extend({
);
},
_enable: function(e) {
_enable: function (e) {
e.layer.setTooltipContent(BR.NogoAreas.MSG_ENABLED);
this.editTools.once(
'editable:editing',
function(e) {
function (e) {
e.layer.closeTooltip();
},
this
);
},
_disable: function(e) {
_disable: function (e) {
e.layer.setTooltipContent(BR.NogoAreas.MSG_DISABLED);
this._setCloseTimeout(e.layer);
}
},
});
BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
_computeDeleteLatLng: function() {
_computeDeleteLatLng: function () {
// 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: function () {
this._deleteLatLng.update(this._computeDeleteLatLng());
this._deleteLatLng.__vertex.update();
},
_addDeleteMarker: function() {
_addDeleteMarker: function () {
if (!this.enabled()) return;
this._deleteLatLng = this._computeDeleteLatLng();
return new BR.DeleteMarker(this._deleteLatLng, this);
},
_delete: function() {
_delete: function () {
this.disable();
this.tools.featuresLayer.removeLayer(this.feature);
},
delete: function() {
delete: function () {
this._delete();
this.fireAndForward('editable:deleted');
},
initialize: function(map, feature, options) {
initialize: function (map, feature, options) {
L.Editable.CircleEditor.prototype.initialize.call(this, map, feature, options);
this._deleteLatLng = this._computeDeleteLatLng();
@ -576,7 +576,7 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
this.editLayer = new L.FeatureGroup();
},
addHooks: function() {
addHooks: function () {
L.Editable.CircleEditor.prototype.addHooks.call(this);
if (this.feature) {
this._addDeleteMarker();
@ -584,12 +584,12 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
return this;
},
reset: function() {
reset: function () {
L.Editable.CircleEditor.prototype.reset.call(this);
this._addDeleteMarker();
},
onDrawingMouseDown: function(e) {
onDrawingMouseDown: function (e) {
this._deleteLatLng.update(e.latlng);
L.Editable.CircleEditor.prototype.onDrawingMouseDown.call(this, e);
},
@ -597,7 +597,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: function (e) {
if (this.feature.getRadius() > 0) {
this.commitDrawing(e);
} else {
@ -608,10 +608,10 @@ BR.DeletableCircleEditor = L.Editable.CircleEditor.extend({
L.Editable.PathEditor.prototype.onDrawingMouseUp.call(this, e);
},
onVertexMarkerDrag: function(e) {
onVertexMarkerDrag: function (e) {
this._updateDeleteLatLng();
L.Editable.CircleEditor.prototype.onVertexMarkerDrag.call(this, e);
}
},
});
BR.DeleteMarker = L.Marker.extend({
@ -619,11 +619,11 @@ BR.DeleteMarker = L.Marker.extend({
draggable: false,
icon: L.divIcon({
iconSize: BR.Browser.touch ? new L.Point(24, 24) : new L.Point(16, 16),
className: 'leaflet-div-icon fa fa-trash-o nogo-delete-marker'
})
className: 'leaflet-div-icon fa fa-trash-o nogo-delete-marker',
}),
},
initialize: function(latlng, editor, options) {
initialize: function (latlng, editor, options) {
// derived from L.Editable.VertexMarker.initialize
// We don't use this._latlng, because on drag Leaflet replace it while
@ -640,18 +640,18 @@ BR.DeleteMarker = L.Marker.extend({
this.setZIndexOffset(editor.tools._lastZIndex);
},
onAdd: function(map) {
onAdd: function (map) {
L.Marker.prototype.onAdd.call(this, map);
this.on('click', this.onClick);
},
onRemove: function(map) {
onRemove: function (map) {
delete this.latlng.__vertex;
this.off('click', this.onClick);
L.Marker.prototype.onRemove.call(this, map);
},
onClick: function(e) {
onClick: function (e) {
this.editor.delete();
}
},
});