Skip to content

Commit

Permalink
Var to const
Browse files Browse the repository at this point in the history
  • Loading branch information
w8r committed Feb 15, 2024
1 parent 133850e commit affc541
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 49 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"L": true
},
"rules": {
"prefer-const": 2,
"yoda": 0,
"block-scoped-var": 2,
"camelcase": 1,
Expand Down
14 changes: 7 additions & 7 deletions src/Canvas.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ Canvas.include({
* @param {Array.<Number>} matrix
*/
transformPath: function (layer, matrix) {
var copy = this._containerCopy;
var ctx = this._ctx,
copyCtx;
var m = Browser.retina ? 2 : 1;
var bounds = this._bounds;
var size = bounds.getSize();
var pos = bounds.min;
let copy = this._containerCopy;
const ctx = this._ctx;
let copyCtx;
const m = Browser.retina ? 2 : 1;
const bounds = this._bounds;
const size = bounds.getSize();
const pos = bounds.min;

if (!copy) {
// get copy of all rendered layers
Expand Down
58 changes: 29 additions & 29 deletions src/Path.Drag.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import {
LatLngBounds,
} from 'leaflet';

var END = {
const END = {
mousedown: 'mouseup',
touchstart: 'touchend',
pointerdown: 'touchend',
MSPointerDown: 'touchend',
};

var MOVE = {
const MOVE = {
mousedown: 'mousemove',
touchstart: 'touchmove',
pointerdown: 'touchmove',
MSPointerDown: 'touchmove',
};

function distance(a, b) {
var dx = a.x - b.x,
dy = a.y - b.y;
const dx = a.x - b.x;
const dy = a.y - b.y;
return Math.sqrt(dx * dx + dy * dy);
}

Expand Down Expand Up @@ -114,7 +114,7 @@ Handler.PathDrag = Handler.extend(
* @param {L.MouseEvent} evt
*/
_onDragStart: function (evt) {
var eventType = evt.originalEvent._simulated
const eventType = evt.originalEvent._simulated
? 'touchstart'
: evt.originalEvent.type;

Expand Down Expand Up @@ -159,23 +159,24 @@ Handler.PathDrag = Handler.extend(
_onDrag: function (evt) {
DomEvent.stop(evt);

var first = evt.touches && evt.touches.length >= 1 ? evt.touches[0] : evt;
var containerPoint = this._path._map.mouseEventToContainerPoint(first);
const first =
evt.touches && evt.touches.length >= 1 ? evt.touches[0] : evt;
const containerPoint = this._path._map.mouseEventToContainerPoint(first);

// skip taps
if (evt.type === 'touchmove' && !this._path._dragMoved) {
var totalMouseDragDistance =
const totalMouseDragDistance =
this._dragStartPoint.distanceTo(containerPoint);
if (totalMouseDragDistance <= this._path._map.options.tapTolerance) {
return;
}
}

var x = containerPoint.x;
var y = containerPoint.y;
const x = containerPoint.x;
const y = containerPoint.y;

var dx = x - this._startPoint.x;
var dy = y - this._startPoint.y;
const dx = x - this._startPoint.x;
const dy = y - this._startPoint.y;

// Send events only if point was moved
if (dx || dy) {
Expand Down Expand Up @@ -206,8 +207,8 @@ Handler.PathDrag = Handler.extend(
* @param {L.MouseEvent} evt
*/
_onDragEnd: function (evt) {
var containerPoint = this._path._map.mouseEventToContainerPoint(evt);
var moved = this.moved();
const containerPoint = this._path._map.mouseEventToContainerPoint(evt);
const moved = this.moved();

// apply matrix
if (moved) {
Expand All @@ -231,7 +232,7 @@ Handler.PathDrag = Handler.extend(
});

// hack for skipping the click in canvas-rendered layers
var contains = this._path._containsPoint;
const contains = this._path._containsPoint;
this._path._containsPoint = Util.falseFn;

Util.requestAnimFrame(function () {
Expand All @@ -257,20 +258,19 @@ Handler.PathDrag = Handler.extend(
* @param {Array.<Number>} matrix
*/
_transformPoints: function (matrix, dest) {
var path = this._path;
var i, len, latlng;
const path = this._path;

var px = L.point(matrix[4], matrix[5]);
const px = L.point(matrix[4], matrix[5]);

var crs = path._map.options.crs;
var transformation = crs.transformation;
var scale = crs.scale(path._map.getZoom());
var projection = crs.projection;
const crs = path._map.options.crs;
const transformation = crs.transformation;
const scale = crs.scale(path._map.getZoom());
const projection = crs.projection;

var diff = transformation
const diff = transformation
.untransform(px, scale)
.subtract(transformation.untransform(point(0, 0), scale));
var applyTransform = !dest;
const applyTransform = !dest;

path._bounds = new LatLngBounds();

Expand All @@ -287,18 +287,18 @@ Handler.PathDrag = Handler.extend(
}
} else if (path._rings || path._parts) {
// everything else
var rings = path._rings || path._parts;
var latlngs = path._latlngs;
const rings = path._rings || path._parts;
let latlngs = path._latlngs;
dest = dest || latlngs;
if (!Util.isArray(latlngs[0])) {
// polyline
latlngs = [latlngs];
dest = [dest];
}
for (i = 0, len = rings.length; i < len; i++) {
for (let i = 0, len = rings.length; i < len; i++) {
dest[i] = dest[i] || [];
for (var j = 0, jj = rings[i].length; j < jj; j++) {
latlng = latlngs[i][j];
for (let j = 0, jj = rings[i].length; j < jj; j++) {
const latlng = latlngs[i][j];
dest[i][j] = projection.unproject(
projection.project(latlng)._add(diff)
);
Expand Down
18 changes: 9 additions & 9 deletions src/SVG.VML.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SVG.include(
* @param {Array.<Number>} matrix
*/
transformPath: function (layer, matrix) {
var skew = layer._skew;
let skew = layer._skew;

if (!skew) {
skew = SVG.create('skew');
Expand All @@ -33,7 +33,7 @@ SVG.include(
}

// handle skew/translate separately, cause it's broken
var mt =
const mt =
matrix[0].toFixed(8) +
' ' +
matrix[1].toFixed(8) +
Expand All @@ -42,24 +42,24 @@ SVG.include(
' ' +
matrix[3].toFixed(8) +
' 0 0';
var offset =
const offset =
Math.floor(matrix[4]).toFixed() +
', ' +
Math.floor(matrix[5]).toFixed() +
'';

var s = this._path.style;
var l = parseFloat(s.left);
var t = parseFloat(s.top);
var w = parseFloat(s.width);
var h = parseFloat(s.height);
const s = this._path.style;
let l = parseFloat(s.left);
let t = parseFloat(s.top);
let w = parseFloat(s.width);
let h = parseFloat(s.height);

if (isNaN(l)) l = 0;
if (isNaN(t)) t = 0;
if (isNaN(w) || !w) w = 1;
if (isNaN(h) || !h) h = 1;

var origin =
const origin =
(-l / w - 0.5).toFixed(8) + ' ' + (-t / h - 0.5).toFixed(8);

skew.on = 'f';
Expand Down
8 changes: 4 additions & 4 deletions src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as L from 'leaflet';
import '../src';

////////////////////////////////////////////////////////////////////////////////
var map = (window.map = new L.Map('map', {
const map = (window.map = new L.Map('map', {
// crs: L.CRS.EPSG4326 // that was tested as well
}).setView([22.42658, 114.1952], 11));

var renderer = new L.Canvas();
const renderer = new L.Canvas();

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution:
Expand All @@ -17,12 +17,12 @@ L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {

////////////////////////////////////////////////////////////////////////////////
function interpolateArr(array, insert) {
var res = [];
const res = [];
array.forEach((p, i, arr) => {
res.push(p.concat());

if (i < arr.length - 1) {
var diff = [arr[i + 1][0] - p[0], arr[i + 1][1] - p[1]];
const diff = [arr[i + 1][0] - p[0], arr[i + 1][1] - p[1]];
for (let j = 1; j < insert; j++) {
res.push([
p[0] + (diff[0] * j) / insert,
Expand Down

0 comments on commit affc541

Please sign in to comment.