@tomickigrzegorz/leaflet-rotate 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,59 +48,52 @@ Load it **after** Leaflet. `leaflet` is a peer dependency (>=1.9).
48
48
  | `shiftKeyRotate` | `boolean` | `false` | Rotation via **Shift + scroll wheel**. Normal scroll-wheel zoom is suppressed while Shift is held. |
49
49
  | `touchRotate` | `boolean` | `false` | Rotation with a **two-finger** gesture (pinch-rotate, Google Maps style). Rotation has a ~30° threshold to avoid colliding with pinch-zoom. |
50
50
  | `rotateClockwise` | `boolean` | `true` | Direction of all rotation inputs (two-finger, right-mouse drag, Shift+wheel). `true` = clockwise gesture rotates the map clockwise (MapLibre-like). Set `false` to invert all three. |
51
- | `rotateControl` | `boolean \| object` | `false` | Arrow control that resets bearing to north (see below). |
52
- | `rotateCompassControl` | `boolean \| object` | `false` | Compass control that toggles rotation (see below). |
51
+ | `rotateControl` | `boolean \| object` | `false` | Compass control. `behavior: "reset"` resets bearing to north; `behavior: "toggle"` enables/disables rotation (see below). |
53
52
  | `preventPageGestures` | `boolean` | `true` | Blocks native page pinch-zoom on iOS Safari (`preventDefault` on `gesturestart/change/end` events) so a pinch acts on the map rather than zooming the page. Not needed on desktop/Android (where `touch-action` suffices) but harmless. Set `false` to disable. Works independently of `rotate`. |
54
53
 
55
54
  > Note: zoom (via buttons, scroll wheel, or around the cursor) is animated even when the map is rotated. If the map was panned, the offset is "committed" (reprojected without changing the view) just before the animation, keeping the zoom anchor in place and preventing grey tile flashes.
56
55
 
57
56
  ---
58
57
 
59
- ## `rotateCompassControl` — compass (main rotation toggle)
58
+ ## `rotateControl` — compass control
59
+
60
+ A single compass control with two behaviours selected via `behavior`.
60
61
 
61
62
  Value:
62
63
 
63
64
  - `false` — control is not added (button invisible).
64
- - `true` — control with default settings.
65
+ - `true` — control with default settings (`behavior: "reset"`).
65
66
  - `object` — control with custom settings:
66
67
 
67
68
  ```js
68
- rotateCompassControl: { enabled: false, position: "bottomright" }
69
+ rotateControl: { position: "topleft", behavior: "reset", closeOnZeroBearing: true }
69
70
  ```
70
71
 
71
- | Field | Type | Default | Description |
72
- | ---------- | --------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
73
- | `enabled` | `boolean` | `false` | Initial rotation state. `true` = rotation active immediately, button coloured. `false` = rotation off, enabled **only after clicking** the compass. |
74
- | `position` | `string` | `"bottomright"` | Position: `"topleft"`, `"topright"`, `"bottomleft"`, `"bottomright"`. |
75
-
76
- Behaviour:
77
-
78
- - Click toggles rotation **on/off**. Disabling also resets `bearing` to 0 and disables all rotation gestures (`dragRotate`, `shiftKeyRotate`, `touchGestures`).
79
- - The icon rotates with the current `bearing`.
80
- - When visible but **inactive** → icon is greyscale. Active → coloured.
81
-
82
- ---
83
-
84
- ## `rotateControl` — arrow that resets to north
72
+ | Field | Type | Default | Description |
73
+ | -------------------- | --------- | ----------- | ------------------------------------------------------------------------------------------------------------------ |
74
+ | `behavior` | `string` | `"reset"` | `"reset"` = rotation always on, click returns to north. `"toggle"` = click enables/disables rotation. |
75
+ | `position` | `string` | `"topleft"` | Position: `"topleft"`, `"topright"`, `"bottomleft"`, `"bottomright"`. |
76
+ | `closeOnZeroBearing` | `boolean` | `true` | **Reset mode only.** Hides the control when `bearing === 0` (appears after rotating, hides after returning north). |
77
+ | `enabled` | `boolean` | `false` | **Toggle mode only.** Initial rotation state. `false` = rotation off until the compass is clicked. |
85
78
 
86
- ```js
87
- rotateControl: { position: "topleft", closeOnZeroBearing: true }
88
- ```
79
+ ### `behavior: "reset"` (rotation always on, Google-style)
89
80
 
90
- | Field | Type | Default | Description |
91
- | -------------------- | --------- | ----------- | --------------------------------------- |
92
- | `position` | `string` | `"topleft"` | Control position. |
93
- | `closeOnZeroBearing` | `boolean` | `true` | Hides the control when `bearing === 0`. |
81
+ - Rotation is enabled by the map options (`rotate`, `dragRotate`, `touchRotate`, `shiftKeyRotate`) — the control does **not** manage gestures.
82
+ - Click sets `bearing` to 0 (north).
83
+ - The needle rotates with the current `bearing`.
84
+ - With `closeOnZeroBearing: true` the control appears only when rotated and hides after returning to north (including after a click). With `false` it is always visible.
94
85
 
95
- Click sets `bearing` to 0 (north).
86
+ ### `behavior: "toggle"` (button enables rotation)
96
87
 
97
- ### Adding controls programmatically
88
+ - Rotation is **off by default**. Click enables it (gestures active, needle coloured); click again disables it, resets `bearing` to 0, and greys the needle.
89
+ - Always visible; state shown by needle colour (active = coloured, inactive = greyscale).
90
+ - Two-finger gesture zooms and rotates simultaneously (Google-style) once rotation is enabled.
98
91
 
99
- Both controls can also be created via factory functions (e.g. to add them after map init):
92
+ ### Adding the control programmatically
100
93
 
101
94
  ```js
102
- L.control.rotate({ position: "topleft" }).addTo(map);
103
- L.control.rotateCompass({ enabled: true, position: "bottomright" }).addTo(map);
95
+ L.control.rotate({ position: "topleft", behavior: "reset" }).addTo(map);
96
+ L.control.rotate({ position: "bottomright", behavior: "toggle", enabled: false }).addTo(map);
104
97
  ```
105
98
 
106
99
  ---
@@ -154,9 +147,9 @@ map.stopHeadingUp(); // disable heading-up (keeps current bearing)
154
147
  | Right mouse button + drag | `dragRotate: true` |
155
148
  | Shift + scroll wheel | `shiftKeyRotate: true` |
156
149
  | Two fingers (rotate) | `touchRotate: true` |
157
- | Compass click | `rotateCompassControl` (toggles rotation on/off) |
150
+ | Compass click | `rotateControl` with `behavior: "toggle"` (on/off) |
158
151
 
159
- All require `rotate: true`. When rotation is disabled via the compass, no gesture works until the compass is clicked again.
152
+ All require `rotate: true`. With `rotateControl` in `behavior: "toggle"`, rotation is off until the compass is clicked; no gesture works until then.
160
153
 
161
154
  ---
162
155
 
@@ -185,7 +178,6 @@ const map = L.map("map", {
185
178
  shiftKeyRotate: true,
186
179
  dragRotate: true,
187
180
  rotateClockwise: true,
188
- rotateControl: false,
189
- rotateCompassControl: { enabled: false, position: "bottomright" },
181
+ rotateControl: { position: "topright", behavior: "reset", closeOnZeroBearing: true },
190
182
  });
191
183
  ```
package/dist/index.d.ts CHANGED
@@ -7,9 +7,15 @@ declare module "leaflet" {
7
7
  touchRotate?: boolean;
8
8
  shiftKeyRotate?: boolean;
9
9
  dragRotate?: boolean;
10
- rotateControl?: boolean | { position?: string; closeOnZeroBearing?: boolean };
10
+ rotateControl?:
11
+ | boolean
12
+ | {
13
+ position?: string;
14
+ behavior?: "reset" | "toggle";
15
+ closeOnZeroBearing?: boolean;
16
+ enabled?: boolean;
17
+ };
11
18
  rotateClockwise?: boolean;
12
- rotateCompassControl?: boolean | { enabled?: boolean; position?: string };
13
19
  preventPageGestures?: boolean;
14
20
  }
15
21
 
@@ -6,16 +6,6 @@
6
6
  }
7
7
  .leaflet-control-rotate { background: var(--lrc-control-bg); }
8
8
  .leaflet-control-rotate a {
9
- display: block;
10
- width: 26px;
11
- height: 26px;
12
- line-height: 26px;
13
- text-align: center;
14
- cursor: pointer;
15
- }
16
- .leaflet-control-rotate a:hover { background: var(--lrc-control-hover); }
17
- .leaflet-control-rotate-compass { background: var(--lrc-control-bg); }
18
- .leaflet-control-rotate-compass a {
19
9
  display: flex;
20
10
  align-items: center;
21
11
  justify-content: center;
@@ -23,5 +13,5 @@
23
13
  height: var(--lrc-control-size);
24
14
  cursor: pointer;
25
15
  }
26
- .leaflet-control-rotate-compass a:hover { background: var(--lrc-control-hover); }
27
- .leaflet-rotate-compass--inactive a svg { filter: grayscale(1); }
16
+ .leaflet-control-rotate a:hover { background: var(--lrc-control-hover); }
17
+ .leaflet-control-rotate--inactive a svg { filter: grayscale(1); }
@@ -1258,15 +1258,21 @@ const _mapProto = L.Map.prototype;
1258
1258
  };
1259
1259
 
1260
1260
  // =====================================================================
1261
- // 11. L.Control.Rotate — compass control
1261
+ // 11. L.Control.Rotate — unified compass control
1262
+ // behavior: "reset" → rotation always on, click returns to north
1263
+ // behavior: "toggle" → click enables/disables rotation (+ reset)
1262
1264
  // =====================================================================
1263
1265
  L.Control.Rotate = L.Control.extend({
1264
1266
  options: {
1265
1267
  position: "topleft",
1266
- closeOnZeroBearing: true,
1268
+ behavior: "reset", // "reset" | "toggle"
1269
+ closeOnZeroBearing: true, // reset mode: hide control at bearing 0
1270
+ enabled: false, // toggle mode: initial rotation state
1267
1271
  },
1268
1272
 
1269
1273
  onAdd: function (map) {
1274
+ this._map = map;
1275
+
1270
1276
  var container = L.DomUtil.create(
1271
1277
  "div",
1272
1278
  "leaflet-control-rotate leaflet-bar",
@@ -1277,81 +1283,13 @@ const _mapProto = L.Map.prototype;
1277
1283
  container,
1278
1284
  );
1279
1285
  link.href = "#";
1280
- link.title = "Reset rotation";
1281
1286
  link.setAttribute("role", "button");
1282
- link.setAttribute("aria-label", "Reset rotation");
1283
- link.innerHTML =
1284
- '<svg viewBox="0 0 24 24" width="18" height="18" style="display:block;margin:auto;padding:3px">' +
1285
- '<path d="M12 2L8 8h3v8h2V8h3L12 2z" fill="currentColor"/></svg>';
1286
-
1287
- this._link = link;
1288
- this._container = container;
1289
-
1290
- L.DomEvent.disableClickPropagation(container);
1291
- L.DomEvent.on(link, "click", this._resetBearing, this);
1292
- map.on("rotate", this._updateDisplay, this);
1293
- this._updateDisplay();
1294
- return container;
1295
- },
1296
-
1297
- onRemove: function (map) {
1298
- map.off("rotate", this._updateDisplay, this);
1299
- L.DomEvent.off(this._link, "click", this._resetBearing, this);
1300
- },
1301
-
1302
- _resetBearing: function (e) {
1303
- L.DomEvent.stop(e);
1304
- this._map.setBearing(0);
1305
- },
1306
1287
 
1307
- _updateDisplay: function () {
1308
- if (!this._map || !this._link) return;
1309
- var bearing = this._map.getBearing();
1310
- this._link.style[L.DomUtil.TRANSFORM] = "rotate(" + -bearing + "deg)";
1311
- if (this.options.closeOnZeroBearing) {
1312
- this._container.style.display = bearing === 0 ? "none" : "";
1313
- }
1314
- },
1315
- });
1288
+ var label =
1289
+ this.options.behavior === "toggle" ? "Map rotation" : "Reset rotation";
1290
+ link.title = label;
1291
+ link.setAttribute("aria-label", label);
1316
1292
 
1317
- L.control.rotate = function (options) {
1318
- return new L.Control.Rotate(options);
1319
- };
1320
-
1321
- L.Map.addInitHook(function () {
1322
- if (this.options.rotate && this.options.rotateControl) {
1323
- var opts =
1324
- this.options.rotateControl === true ? {} : this.options.rotateControl;
1325
- this.rotateControl = L.control.rotate(opts);
1326
- this.addControl(this.rotateControl);
1327
- }
1328
- });
1329
-
1330
- // =====================================================================
1331
- // 11b. L.Control.RotateCompass — bottom-right compass toggle
1332
- // =====================================================================
1333
- L.Control.RotateCompass = L.Control.extend({
1334
- options: {
1335
- position: "bottomright",
1336
- enabled: false,
1337
- },
1338
-
1339
- onAdd: function (map) {
1340
- this._map = map;
1341
-
1342
- var container = L.DomUtil.create(
1343
- "div",
1344
- "leaflet-control-rotate-compass leaflet-bar",
1345
- );
1346
- var link = L.DomUtil.create(
1347
- "a",
1348
- "leaflet-control-rotate-compass-toggle",
1349
- container,
1350
- );
1351
- link.href = "#";
1352
- link.title = "Map rotation";
1353
- link.setAttribute("role", "button");
1354
- link.setAttribute("aria-label", "Map rotation");
1355
1293
  link.innerHTML =
1356
1294
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="22" height="22" fill-rule="evenodd" clip-rule="evenodd" style="display:block;transform-origin:center;transform-box:fill-box">' +
1357
1295
  '<path fill="#ebebeb" stroke="#333" stroke-width=".6" d="m11.81.44 3.6 11.27h-7.2z"/>' +
@@ -1363,27 +1301,36 @@ const _mapProto = L.Map.prototype;
1363
1301
  this._container = container;
1364
1302
 
1365
1303
  L.DomEvent.disableClickPropagation(container);
1366
- L.DomEvent.on(link, "click", this._toggleRotation, this);
1304
+ L.DomEvent.on(link, "click", this._onClick, this);
1367
1305
  map.on("rotate", this._updateDisplay, this);
1368
- if (this.options.enabled) {
1369
- this._enableRotation();
1306
+
1307
+ if (this.options.behavior === "toggle") {
1308
+ if (this.options.enabled) {
1309
+ this._enableRotation();
1310
+ } else {
1311
+ this._disableRotation();
1312
+ }
1370
1313
  } else {
1371
- this._disableRotation();
1314
+ this._updateDisplay();
1372
1315
  }
1373
1316
  return container;
1374
1317
  },
1375
1318
 
1376
1319
  onRemove: function (map) {
1377
1320
  map.off("rotate", this._updateDisplay, this);
1378
- L.DomEvent.off(this._link, "click", this._toggleRotation, this);
1321
+ L.DomEvent.off(this._link, "click", this._onClick, this);
1379
1322
  },
1380
1323
 
1381
- _toggleRotation: function (e) {
1324
+ _onClick: function (e) {
1382
1325
  L.DomEvent.stop(e);
1383
- if (this._enabled) {
1384
- this._disableRotation();
1326
+ if (this.options.behavior === "toggle") {
1327
+ if (this._enabled) {
1328
+ this._disableRotation();
1329
+ } else {
1330
+ this._enableRotation();
1331
+ }
1385
1332
  } else {
1386
- this._enableRotation();
1333
+ this._map.setBearing(0);
1387
1334
  }
1388
1335
  },
1389
1336
 
@@ -1418,29 +1365,34 @@ const _mapProto = L.Map.prototype;
1418
1365
  if (this._needle) {
1419
1366
  this._needle.style[L.DomUtil.TRANSFORM] = "rotate(" + -bearing + "deg)";
1420
1367
  }
1421
- if (this._enabled) {
1422
- L.DomUtil.removeClass(
1423
- this._container,
1424
- "leaflet-rotate-compass--inactive",
1425
- );
1426
- } else {
1427
- L.DomUtil.addClass(this._container, "leaflet-rotate-compass--inactive");
1368
+ if (this.options.behavior === "toggle") {
1369
+ if (this._enabled) {
1370
+ L.DomUtil.removeClass(
1371
+ this._container,
1372
+ "leaflet-control-rotate--inactive",
1373
+ );
1374
+ } else {
1375
+ L.DomUtil.addClass(
1376
+ this._container,
1377
+ "leaflet-control-rotate--inactive",
1378
+ );
1379
+ }
1380
+ } else if (this.options.closeOnZeroBearing) {
1381
+ this._container.style.display = bearing === 0 ? "none" : "";
1428
1382
  }
1429
1383
  },
1430
1384
  });
1431
1385
 
1432
- L.control.rotateCompass = function (options) {
1433
- return new L.Control.RotateCompass(options);
1386
+ L.control.rotate = function (options) {
1387
+ return new L.Control.Rotate(options);
1434
1388
  };
1435
1389
 
1436
1390
  L.Map.addInitHook(function () {
1437
- if (this.options.rotate && this.options.rotateCompassControl) {
1391
+ if (this.options.rotate && this.options.rotateControl) {
1438
1392
  var opts =
1439
- this.options.rotateCompassControl === true
1440
- ? {}
1441
- : this.options.rotateCompassControl;
1442
- this.rotateCompassControl = L.control.rotateCompass(opts);
1443
- this.addControl(this.rotateCompassControl);
1393
+ this.options.rotateControl === true ? {} : this.options.rotateControl;
1394
+ this.rotateControl = L.control.rotate(opts);
1395
+ this.addControl(this.rotateControl);
1444
1396
  }
1445
1397
  });
1446
1398
 
@@ -1262,15 +1262,21 @@
1262
1262
  };
1263
1263
 
1264
1264
  // =====================================================================
1265
- // 11. L.Control.Rotate — compass control
1265
+ // 11. L.Control.Rotate — unified compass control
1266
+ // behavior: "reset" → rotation always on, click returns to north
1267
+ // behavior: "toggle" → click enables/disables rotation (+ reset)
1266
1268
  // =====================================================================
1267
1269
  L.Control.Rotate = L.Control.extend({
1268
1270
  options: {
1269
1271
  position: "topleft",
1270
- closeOnZeroBearing: true,
1272
+ behavior: "reset", // "reset" | "toggle"
1273
+ closeOnZeroBearing: true, // reset mode: hide control at bearing 0
1274
+ enabled: false, // toggle mode: initial rotation state
1271
1275
  },
1272
1276
 
1273
1277
  onAdd: function (map) {
1278
+ this._map = map;
1279
+
1274
1280
  var container = L.DomUtil.create(
1275
1281
  "div",
1276
1282
  "leaflet-control-rotate leaflet-bar",
@@ -1281,81 +1287,13 @@
1281
1287
  container,
1282
1288
  );
1283
1289
  link.href = "#";
1284
- link.title = "Reset rotation";
1285
1290
  link.setAttribute("role", "button");
1286
- link.setAttribute("aria-label", "Reset rotation");
1287
- link.innerHTML =
1288
- '<svg viewBox="0 0 24 24" width="18" height="18" style="display:block;margin:auto;padding:3px">' +
1289
- '<path d="M12 2L8 8h3v8h2V8h3L12 2z" fill="currentColor"/></svg>';
1290
-
1291
- this._link = link;
1292
- this._container = container;
1293
-
1294
- L.DomEvent.disableClickPropagation(container);
1295
- L.DomEvent.on(link, "click", this._resetBearing, this);
1296
- map.on("rotate", this._updateDisplay, this);
1297
- this._updateDisplay();
1298
- return container;
1299
- },
1300
-
1301
- onRemove: function (map) {
1302
- map.off("rotate", this._updateDisplay, this);
1303
- L.DomEvent.off(this._link, "click", this._resetBearing, this);
1304
- },
1305
-
1306
- _resetBearing: function (e) {
1307
- L.DomEvent.stop(e);
1308
- this._map.setBearing(0);
1309
- },
1310
1291
 
1311
- _updateDisplay: function () {
1312
- if (!this._map || !this._link) return;
1313
- var bearing = this._map.getBearing();
1314
- this._link.style[L.DomUtil.TRANSFORM] = "rotate(" + -bearing + "deg)";
1315
- if (this.options.closeOnZeroBearing) {
1316
- this._container.style.display = bearing === 0 ? "none" : "";
1317
- }
1318
- },
1319
- });
1292
+ var label =
1293
+ this.options.behavior === "toggle" ? "Map rotation" : "Reset rotation";
1294
+ link.title = label;
1295
+ link.setAttribute("aria-label", label);
1320
1296
 
1321
- L.control.rotate = function (options) {
1322
- return new L.Control.Rotate(options);
1323
- };
1324
-
1325
- L.Map.addInitHook(function () {
1326
- if (this.options.rotate && this.options.rotateControl) {
1327
- var opts =
1328
- this.options.rotateControl === true ? {} : this.options.rotateControl;
1329
- this.rotateControl = L.control.rotate(opts);
1330
- this.addControl(this.rotateControl);
1331
- }
1332
- });
1333
-
1334
- // =====================================================================
1335
- // 11b. L.Control.RotateCompass — bottom-right compass toggle
1336
- // =====================================================================
1337
- L.Control.RotateCompass = L.Control.extend({
1338
- options: {
1339
- position: "bottomright",
1340
- enabled: false,
1341
- },
1342
-
1343
- onAdd: function (map) {
1344
- this._map = map;
1345
-
1346
- var container = L.DomUtil.create(
1347
- "div",
1348
- "leaflet-control-rotate-compass leaflet-bar",
1349
- );
1350
- var link = L.DomUtil.create(
1351
- "a",
1352
- "leaflet-control-rotate-compass-toggle",
1353
- container,
1354
- );
1355
- link.href = "#";
1356
- link.title = "Map rotation";
1357
- link.setAttribute("role", "button");
1358
- link.setAttribute("aria-label", "Map rotation");
1359
1297
  link.innerHTML =
1360
1298
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="22" height="22" fill-rule="evenodd" clip-rule="evenodd" style="display:block;transform-origin:center;transform-box:fill-box">' +
1361
1299
  '<path fill="#ebebeb" stroke="#333" stroke-width=".6" d="m11.81.44 3.6 11.27h-7.2z"/>' +
@@ -1367,27 +1305,36 @@
1367
1305
  this._container = container;
1368
1306
 
1369
1307
  L.DomEvent.disableClickPropagation(container);
1370
- L.DomEvent.on(link, "click", this._toggleRotation, this);
1308
+ L.DomEvent.on(link, "click", this._onClick, this);
1371
1309
  map.on("rotate", this._updateDisplay, this);
1372
- if (this.options.enabled) {
1373
- this._enableRotation();
1310
+
1311
+ if (this.options.behavior === "toggle") {
1312
+ if (this.options.enabled) {
1313
+ this._enableRotation();
1314
+ } else {
1315
+ this._disableRotation();
1316
+ }
1374
1317
  } else {
1375
- this._disableRotation();
1318
+ this._updateDisplay();
1376
1319
  }
1377
1320
  return container;
1378
1321
  },
1379
1322
 
1380
1323
  onRemove: function (map) {
1381
1324
  map.off("rotate", this._updateDisplay, this);
1382
- L.DomEvent.off(this._link, "click", this._toggleRotation, this);
1325
+ L.DomEvent.off(this._link, "click", this._onClick, this);
1383
1326
  },
1384
1327
 
1385
- _toggleRotation: function (e) {
1328
+ _onClick: function (e) {
1386
1329
  L.DomEvent.stop(e);
1387
- if (this._enabled) {
1388
- this._disableRotation();
1330
+ if (this.options.behavior === "toggle") {
1331
+ if (this._enabled) {
1332
+ this._disableRotation();
1333
+ } else {
1334
+ this._enableRotation();
1335
+ }
1389
1336
  } else {
1390
- this._enableRotation();
1337
+ this._map.setBearing(0);
1391
1338
  }
1392
1339
  },
1393
1340
 
@@ -1422,29 +1369,34 @@
1422
1369
  if (this._needle) {
1423
1370
  this._needle.style[L.DomUtil.TRANSFORM] = "rotate(" + -bearing + "deg)";
1424
1371
  }
1425
- if (this._enabled) {
1426
- L.DomUtil.removeClass(
1427
- this._container,
1428
- "leaflet-rotate-compass--inactive",
1429
- );
1430
- } else {
1431
- L.DomUtil.addClass(this._container, "leaflet-rotate-compass--inactive");
1372
+ if (this.options.behavior === "toggle") {
1373
+ if (this._enabled) {
1374
+ L.DomUtil.removeClass(
1375
+ this._container,
1376
+ "leaflet-control-rotate--inactive",
1377
+ );
1378
+ } else {
1379
+ L.DomUtil.addClass(
1380
+ this._container,
1381
+ "leaflet-control-rotate--inactive",
1382
+ );
1383
+ }
1384
+ } else if (this.options.closeOnZeroBearing) {
1385
+ this._container.style.display = bearing === 0 ? "none" : "";
1432
1386
  }
1433
1387
  },
1434
1388
  });
1435
1389
 
1436
- L.control.rotateCompass = function (options) {
1437
- return new L.Control.RotateCompass(options);
1390
+ L.control.rotate = function (options) {
1391
+ return new L.Control.Rotate(options);
1438
1392
  };
1439
1393
 
1440
1394
  L.Map.addInitHook(function () {
1441
- if (this.options.rotate && this.options.rotateCompassControl) {
1395
+ if (this.options.rotate && this.options.rotateControl) {
1442
1396
  var opts =
1443
- this.options.rotateCompassControl === true
1444
- ? {}
1445
- : this.options.rotateCompassControl;
1446
- this.rotateCompassControl = L.control.rotateCompass(opts);
1447
- this.addControl(this.rotateCompassControl);
1397
+ this.options.rotateControl === true ? {} : this.options.rotateControl;
1398
+ this.rotateControl = L.control.rotate(opts);
1399
+ this.addControl(this.rotateControl);
1448
1400
  }
1449
1401
  });
1450
1402
 
@@ -1,2 +1,2 @@
1
1
  /*! @tomickigrzegorz/leaflet-rotate v0.1.0 | MIT */
2
- !function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(require("leaflet")):"function"==typeof define&&define.amd?define(["leaflet"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).L)}(this,function(t){"use strict";t.Point.prototype.rotate=function(i){var e=Math.cos(i),o=Math.sin(i);return new t.Point(this.x*e-this.y*o,this.x*o+this.y*e)},t.Point.prototype.rotateFrom=function(t,i){return i?this.subtract(i).rotate(t).add(i):this.rotate(t)},t.DomUtil.setTransform=function(i,e,o,a,n){var s=e||new t.Point(0,0),r="translate3d("+s.x+"px,"+s.y+"px,0)";null!=o&&(r+=" scale("+o+")"),a&&(r+=" rotate("+a+"rad)"),i.style[t.DomUtil.TRANSFORM]=r,n&&(i.style[t.DomUtil.TRANSFORM+"Origin"]=n.x+"px "+n.y+"px")},t.DomUtil.setPosition=function(i,e,o,a){i._leaflet_pos=e,t.Browser.any3d?t.DomUtil.setTransform(i,e,void 0,o,a):(i.style.left=e.x+"px",i.style.top=e.y+"px")};const i=Math.PI/180,e=180/Math.PI;var o=t.Map.prototype;t.Map.mergeOptions({rotate:!1,bearing:0,touchRotate:!1,shiftKeyRotate:!1,dragRotate:!0,rotateControl:!1,rotateClockwise:!0});var a=o.initialize;o.initialize=function(t,i){i&&i.rotate&&(this._rotate=!0,this._bearing=0,this._bearingRad=0),a.call(this,t,i),this._rotate&&this.setBearing(i.bearing||0)};var n=o._initPanes;o._initPanes=function(){if(n.call(this),this._rotate){var i=this._mapPane;this._rotatePane=t.DomUtil.create("div","leaflet-rotate-pane",i),this._norotatePane=t.DomUtil.create("div","leaflet-norotate-pane",i),this._rotatePane.appendChild(this._panes.tilePane),this._rotatePane.appendChild(this._panes.overlayPane),this._norotatePane.appendChild(this._panes.shadowPane),this._norotatePane.appendChild(this._panes.markerPane),this._norotatePane.appendChild(this._panes.tooltipPane),this._norotatePane.appendChild(this._panes.popupPane),t.DomUtil.addClass(this._rotatePane,"leaflet-proxy leaflet-zoom-animated")}},o.setBearing=function(e){if(this._rotate){this._commitRotatePan();var o=this._bearing||0,a=(e%360+360)%360;if(this._bearing=a,this._bearingRad=a*i,this._updateRotatePaneTransform(),0===o!=(0===a))for(var n in this._layers){var s=this._layers[n];s instanceof t.Renderer&&s._update()}this.fire("rotate")}},o.getBearing=function(){return this._bearing||0},o._updateRotatePaneTransform=function(){if(this._rotatePane){if(!this._bearing)return this._rotatePane.style[t.DomUtil.TRANSFORM]="",void(this._rotatePane.style[t.DomUtil.TRANSFORM+"Origin"]="");var i=this.getSize().divideBy(2);this._rotatePane.style[t.DomUtil.TRANSFORM+"Origin"]=i.x+"px "+i.y+"px",this._rotatePane.style[t.DomUtil.TRANSFORM]="rotate("+this._bearingRad+"rad)"}},o._commitRotatePan=function(){if(this._rotate&&!this._committingRotatePan){var t=this._getMapPanePos();!t||0===t.x&&0===t.y||(this._committingRotatePan=!0,this._resetView(this.getCenter(),this.getZoom(),!0),this._committingRotatePan=!1)}};var s=o.containerPointToLayerPoint;o.containerPointToLayerPoint=function(i){if(!this._rotate||!this._bearing)return s.call(this,i);var e=t.point(i),o=this._getMapPanePos(),a=this.getSize().divideBy(2);return e.subtract(o).subtract(a).rotate(-this._bearingRad).add(a)};var r=o.layerPointToContainerPoint;o.layerPointToContainerPoint=function(i){if(!this._rotate||!this._bearing)return r.call(this,i);var e=t.point(i),o=this._getMapPanePos(),a=this.getSize().divideBy(2);return e.subtract(a).rotate(this._bearingRad).add(a).add(o)},o.rotatedPointToMapPanePoint=function(i){if(!this._bearing)return t.point(i);var e=this.getSize().divideBy(2);return t.point(i).rotateFrom(this._bearingRad,e)},o.mapPanePointToRotatedPoint=function(i){if(!this._bearing)return t.point(i);var e=this.getSize().divideBy(2);return t.point(i).rotateFrom(-this._bearingRad,e)};var h=o._getCenterOffset;o._getCenterOffset=function(t){return this._rotate&&this._bearing?this.project(t).subtract(this.project(this.getCenter())).rotate(this._bearingRad):h.call(this,t)};var _=o.getBounds;o.getBounds=function(){if(!this._rotate||!this._bearing)return _.call(this);var i=this.getSize(),e=t.latLngBounds();return e.extend(this.containerPointToLatLng(t.point(0,0))),e.extend(this.containerPointToLatLng(t.point(i.x,0))),e.extend(this.containerPointToLatLng(t.point(i.x,i.y))),e.extend(this.containerPointToLatLng(t.point(0,i.y))),e},o.mapBoundsToContainerBounds=function(i){return t.bounds([this.latLngToContainerPoint(i.getNorthWest()),this.latLngToContainerPoint(i.getNorthEast()),this.latLngToContainerPoint(i.getSouthEast()),this.latLngToContainerPoint(i.getSouthWest())])};var p=o.getBoundsZoom;o.getBoundsZoom=function(i,e,o){if(!this._rotate||!this._bearing)return p.call(this,i,e,o);i=t.latLngBounds(i),o=t.point(o||[0,0]);var a=this.getZoom()||0,n=this.getMinZoom(),s=this.getMaxZoom(),r=this.getSize().subtract(o);if(r.x<=0||r.y<=0)return a;var h=this.mapBoundsToContainerBounds(i).getSize(),_=this.options.zoomSnap,l=r.x/h.x,m=r.y/h.y,d=e?Math.max(l,m):Math.min(l,m);return a=this.getScaleZoom(d,a),_&&(a=Math.round(a/_)*_),Math.max(n,Math.min(s,a))},o._animateZoomNoDelay=function(t,i,e){this._mapPane&&(e&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=i),this._move(this._animateToCenter,this._animateToZoom,void 0,!0),this._onZoomTransitionEnd())};var l=o._tryAnimatedZoom;o._tryAnimatedZoom=function(t,i,e){if(this._rotate&&this._bearing&&!this._animatingZoom){var o=this._getMapPanePos();o&&(o.x||o.y)&&this._resetView(this.getCenter(),this.getZoom(),!0)}return l.call(this,t,i,e)},t.Map.addInitHook(function(){this._rotate&&this.on("resize",this._updateRotatePaneTransform,this)});var m=t.GridLayer.prototype.getEvents;t.GridLayer.prototype.getEvents=function(){var t=m.call(this);return this._map&&this._map._rotate&&(t.rotate=this._onRotate),t},t.GridLayer.prototype._onRotate=function(){this._update()};var d=t.GridLayer.prototype._getTiledPixelBounds;t.GridLayer.prototype._getTiledPixelBounds=function(i){if(!this._map._rotate||!this._map._bearing)return d.call(this,i);for(var e=this._map,o=e._animatingZoom?Math.max(e._animateToZoom,e.getZoom()):e.getZoom(),a=e.getZoomScale(o,this._tileZoom),n=e.project(i,this._tileZoom).floor(),s=e.getSize().divideBy(2*Math.min(a,1)).multiplyBy(1.25),r=new t.Bounds,h=[t.point(-s.x,-s.y),t.point(s.x,-s.y),t.point(s.x,s.y),t.point(-s.x,s.y)],_=0;_<4;_++)r.extend(n.add(h[_].rotate(-e._bearingRad)));return r};var c=t.Renderer.prototype.onAdd;t.Renderer.prototype.onAdd=function(i){c.call(this,i),i._rotate&&t.DomUtil.addClass(this._container,"leaflet-zoom-animated")};var u=t.Renderer.prototype._updateTransform;t.Renderer.prototype._updateTransform=function(i,e){if(!this._map||!this._map._rotate||!this._map._bearing)return u.call(this,i,e);if(this._bounds&&this._boundsMinLatLng){var o=this._map,a=o.getZoomScale(e,this._zoom),n=o._latLngToNewLayerPoint(this._boundsMinLatLng,e,i);t.DomUtil.setTransform(this._container,n,a)}};var g=t.Renderer.prototype._update;t.Renderer.prototype._update=function(){if(!this._map||!this._map._rotate||!this._map._bearing)return g.call(this);var i=Math.max(this.options.padding||0,1.5),e=this._map,o=e.getSize(),a=e.containerPointToLayerPoint(o.divideBy(2)),n=o.multiplyBy(.5+i),s=Math.ceil(Math.sqrt(n.x*n.x+n.y*n.y));this._bounds=new t.Bounds(a.subtract([s,s]).round(),a.add([s,s]).round()),this._center=e.getCenter(),this._zoom=e.getZoom(),this._boundsMinLatLng=e.layerPointToLatLng(this._bounds.min)};const f=t.Map.prototype;f.setHeading=function(t,i){return this._rotate?null==t||isNaN(t)?this.stopHeadingUp():(i=i||{},this._headingUp=!0,this._headingEase=null!=i.ease?i.ease:.2,this._headingDeadzone=null!=i.deadzone?i.deadzone:.5,this._headingTarget=(-t%360+360)%360,this._startHeadingAnim(),this):this},f.stopHeadingUp=function(){return this._headingUp=!1,this._headingRAF&&(t.Util.cancelAnimFrame(this._headingRAF),this._headingRAF=null),this},f.getHeadingUp=function(){return!!this._headingUp},f._startHeadingAnim=function(){this._headingRAF||(this._headingRAF=t.Util.requestAnimFrame(this._headingAnim,this))},f._headingAnim=function(){if(this._headingRAF=null,this._headingUp){for(var i=this.getBearing(),e=this._headingTarget-i;e>180;)e-=360;for(;e<-180;)e+=360;Math.abs(e)<this._headingDeadzone?Math.abs(e)>.001&&this.setBearing(this._headingTarget):(this.setBearing(i+e*this._headingEase),this._headingRAF=t.Util.requestAnimFrame(this._headingAnim,this))}},t.Marker.mergeOptions({rotation:0,rotateWithView:!1,scale:void 0});var v=t.Marker.prototype.getEvents;t.Marker.prototype.getEvents=function(){var t=v.call(this);return this._map&&this._map._rotate&&(t.rotate=this._rotateReposition,t.rotateend=this._rotateEnd),t};var y=t.Marker.prototype._setPos;t.Marker.prototype._setPos=function(i){this._map&&this._map._rotate&&this._map._bearing&&(i=this._map.rotatedPointToMapPanePoint(i)),y?y.call(this,i):(t.DomUtil.setPosition(this._icon,i),this._shadow&&t.DomUtil.setPosition(this._shadow,i),this._zIndex=i.y+this.options.zIndexOffset,this._resetZIndex())};var R=t.Marker.prototype.update;t.Marker.prototype.update=function(){var i=R.call(this);if(this._icon&&this._map){var e=this.options.rotation||0;if(this.options.rotateWithView&&(e+=this._map._bearing),e||this.options.scale){var o=t.DomUtil.getPosition(this._icon)||new t.Point(0,0),a="translate3d("+o.x+"px,"+o.y+"px,0)";e&&(a+=" rotate("+e+"deg)"),this.options.scale&&(a+=" scale("+this.options.scale+")"),this._icon.style[t.DomUtil.TRANSFORM]=a}}return i},t.Marker.prototype._rotateReposition=function(){var i=this._map;if(i&&this._icon){var e;i._rotInertia&&this._rotLayerPt?e=this._rotLayerPt:(e=i.latLngToLayerPoint(this._latlng),i._rotInertia&&(this._rotLayerPt=e)),this._setPos(e);var o=this.options.rotation||0;if(this.options.rotateWithView&&(o+=i._bearing),o||this.options.scale){var a=t.DomUtil.getPosition(this._icon)||new t.Point(0,0),n="translate3d("+a.x+"px,"+a.y+"px,0)";o&&(n+=" rotate("+o+"deg)"),this.options.scale&&(n+=" scale("+this.options.scale+")"),this._icon.style[t.DomUtil.TRANSFORM]=n}}},t.Marker.prototype._rotateEnd=function(){this._rotLayerPt=null,this.update()};var P=t.Marker.prototype._resetZIndex;t.Marker.prototype._resetZIndex=function(){if(!this._map||!this._map._rotating)return P.call(this)};var T=t.Icon.prototype._setIconStyles;if(t.Icon.prototype._setIconStyles=function(i,e){T.call(this,i,e);var o=this.options.iconAnchor||this.options.shadowAnchor;o&&(i.style[t.DomUtil.TRANSFORM+"Origin"]=o[0]+"px "+o[1]+"px")},t.DivOverlay){var M=t.DivOverlay.prototype.getEvents;t.DivOverlay.prototype.getEvents=function(){var t=M.call(this);return this._map&&this._map._rotate&&(t.rotate=this._updatePosition),t}}if(t.Popup){var b=t.Popup.prototype._updatePosition;t.Popup.prototype._updatePosition=function(){if(this._map){if(!this._map._rotate||!this._map._bearing)return b.call(this);var i=this._map.latLngToLayerPoint(this._latlng),e=this._map.rotatedPointToMapPanePoint(i),o=t.point(this.options.offset),a=this._getAnchor();t.DomUtil.setPosition(this._container,e.add(a)),this._containerBottom=-o.y,this._containerLeft=-Math.round(this._containerWidth/2)+o.x,this._container.style.bottom=this._containerBottom+"px",this._container.style.left=this._containerLeft+"px"}};var D=t.Popup.prototype._animateZoom;t.Popup.prototype._animateZoom=function(i){if(!this._map||!this._map._rotate||!this._map._bearing)return D?D.call(this,i):void 0;var e=this._map._latLngToNewLayerPoint(this._latlng,i.zoom,i.center);e=this._map.rotatedPointToMapPanePoint(e);var o=this._getAnchor();t.DomUtil.setPosition(this._container,e.add(o))};var E=t.Popup.prototype._adjustPan;t.Popup.prototype._adjustPan=function(){this._map&&this._map._rotate||E&&E.call(this)}}if(t.Tooltip){var A=t.Tooltip.prototype._updatePosition;t.Tooltip.prototype._updatePosition=function(){if(this._map){if(!this._map._rotate||!this._map._bearing)return A.call(this);var t=this._map.latLngToLayerPoint(this._latlng);this._setPosition(this._map.rotatedPointToMapPanePoint(t))}};var L=t.Tooltip.prototype._animateZoom;t.Tooltip.prototype._animateZoom=function(t){if(!this._map||!this._map._rotate||!this._map._bearing)return L?L.call(this,t):void 0;var i=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center);this._setPosition(this._map.rotatedPointToMapPanePoint(i))}}if(t.Map.TouchGestures=t.Handler.extend({_ROTATION_THRESHOLD:30*i,_SCALE_THRESHOLD:.04,_SCALE_THRESHOLD_ROT:.12,_MOVE_THRESHOLD:4,_ZOOM_EPS:.01,_PAN_EPS:2,_ZOOM_SNAP_STEP:0,_ROT_INERTIA:!0,_ROT_DECAY:.0018,_ROT_MIN_VELOCITY:.004,_ROT_MAX_VELOCITY:1.2,_ROT_VELOCITY_SMOOTH:.4,_ROT_STALE_MS:80,addHooks:function(){t.DomEvent.on(this._map._container,"touchstart",this._onTouchStart,this),t.DomEvent.on(this._map._container,"touchmove",this._onTouchMove,this),t.DomEvent.on(this._map._container,"touchend touchcancel",this._onTouchEnd,this)},removeHooks:function(){t.DomEvent.off(this._map._container,"touchstart",this._onTouchStart,this),t.DomEvent.off(this._map._container,"touchmove",this._onTouchMove,this),t.DomEvent.off(this._map._container,"touchend touchcancel",this._onTouchEnd,this)},_onTouchStart:function(i){if(this._stopRotateInertia(),i.touches&&2===i.touches.length){var e=this._map;e.dragging&&e.dragging.enabled()&&(this._draggingWasEnabled=!0,e.dragging.disable()),e._stop&&e._stop(),this._rotVelocity=0,this._lastRotTime=0,this._lastRotBearing=0,e.stopHeadingUp(),e._commitRotatePan();var o=e.mouseEventToContainerPoint(i.touches[0]),a=e.mouseEventToContainerPoint(i.touches[1]);this._startDist=o.distanceTo(a),this._startDist<1?this._active=!1:(this._touchZoomCenter="center"===e.options.touchZoom,this._centerPoint=e.getSize().divideBy(2),this._startCenter=e.getCenter(),this._startMidpoint=this._touchZoomCenter?this._centerPoint:o.add(a).divideBy(2),this._startAngle=Math.atan2(a.y-o.y,a.x-o.x),this._startBearing=e.getBearing(),this._startBearingRad=e._bearingRad||0,this._startZoom=e.getZoom(),this._anchorLatLng=this._touchZoomCenter?this._startCenter:e.containerPointToLatLng(this._startMidpoint),this._moved=!1,this._active=!0,this._rotationActive=!1,this._scaleActive=!1,this.zoom=!1,this._lastMoveZoom=this._startZoom,this._lastMoveMidpoint=this._startMidpoint,t.DomEvent.preventDefault(i))}else this._active=!1},_onTouchMove:function(i){if(i.touches&&2===i.touches.length&&this._active){for(var o=this._map,a=o.mouseEventToContainerPoint(i.touches[0]),n=o.mouseEventToContainerPoint(i.touches[1]),s=this._touchZoomCenter?this._centerPoint:a.add(n).divideBy(2),r=a.distanceTo(n),h=Math.atan2(n.y-a.y,n.x-a.x),_=s.distanceTo(this._startMidpoint),p=r/this._startDist,l=Math.abs(p-1),m=h-this._startAngle;m>Math.PI;)m-=2*Math.PI;for(;m<-Math.PI;)m+=2*Math.PI;var d=o.options.touchRotate&&Math.abs(m)>this._ROTATION_THRESHOLD,c=l>(this._rotationActive?this._SCALE_THRESHOLD_ROT:this._SCALE_THRESHOLD),u=_>this._MOVE_THRESHOLD;if(!this._moved){if(!d&&!c&&!u)return void t.DomEvent.preventDefault(i);o._moveStart(!0,!1),this._moved=!0}var g=this._startZoom;!this._scaleActive&&c&&(this._scaleActive=!0),this._scaleActive&&(g=o.getScaleZoom(p,this._startZoom),!o.options.bounceAtZoomLimits&&(g<o.getMinZoom()&&p<1||g>o.getMaxZoom()&&p>1)&&(g=Math.max(o.getMinZoom(),Math.min(o.getMaxZoom(),g))),this._ZOOM_SNAP_STEP>0&&(g=Math.round(g/this._ZOOM_SNAP_STEP)*this._ZOOM_SNAP_STEP));var f=this._startBearingRad;if(o.options.touchRotate&&(this._rotationActive||Math.abs(m)>this._ROTATION_THRESHOLD&&(this._rotationActive=!0,this._rotRefAngle=h,o._rotating=!0,o.stopHeadingUp(),o.fire("rotatestart")),this._rotationActive)){for(var v=h-this._rotRefAngle;v>Math.PI;)v-=2*Math.PI;for(;v<-Math.PI;)v+=2*Math.PI;var y=!1===o.options.rotateClockwise?-1:1,R=this._startBearing+y*v*e;R=(R%360+360)%360,o.setBearing(R),f=o._bearingRad||0;var P="undefined"!=typeof performance&&performance.now?performance.now():Date.now();if(this._lastRotTime){var T=P-this._lastRotTime;if(T>0){for(var M=R-this._lastRotBearing;M>180;)M-=360;for(;M<-180;)M+=360;var b=M/T,D=this._ROT_VELOCITY_SMOOTH;this._rotVelocity=(1-D)*(this._rotVelocity||0)+D*b}}this._lastRotTime=P,this._lastRotBearing=R}var E=Math.abs(g-this._lastMoveZoom)>this._ZOOM_EPS,A=s.distanceTo(this._lastMoveMidpoint)>this._PAN_EPS;if(this._scaleActive&&(E||A)){var L=o.getSize().divideBy(2),C=s.subtract(L),O=o.project(this._anchorLatLng,g).subtract(C.rotate(-f)),S=o.unproject(O,g);this._center=S,this._zoom=g,this.zoom=!0,this._lastMoveZoom=g,this._lastMoveMidpoint=s,this._animRequest&&t.Util.cancelAnimFrame(this._animRequest);var x=t.Util.bind(o._move,o,S,g,{pinch:!0,round:!1},void 0);this._animRequest=t.Util.requestAnimFrame(x,this,!0)}else this._scaleActive||(this._center=this._startCenter,this._zoom=this._startZoom,this.zoom=!1,this._animRequest&&(t.Util.cancelAnimFrame(this._animRequest),this._animRequest=null));t.DomEvent.preventDefault(i)}},_onTouchEnd:function(i){var e=this._map;this._draggingWasEnabled&&e.dragging&&(e.dragging.enable(),this._draggingWasEnabled=!1),this._active&&(this._active=!1,this._moved&&(this._animRequest&&(t.Util.cancelAnimFrame(this._animRequest),this._animRequest=null),this.zoom&&(e.options.zoomAnimation?e._animateZoom(this._center,e._limitZoom(this._zoom),!0,e.options.zoomSnap):e._resetView(this._center,e._limitZoom(this._zoom))),this._rotationActive&&(this._startRotateInertia()||(e._rotating=!1,e.fire("rotateend"))),this.zoom=!1))},_stopRotateInertia:function(){this._rotInertiaReq&&(t.Util.cancelAnimFrame(this._rotInertiaReq),this._rotInertiaReq=null);var i=this._map;i&&i._rotating&&(i._rotating=!1,i._rotInertia=!1,i.fire("rotateend"))},_startRotateInertia:function(){var i=this._map;if(!this._ROT_INERTIA)return!1;var e="undefined"!=typeof performance&&performance.now?performance.now():Date.now();if(!this._lastRotTime||e-this._lastRotTime>this._ROT_STALE_MS||Math.abs(this._rotVelocity||0)<this._ROT_MIN_VELOCITY)return!1;var o=this._rotVelocity,a=this._ROT_MAX_VELOCITY;o>a&&(o=a),o<-a&&(o=-a);var n=this._ROT_DECAY,s=this._ROT_MIN_VELOCITY,r=e,h=this;i._rotInertia=!0,i.fire("rotatestart");var _=function(){var e="undefined"!=typeof performance&&performance.now?performance.now():Date.now(),a=e-r;if(r=e,a<=0&&(a=16),o*=Math.exp(-n*a),Math.abs(o)<s)return h._rotInertiaReq=null,i._rotating=!1,i._rotInertia=!1,void i.fire("rotateend");var p=i.getBearing()+o*a;p=(p%360+360)%360,i.setBearing(p),h._rotInertiaReq=t.Util.requestAnimFrame(_,h)};return this._rotInertiaReq=t.Util.requestAnimFrame(_,this),!0}}),t.Map.addInitHook("addHandler","touchGestures",t.Map.TouchGestures),t.Map.addInitHook(function(){this.options.rotate&&this.options.touchRotate&&(this.touchGestures&&this.touchGestures.enable(),this.touchZoom&&this.touchZoom.disable())}),t.Map.ShiftKeyRotate=t.Handler.extend({_ROTATE_STEP:5,_EASE:.2,addHooks:function(){t.DomEvent.on(this._map._container,"wheel",this._onWheel,this)},removeHooks:function(){t.DomEvent.off(this._map._container,"wheel",this._onWheel,this),this._stopAnim()},_onWheel:function(i){if(i.shiftKey){t.DomEvent.stop(i);var e=this._map;e.stopHeadingUp(),this._animating||e.fire("rotatestart");var o=t.DomEvent.getWheelDelta(i),a=!1===e.options.rotateClockwise?-1:1,n=e.getBearing()-a*o*this._ROTATE_STEP;this._targetBearing=(n%360+360)%360,this._animating||this._startAnim()}},_startAnim:function(){this._animating||(this._animating=!0,this._animRequest=t.Util.requestAnimFrame(this._animate,this,!0))},_stopAnim:function(){this._animRequest&&(t.Util.cancelAnimFrame(this._animRequest),this._animRequest=null),this._animating=!1},_animate:function(){if(this._animating)if(void 0!==this._targetBearing&&null!==this._targetBearing){var i=this._map,e=i.getBearing(),o=this._targetBearing-e;if(o>180&&(o-=360),o<-180&&(o+=360),Math.abs(o)<.1)return i.setBearing(this._targetBearing),void this._stopAnim();i.setBearing(e+o*this._EASE),this._animRequest=t.Util.requestAnimFrame(this._animate,this,!0)}else this._stopAnim()}}),t.Map.addInitHook("addHandler","shiftKeyRotate",t.Map.ShiftKeyRotate),t.Map.addInitHook(function(){this.options.rotate&&this.options.shiftKeyRotate&&this.shiftKeyRotate&&this.shiftKeyRotate.enable()}),t.Map.ScrollWheelZoom){var C=t.Map.ScrollWheelZoom.prototype._onWheelScroll;t.Map.ScrollWheelZoom.prototype._onWheelScroll=function(t){if(!(t.shiftKey&&this._map&&this._map._rotate&&this._map.options.shiftKeyRotate))return C.call(this,t)}}t.Map.DragRotate=t.Handler.extend({_SENSITIVITY:.5,addHooks:function(){t.DomEvent.on(this._map._container,"mousedown",this._onDown,this),t.DomEvent.on(this._map._container,"contextmenu",t.DomEvent.preventDefault)},removeHooks:function(){t.DomEvent.off(this._map._container,"mousedown",this._onDown,this),t.DomEvent.off(this._map._container,"contextmenu",t.DomEvent.preventDefault),this._cleanup()},_onDown:function(i){if(2===i.button){t.DomEvent.preventDefault(i),t.DomEvent.stopPropagation(i);var e=this._map;this._startX=i.clientX,this._startBearing=e.getBearing(),this._moved=!1,e.dragging&&e.dragging.enabled()?(this._draggingWasEnabled=!0,e.dragging.disable()):this._draggingWasEnabled=!1,t.DomEvent.on(document,"mousemove",this._onMove,this),t.DomEvent.on(document,"mouseup",this._onUp,this)}},_onMove:function(t){var i=t.clientX-this._startX;if(this._moved||!(Math.abs(i)<2)){this._moved||this._map.fire("rotatestart"),this._moved=!0,this._map.stopHeadingUp();var e=!1===this._map.options.rotateClockwise?-1:1;this._map.setBearing(this._startBearing+e*i*this._SENSITIVITY)}},_onUp:function(i){this._cleanup(),this._draggingWasEnabled&&this._map.dragging&&this._map.dragging.enable(),this._moved&&(t.DomEvent.preventDefault(i),this._map.fire("rotate"))},_cleanup:function(){t.DomEvent.off(document,"mousemove",this._onMove,this),t.DomEvent.off(document,"mouseup",this._onUp,this)}}),t.Map.addInitHook("addHandler","dragRotate",t.Map.DragRotate),t.Map.addInitHook(function(){this.options.rotate&&this.options.dragRotate&&this.dragRotate&&this.dragRotate.enable()});var O=t.Marker.prototype._initInteraction;t.Marker.prototype._initInteraction=function(){var i=O.call(this);if(this.dragging){var e=Object.getPrototypeOf(this.dragging);if(e&&e._onDrag&&!e._rotateOnDragPatched){e._rotateOnDragPatched=!0;var o=e._onDrag;e._onDrag=function(i){var e=this._marker,a=e._map;if(a&&a._rotate&&a._bearing){var n=t.DomUtil.getPosition(e._icon),s=a.mapPanePointToRotatedPoint(n),r=a.layerPointToLatLng(s);return e._shadow&&t.DomUtil.setPosition(e._shadow,n),e._latlng=r,i.latlng=r,i.oldLatLng=this._oldLatLng,void e.fire("move",i).fire("drag",i)}return o.call(this,i)}}}return i},t.Control.Rotate=t.Control.extend({options:{position:"topleft",closeOnZeroBearing:!0},onAdd:function(i){var e=t.DomUtil.create("div","leaflet-control-rotate leaflet-bar"),o=t.DomUtil.create("a","leaflet-control-rotate-toggle",e);return o.href="#",o.title="Reset rotation",o.setAttribute("role","button"),o.setAttribute("aria-label","Reset rotation"),o.innerHTML='<svg viewBox="0 0 24 24" width="18" height="18" style="display:block;margin:auto;padding:3px"><path d="M12 2L8 8h3v8h2V8h3L12 2z" fill="currentColor"/></svg>',this._link=o,this._container=e,t.DomEvent.disableClickPropagation(e),t.DomEvent.on(o,"click",this._resetBearing,this),i.on("rotate",this._updateDisplay,this),this._updateDisplay(),e},onRemove:function(i){i.off("rotate",this._updateDisplay,this),t.DomEvent.off(this._link,"click",this._resetBearing,this)},_resetBearing:function(i){t.DomEvent.stop(i),this._map.setBearing(0)},_updateDisplay:function(){if(this._map&&this._link){var i=this._map.getBearing();this._link.style[t.DomUtil.TRANSFORM]="rotate("+-i+"deg)",this.options.closeOnZeroBearing&&(this._container.style.display=0===i?"none":"")}}}),t.control.rotate=function(i){return new t.Control.Rotate(i)},t.Map.addInitHook(function(){if(this.options.rotate&&this.options.rotateControl){var i=!0===this.options.rotateControl?{}:this.options.rotateControl;this.rotateControl=t.control.rotate(i),this.addControl(this.rotateControl)}}),t.Control.RotateCompass=t.Control.extend({options:{position:"bottomright",enabled:!1},onAdd:function(i){this._map=i;var e=t.DomUtil.create("div","leaflet-control-rotate-compass leaflet-bar"),o=t.DomUtil.create("a","leaflet-control-rotate-compass-toggle",e);return o.href="#",o.title="Map rotation",o.setAttribute("role","button"),o.setAttribute("aria-label","Map rotation"),o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="22" height="22" fill-rule="evenodd" clip-rule="evenodd" style="display:block;transform-origin:center;transform-box:fill-box"><path fill="#ebebeb" stroke="#333" stroke-width=".6" d="m11.81.44 3.6 11.27h-7.2z"/><path fill="#b95358" stroke="#333" stroke-width=".6" d="m11.81 23.18-3.6-11.27h7.2z"/></svg>',this._needle=o.firstChild,this._link=o,this._container=e,t.DomEvent.disableClickPropagation(e),t.DomEvent.on(o,"click",this._toggleRotation,this),i.on("rotate",this._updateDisplay,this),this.options.enabled?this._enableRotation():this._disableRotation(),e},onRemove:function(i){i.off("rotate",this._updateDisplay,this),t.DomEvent.off(this._link,"click",this._toggleRotation,this)},_toggleRotation:function(i){t.DomEvent.stop(i),this._enabled?this._disableRotation():this._enableRotation()},_disableRotation:function(){this._enabled=!1,this._map.dragRotate&&this._map.dragRotate.disable(),this._map.touchGestures&&this._map.touchGestures.disable(),this._map.touchZoom&&this._map.touchZoom.enable(),this._map.shiftKeyRotate&&this._map.shiftKeyRotate.disable(),this._map.setBearing(0),this._updateDisplay()},_enableRotation:function(){this._enabled=!0,this._map.dragRotate&&this._map.options.dragRotate&&this._map.dragRotate.enable(),this._map.touchGestures&&this._map.options.touchRotate&&(this._map.touchGestures.enable(),this._map.touchZoom&&this._map.touchZoom.disable()),this._map.shiftKeyRotate&&this._map.options.shiftKeyRotate&&this._map.shiftKeyRotate.enable(),this._updateDisplay()},_updateDisplay:function(){if(this._map&&this._link){var i=this._map.getBearing();this._needle&&(this._needle.style[t.DomUtil.TRANSFORM]="rotate("+-i+"deg)"),this._enabled?t.DomUtil.removeClass(this._container,"leaflet-rotate-compass--inactive"):t.DomUtil.addClass(this._container,"leaflet-rotate-compass--inactive")}}}),t.control.rotateCompass=function(i){return new t.Control.RotateCompass(i)},t.Map.addInitHook(function(){if(this.options.rotate&&this.options.rotateCompassControl){var i=!0===this.options.rotateCompassControl?{}:this.options.rotateCompassControl;this.rotateCompassControl=t.control.rotateCompass(i),this.addControl(this.rotateCompassControl)}}),t.Map.mergeOptions({preventPageGestures:!0}),t.Map.addInitHook(function(){if(this.options.preventPageGestures){var t=["gesturestart","gesturechange","gestureend"],i=function(t){t.preventDefault()};t.forEach(function(t){document.addEventListener(t,i,{passive:!1})}),this.on("unload",function(){t.forEach(function(t){document.removeEventListener(t,i,{passive:!1})})})}});const S=document.createElement("style");S.textContent=[".leaflet-rotate-pane { position: absolute; top: 0; left: 0; will-change: transform; }",".leaflet-norotate-pane { position: absolute; top: 0; left: 0; z-index: 600; }"].join("\n"),document.head.appendChild(S)});
2
+ !function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(require("leaflet")):"function"==typeof define&&define.amd?define(["leaflet"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).L)}(this,function(t){"use strict";t.Point.prototype.rotate=function(i){var e=Math.cos(i),o=Math.sin(i);return new t.Point(this.x*e-this.y*o,this.x*o+this.y*e)},t.Point.prototype.rotateFrom=function(t,i){return i?this.subtract(i).rotate(t).add(i):this.rotate(t)},t.DomUtil.setTransform=function(i,e,o,a,n){var s=e||new t.Point(0,0),r="translate3d("+s.x+"px,"+s.y+"px,0)";null!=o&&(r+=" scale("+o+")"),a&&(r+=" rotate("+a+"rad)"),i.style[t.DomUtil.TRANSFORM]=r,n&&(i.style[t.DomUtil.TRANSFORM+"Origin"]=n.x+"px "+n.y+"px")},t.DomUtil.setPosition=function(i,e,o,a){i._leaflet_pos=e,t.Browser.any3d?t.DomUtil.setTransform(i,e,void 0,o,a):(i.style.left=e.x+"px",i.style.top=e.y+"px")};const i=Math.PI/180,e=180/Math.PI;var o=t.Map.prototype;t.Map.mergeOptions({rotate:!1,bearing:0,touchRotate:!1,shiftKeyRotate:!1,dragRotate:!0,rotateControl:!1,rotateClockwise:!0});var a=o.initialize;o.initialize=function(t,i){i&&i.rotate&&(this._rotate=!0,this._bearing=0,this._bearingRad=0),a.call(this,t,i),this._rotate&&this.setBearing(i.bearing||0)};var n=o._initPanes;o._initPanes=function(){if(n.call(this),this._rotate){var i=this._mapPane;this._rotatePane=t.DomUtil.create("div","leaflet-rotate-pane",i),this._norotatePane=t.DomUtil.create("div","leaflet-norotate-pane",i),this._rotatePane.appendChild(this._panes.tilePane),this._rotatePane.appendChild(this._panes.overlayPane),this._norotatePane.appendChild(this._panes.shadowPane),this._norotatePane.appendChild(this._panes.markerPane),this._norotatePane.appendChild(this._panes.tooltipPane),this._norotatePane.appendChild(this._panes.popupPane),t.DomUtil.addClass(this._rotatePane,"leaflet-proxy leaflet-zoom-animated")}},o.setBearing=function(e){if(this._rotate){this._commitRotatePan();var o=this._bearing||0,a=(e%360+360)%360;if(this._bearing=a,this._bearingRad=a*i,this._updateRotatePaneTransform(),0===o!=(0===a))for(var n in this._layers){var s=this._layers[n];s instanceof t.Renderer&&s._update()}this.fire("rotate")}},o.getBearing=function(){return this._bearing||0},o._updateRotatePaneTransform=function(){if(this._rotatePane){if(!this._bearing)return this._rotatePane.style[t.DomUtil.TRANSFORM]="",void(this._rotatePane.style[t.DomUtil.TRANSFORM+"Origin"]="");var i=this.getSize().divideBy(2);this._rotatePane.style[t.DomUtil.TRANSFORM+"Origin"]=i.x+"px "+i.y+"px",this._rotatePane.style[t.DomUtil.TRANSFORM]="rotate("+this._bearingRad+"rad)"}},o._commitRotatePan=function(){if(this._rotate&&!this._committingRotatePan){var t=this._getMapPanePos();!t||0===t.x&&0===t.y||(this._committingRotatePan=!0,this._resetView(this.getCenter(),this.getZoom(),!0),this._committingRotatePan=!1)}};var s=o.containerPointToLayerPoint;o.containerPointToLayerPoint=function(i){if(!this._rotate||!this._bearing)return s.call(this,i);var e=t.point(i),o=this._getMapPanePos(),a=this.getSize().divideBy(2);return e.subtract(o).subtract(a).rotate(-this._bearingRad).add(a)};var r=o.layerPointToContainerPoint;o.layerPointToContainerPoint=function(i){if(!this._rotate||!this._bearing)return r.call(this,i);var e=t.point(i),o=this._getMapPanePos(),a=this.getSize().divideBy(2);return e.subtract(a).rotate(this._bearingRad).add(a).add(o)},o.rotatedPointToMapPanePoint=function(i){if(!this._bearing)return t.point(i);var e=this.getSize().divideBy(2);return t.point(i).rotateFrom(this._bearingRad,e)},o.mapPanePointToRotatedPoint=function(i){if(!this._bearing)return t.point(i);var e=this.getSize().divideBy(2);return t.point(i).rotateFrom(-this._bearingRad,e)};var h=o._getCenterOffset;o._getCenterOffset=function(t){return this._rotate&&this._bearing?this.project(t).subtract(this.project(this.getCenter())).rotate(this._bearingRad):h.call(this,t)};var _=o.getBounds;o.getBounds=function(){if(!this._rotate||!this._bearing)return _.call(this);var i=this.getSize(),e=t.latLngBounds();return e.extend(this.containerPointToLatLng(t.point(0,0))),e.extend(this.containerPointToLatLng(t.point(i.x,0))),e.extend(this.containerPointToLatLng(t.point(i.x,i.y))),e.extend(this.containerPointToLatLng(t.point(0,i.y))),e},o.mapBoundsToContainerBounds=function(i){return t.bounds([this.latLngToContainerPoint(i.getNorthWest()),this.latLngToContainerPoint(i.getNorthEast()),this.latLngToContainerPoint(i.getSouthEast()),this.latLngToContainerPoint(i.getSouthWest())])};var p=o.getBoundsZoom;o.getBoundsZoom=function(i,e,o){if(!this._rotate||!this._bearing)return p.call(this,i,e,o);i=t.latLngBounds(i),o=t.point(o||[0,0]);var a=this.getZoom()||0,n=this.getMinZoom(),s=this.getMaxZoom(),r=this.getSize().subtract(o);if(r.x<=0||r.y<=0)return a;var h=this.mapBoundsToContainerBounds(i).getSize(),_=this.options.zoomSnap,l=r.x/h.x,m=r.y/h.y,d=e?Math.max(l,m):Math.min(l,m);return a=this.getScaleZoom(d,a),_&&(a=Math.round(a/_)*_),Math.max(n,Math.min(s,a))},o._animateZoomNoDelay=function(t,i,e){this._mapPane&&(e&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=i),this._move(this._animateToCenter,this._animateToZoom,void 0,!0),this._onZoomTransitionEnd())};var l=o._tryAnimatedZoom;o._tryAnimatedZoom=function(t,i,e){if(this._rotate&&this._bearing&&!this._animatingZoom){var o=this._getMapPanePos();o&&(o.x||o.y)&&this._resetView(this.getCenter(),this.getZoom(),!0)}return l.call(this,t,i,e)},t.Map.addInitHook(function(){this._rotate&&this.on("resize",this._updateRotatePaneTransform,this)});var m=t.GridLayer.prototype.getEvents;t.GridLayer.prototype.getEvents=function(){var t=m.call(this);return this._map&&this._map._rotate&&(t.rotate=this._onRotate),t},t.GridLayer.prototype._onRotate=function(){this._update()};var d=t.GridLayer.prototype._getTiledPixelBounds;t.GridLayer.prototype._getTiledPixelBounds=function(i){if(!this._map._rotate||!this._map._bearing)return d.call(this,i);for(var e=this._map,o=e._animatingZoom?Math.max(e._animateToZoom,e.getZoom()):e.getZoom(),a=e.getZoomScale(o,this._tileZoom),n=e.project(i,this._tileZoom).floor(),s=e.getSize().divideBy(2*Math.min(a,1)).multiplyBy(1.25),r=new t.Bounds,h=[t.point(-s.x,-s.y),t.point(s.x,-s.y),t.point(s.x,s.y),t.point(-s.x,s.y)],_=0;_<4;_++)r.extend(n.add(h[_].rotate(-e._bearingRad)));return r};var c=t.Renderer.prototype.onAdd;t.Renderer.prototype.onAdd=function(i){c.call(this,i),i._rotate&&t.DomUtil.addClass(this._container,"leaflet-zoom-animated")};var u=t.Renderer.prototype._updateTransform;t.Renderer.prototype._updateTransform=function(i,e){if(!this._map||!this._map._rotate||!this._map._bearing)return u.call(this,i,e);if(this._bounds&&this._boundsMinLatLng){var o=this._map,a=o.getZoomScale(e,this._zoom),n=o._latLngToNewLayerPoint(this._boundsMinLatLng,e,i);t.DomUtil.setTransform(this._container,n,a)}};var g=t.Renderer.prototype._update;t.Renderer.prototype._update=function(){if(!this._map||!this._map._rotate||!this._map._bearing)return g.call(this);var i=Math.max(this.options.padding||0,1.5),e=this._map,o=e.getSize(),a=e.containerPointToLayerPoint(o.divideBy(2)),n=o.multiplyBy(.5+i),s=Math.ceil(Math.sqrt(n.x*n.x+n.y*n.y));this._bounds=new t.Bounds(a.subtract([s,s]).round(),a.add([s,s]).round()),this._center=e.getCenter(),this._zoom=e.getZoom(),this._boundsMinLatLng=e.layerPointToLatLng(this._bounds.min)};const f=t.Map.prototype;f.setHeading=function(t,i){return this._rotate?null==t||isNaN(t)?this.stopHeadingUp():(i=i||{},this._headingUp=!0,this._headingEase=null!=i.ease?i.ease:.2,this._headingDeadzone=null!=i.deadzone?i.deadzone:.5,this._headingTarget=(-t%360+360)%360,this._startHeadingAnim(),this):this},f.stopHeadingUp=function(){return this._headingUp=!1,this._headingRAF&&(t.Util.cancelAnimFrame(this._headingRAF),this._headingRAF=null),this},f.getHeadingUp=function(){return!!this._headingUp},f._startHeadingAnim=function(){this._headingRAF||(this._headingRAF=t.Util.requestAnimFrame(this._headingAnim,this))},f._headingAnim=function(){if(this._headingRAF=null,this._headingUp){for(var i=this.getBearing(),e=this._headingTarget-i;e>180;)e-=360;for(;e<-180;)e+=360;Math.abs(e)<this._headingDeadzone?Math.abs(e)>.001&&this.setBearing(this._headingTarget):(this.setBearing(i+e*this._headingEase),this._headingRAF=t.Util.requestAnimFrame(this._headingAnim,this))}},t.Marker.mergeOptions({rotation:0,rotateWithView:!1,scale:void 0});var v=t.Marker.prototype.getEvents;t.Marker.prototype.getEvents=function(){var t=v.call(this);return this._map&&this._map._rotate&&(t.rotate=this._rotateReposition,t.rotateend=this._rotateEnd),t};var y=t.Marker.prototype._setPos;t.Marker.prototype._setPos=function(i){this._map&&this._map._rotate&&this._map._bearing&&(i=this._map.rotatedPointToMapPanePoint(i)),y?y.call(this,i):(t.DomUtil.setPosition(this._icon,i),this._shadow&&t.DomUtil.setPosition(this._shadow,i),this._zIndex=i.y+this.options.zIndexOffset,this._resetZIndex())};var P=t.Marker.prototype.update;t.Marker.prototype.update=function(){var i=P.call(this);if(this._icon&&this._map){var e=this.options.rotation||0;if(this.options.rotateWithView&&(e+=this._map._bearing),e||this.options.scale){var o=t.DomUtil.getPosition(this._icon)||new t.Point(0,0),a="translate3d("+o.x+"px,"+o.y+"px,0)";e&&(a+=" rotate("+e+"deg)"),this.options.scale&&(a+=" scale("+this.options.scale+")"),this._icon.style[t.DomUtil.TRANSFORM]=a}}return i},t.Marker.prototype._rotateReposition=function(){var i=this._map;if(i&&this._icon){var e;i._rotInertia&&this._rotLayerPt?e=this._rotLayerPt:(e=i.latLngToLayerPoint(this._latlng),i._rotInertia&&(this._rotLayerPt=e)),this._setPos(e);var o=this.options.rotation||0;if(this.options.rotateWithView&&(o+=i._bearing),o||this.options.scale){var a=t.DomUtil.getPosition(this._icon)||new t.Point(0,0),n="translate3d("+a.x+"px,"+a.y+"px,0)";o&&(n+=" rotate("+o+"deg)"),this.options.scale&&(n+=" scale("+this.options.scale+")"),this._icon.style[t.DomUtil.TRANSFORM]=n}}},t.Marker.prototype._rotateEnd=function(){this._rotLayerPt=null,this.update()};var R=t.Marker.prototype._resetZIndex;t.Marker.prototype._resetZIndex=function(){if(!this._map||!this._map._rotating)return R.call(this)};var T=t.Icon.prototype._setIconStyles;if(t.Icon.prototype._setIconStyles=function(i,e){T.call(this,i,e);var o=this.options.iconAnchor||this.options.shadowAnchor;o&&(i.style[t.DomUtil.TRANSFORM+"Origin"]=o[0]+"px "+o[1]+"px")},t.DivOverlay){var M=t.DivOverlay.prototype.getEvents;t.DivOverlay.prototype.getEvents=function(){var t=M.call(this);return this._map&&this._map._rotate&&(t.rotate=this._updatePosition),t}}if(t.Popup){var b=t.Popup.prototype._updatePosition;t.Popup.prototype._updatePosition=function(){if(this._map){if(!this._map._rotate||!this._map._bearing)return b.call(this);var i=this._map.latLngToLayerPoint(this._latlng),e=this._map.rotatedPointToMapPanePoint(i),o=t.point(this.options.offset),a=this._getAnchor();t.DomUtil.setPosition(this._container,e.add(a)),this._containerBottom=-o.y,this._containerLeft=-Math.round(this._containerWidth/2)+o.x,this._container.style.bottom=this._containerBottom+"px",this._container.style.left=this._containerLeft+"px"}};var D=t.Popup.prototype._animateZoom;t.Popup.prototype._animateZoom=function(i){if(!this._map||!this._map._rotate||!this._map._bearing)return D?D.call(this,i):void 0;var e=this._map._latLngToNewLayerPoint(this._latlng,i.zoom,i.center);e=this._map.rotatedPointToMapPanePoint(e);var o=this._getAnchor();t.DomUtil.setPosition(this._container,e.add(o))};var E=t.Popup.prototype._adjustPan;t.Popup.prototype._adjustPan=function(){this._map&&this._map._rotate||E&&E.call(this)}}if(t.Tooltip){var A=t.Tooltip.prototype._updatePosition;t.Tooltip.prototype._updatePosition=function(){if(this._map){if(!this._map._rotate||!this._map._bearing)return A.call(this);var t=this._map.latLngToLayerPoint(this._latlng);this._setPosition(this._map.rotatedPointToMapPanePoint(t))}};var L=t.Tooltip.prototype._animateZoom;t.Tooltip.prototype._animateZoom=function(t){if(!this._map||!this._map._rotate||!this._map._bearing)return L?L.call(this,t):void 0;var i=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center);this._setPosition(this._map.rotatedPointToMapPanePoint(i))}}if(t.Map.TouchGestures=t.Handler.extend({_ROTATION_THRESHOLD:30*i,_SCALE_THRESHOLD:.04,_SCALE_THRESHOLD_ROT:.12,_MOVE_THRESHOLD:4,_ZOOM_EPS:.01,_PAN_EPS:2,_ZOOM_SNAP_STEP:0,_ROT_INERTIA:!0,_ROT_DECAY:.0018,_ROT_MIN_VELOCITY:.004,_ROT_MAX_VELOCITY:1.2,_ROT_VELOCITY_SMOOTH:.4,_ROT_STALE_MS:80,addHooks:function(){t.DomEvent.on(this._map._container,"touchstart",this._onTouchStart,this),t.DomEvent.on(this._map._container,"touchmove",this._onTouchMove,this),t.DomEvent.on(this._map._container,"touchend touchcancel",this._onTouchEnd,this)},removeHooks:function(){t.DomEvent.off(this._map._container,"touchstart",this._onTouchStart,this),t.DomEvent.off(this._map._container,"touchmove",this._onTouchMove,this),t.DomEvent.off(this._map._container,"touchend touchcancel",this._onTouchEnd,this)},_onTouchStart:function(i){if(this._stopRotateInertia(),i.touches&&2===i.touches.length){var e=this._map;e.dragging&&e.dragging.enabled()&&(this._draggingWasEnabled=!0,e.dragging.disable()),e._stop&&e._stop(),this._rotVelocity=0,this._lastRotTime=0,this._lastRotBearing=0,e.stopHeadingUp(),e._commitRotatePan();var o=e.mouseEventToContainerPoint(i.touches[0]),a=e.mouseEventToContainerPoint(i.touches[1]);this._startDist=o.distanceTo(a),this._startDist<1?this._active=!1:(this._touchZoomCenter="center"===e.options.touchZoom,this._centerPoint=e.getSize().divideBy(2),this._startCenter=e.getCenter(),this._startMidpoint=this._touchZoomCenter?this._centerPoint:o.add(a).divideBy(2),this._startAngle=Math.atan2(a.y-o.y,a.x-o.x),this._startBearing=e.getBearing(),this._startBearingRad=e._bearingRad||0,this._startZoom=e.getZoom(),this._anchorLatLng=this._touchZoomCenter?this._startCenter:e.containerPointToLatLng(this._startMidpoint),this._moved=!1,this._active=!0,this._rotationActive=!1,this._scaleActive=!1,this.zoom=!1,this._lastMoveZoom=this._startZoom,this._lastMoveMidpoint=this._startMidpoint,t.DomEvent.preventDefault(i))}else this._active=!1},_onTouchMove:function(i){if(i.touches&&2===i.touches.length&&this._active){for(var o=this._map,a=o.mouseEventToContainerPoint(i.touches[0]),n=o.mouseEventToContainerPoint(i.touches[1]),s=this._touchZoomCenter?this._centerPoint:a.add(n).divideBy(2),r=a.distanceTo(n),h=Math.atan2(n.y-a.y,n.x-a.x),_=s.distanceTo(this._startMidpoint),p=r/this._startDist,l=Math.abs(p-1),m=h-this._startAngle;m>Math.PI;)m-=2*Math.PI;for(;m<-Math.PI;)m+=2*Math.PI;var d=o.options.touchRotate&&Math.abs(m)>this._ROTATION_THRESHOLD,c=l>(this._rotationActive?this._SCALE_THRESHOLD_ROT:this._SCALE_THRESHOLD),u=_>this._MOVE_THRESHOLD;if(!this._moved){if(!d&&!c&&!u)return void t.DomEvent.preventDefault(i);o._moveStart(!0,!1),this._moved=!0}var g=this._startZoom;!this._scaleActive&&c&&(this._scaleActive=!0),this._scaleActive&&(g=o.getScaleZoom(p,this._startZoom),!o.options.bounceAtZoomLimits&&(g<o.getMinZoom()&&p<1||g>o.getMaxZoom()&&p>1)&&(g=Math.max(o.getMinZoom(),Math.min(o.getMaxZoom(),g))),this._ZOOM_SNAP_STEP>0&&(g=Math.round(g/this._ZOOM_SNAP_STEP)*this._ZOOM_SNAP_STEP));var f=this._startBearingRad;if(o.options.touchRotate&&(this._rotationActive||Math.abs(m)>this._ROTATION_THRESHOLD&&(this._rotationActive=!0,this._rotRefAngle=h,o._rotating=!0,o.stopHeadingUp(),o.fire("rotatestart")),this._rotationActive)){for(var v=h-this._rotRefAngle;v>Math.PI;)v-=2*Math.PI;for(;v<-Math.PI;)v+=2*Math.PI;var y=!1===o.options.rotateClockwise?-1:1,P=this._startBearing+y*v*e;P=(P%360+360)%360,o.setBearing(P),f=o._bearingRad||0;var R="undefined"!=typeof performance&&performance.now?performance.now():Date.now();if(this._lastRotTime){var T=R-this._lastRotTime;if(T>0){for(var M=P-this._lastRotBearing;M>180;)M-=360;for(;M<-180;)M+=360;var b=M/T,D=this._ROT_VELOCITY_SMOOTH;this._rotVelocity=(1-D)*(this._rotVelocity||0)+D*b}}this._lastRotTime=R,this._lastRotBearing=P}var E=Math.abs(g-this._lastMoveZoom)>this._ZOOM_EPS,A=s.distanceTo(this._lastMoveMidpoint)>this._PAN_EPS;if(this._scaleActive&&(E||A)){var L=o.getSize().divideBy(2),O=s.subtract(L),S=o.project(this._anchorLatLng,g).subtract(O.rotate(-f)),x=o.unproject(S,g);this._center=x,this._zoom=g,this.zoom=!0,this._lastMoveZoom=g,this._lastMoveMidpoint=s,this._animRequest&&t.Util.cancelAnimFrame(this._animRequest);var C=t.Util.bind(o._move,o,x,g,{pinch:!0,round:!1},void 0);this._animRequest=t.Util.requestAnimFrame(C,this,!0)}else this._scaleActive||(this._center=this._startCenter,this._zoom=this._startZoom,this.zoom=!1,this._animRequest&&(t.Util.cancelAnimFrame(this._animRequest),this._animRequest=null));t.DomEvent.preventDefault(i)}},_onTouchEnd:function(i){var e=this._map;this._draggingWasEnabled&&e.dragging&&(e.dragging.enable(),this._draggingWasEnabled=!1),this._active&&(this._active=!1,this._moved&&(this._animRequest&&(t.Util.cancelAnimFrame(this._animRequest),this._animRequest=null),this.zoom&&(e.options.zoomAnimation?e._animateZoom(this._center,e._limitZoom(this._zoom),!0,e.options.zoomSnap):e._resetView(this._center,e._limitZoom(this._zoom))),this._rotationActive&&(this._startRotateInertia()||(e._rotating=!1,e.fire("rotateend"))),this.zoom=!1))},_stopRotateInertia:function(){this._rotInertiaReq&&(t.Util.cancelAnimFrame(this._rotInertiaReq),this._rotInertiaReq=null);var i=this._map;i&&i._rotating&&(i._rotating=!1,i._rotInertia=!1,i.fire("rotateend"))},_startRotateInertia:function(){var i=this._map;if(!this._ROT_INERTIA)return!1;var e="undefined"!=typeof performance&&performance.now?performance.now():Date.now();if(!this._lastRotTime||e-this._lastRotTime>this._ROT_STALE_MS||Math.abs(this._rotVelocity||0)<this._ROT_MIN_VELOCITY)return!1;var o=this._rotVelocity,a=this._ROT_MAX_VELOCITY;o>a&&(o=a),o<-a&&(o=-a);var n=this._ROT_DECAY,s=this._ROT_MIN_VELOCITY,r=e,h=this;i._rotInertia=!0,i.fire("rotatestart");var _=function(){var e="undefined"!=typeof performance&&performance.now?performance.now():Date.now(),a=e-r;if(r=e,a<=0&&(a=16),o*=Math.exp(-n*a),Math.abs(o)<s)return h._rotInertiaReq=null,i._rotating=!1,i._rotInertia=!1,void i.fire("rotateend");var p=i.getBearing()+o*a;p=(p%360+360)%360,i.setBearing(p),h._rotInertiaReq=t.Util.requestAnimFrame(_,h)};return this._rotInertiaReq=t.Util.requestAnimFrame(_,this),!0}}),t.Map.addInitHook("addHandler","touchGestures",t.Map.TouchGestures),t.Map.addInitHook(function(){this.options.rotate&&this.options.touchRotate&&(this.touchGestures&&this.touchGestures.enable(),this.touchZoom&&this.touchZoom.disable())}),t.Map.ShiftKeyRotate=t.Handler.extend({_ROTATE_STEP:5,_EASE:.2,addHooks:function(){t.DomEvent.on(this._map._container,"wheel",this._onWheel,this)},removeHooks:function(){t.DomEvent.off(this._map._container,"wheel",this._onWheel,this),this._stopAnim()},_onWheel:function(i){if(i.shiftKey){t.DomEvent.stop(i);var e=this._map;e.stopHeadingUp(),this._animating||e.fire("rotatestart");var o=t.DomEvent.getWheelDelta(i),a=!1===e.options.rotateClockwise?-1:1,n=e.getBearing()-a*o*this._ROTATE_STEP;this._targetBearing=(n%360+360)%360,this._animating||this._startAnim()}},_startAnim:function(){this._animating||(this._animating=!0,this._animRequest=t.Util.requestAnimFrame(this._animate,this,!0))},_stopAnim:function(){this._animRequest&&(t.Util.cancelAnimFrame(this._animRequest),this._animRequest=null),this._animating=!1},_animate:function(){if(this._animating)if(void 0!==this._targetBearing&&null!==this._targetBearing){var i=this._map,e=i.getBearing(),o=this._targetBearing-e;if(o>180&&(o-=360),o<-180&&(o+=360),Math.abs(o)<.1)return i.setBearing(this._targetBearing),void this._stopAnim();i.setBearing(e+o*this._EASE),this._animRequest=t.Util.requestAnimFrame(this._animate,this,!0)}else this._stopAnim()}}),t.Map.addInitHook("addHandler","shiftKeyRotate",t.Map.ShiftKeyRotate),t.Map.addInitHook(function(){this.options.rotate&&this.options.shiftKeyRotate&&this.shiftKeyRotate&&this.shiftKeyRotate.enable()}),t.Map.ScrollWheelZoom){var O=t.Map.ScrollWheelZoom.prototype._onWheelScroll;t.Map.ScrollWheelZoom.prototype._onWheelScroll=function(t){if(!(t.shiftKey&&this._map&&this._map._rotate&&this._map.options.shiftKeyRotate))return O.call(this,t)}}t.Map.DragRotate=t.Handler.extend({_SENSITIVITY:.5,addHooks:function(){t.DomEvent.on(this._map._container,"mousedown",this._onDown,this),t.DomEvent.on(this._map._container,"contextmenu",t.DomEvent.preventDefault)},removeHooks:function(){t.DomEvent.off(this._map._container,"mousedown",this._onDown,this),t.DomEvent.off(this._map._container,"contextmenu",t.DomEvent.preventDefault),this._cleanup()},_onDown:function(i){if(2===i.button){t.DomEvent.preventDefault(i),t.DomEvent.stopPropagation(i);var e=this._map;this._startX=i.clientX,this._startBearing=e.getBearing(),this._moved=!1,e.dragging&&e.dragging.enabled()?(this._draggingWasEnabled=!0,e.dragging.disable()):this._draggingWasEnabled=!1,t.DomEvent.on(document,"mousemove",this._onMove,this),t.DomEvent.on(document,"mouseup",this._onUp,this)}},_onMove:function(t){var i=t.clientX-this._startX;if(this._moved||!(Math.abs(i)<2)){this._moved||this._map.fire("rotatestart"),this._moved=!0,this._map.stopHeadingUp();var e=!1===this._map.options.rotateClockwise?-1:1;this._map.setBearing(this._startBearing+e*i*this._SENSITIVITY)}},_onUp:function(i){this._cleanup(),this._draggingWasEnabled&&this._map.dragging&&this._map.dragging.enable(),this._moved&&(t.DomEvent.preventDefault(i),this._map.fire("rotate"))},_cleanup:function(){t.DomEvent.off(document,"mousemove",this._onMove,this),t.DomEvent.off(document,"mouseup",this._onUp,this)}}),t.Map.addInitHook("addHandler","dragRotate",t.Map.DragRotate),t.Map.addInitHook(function(){this.options.rotate&&this.options.dragRotate&&this.dragRotate&&this.dragRotate.enable()});var S=t.Marker.prototype._initInteraction;t.Marker.prototype._initInteraction=function(){var i=S.call(this);if(this.dragging){var e=Object.getPrototypeOf(this.dragging);if(e&&e._onDrag&&!e._rotateOnDragPatched){e._rotateOnDragPatched=!0;var o=e._onDrag;e._onDrag=function(i){var e=this._marker,a=e._map;if(a&&a._rotate&&a._bearing){var n=t.DomUtil.getPosition(e._icon),s=a.mapPanePointToRotatedPoint(n),r=a.layerPointToLatLng(s);return e._shadow&&t.DomUtil.setPosition(e._shadow,n),e._latlng=r,i.latlng=r,i.oldLatLng=this._oldLatLng,void e.fire("move",i).fire("drag",i)}return o.call(this,i)}}}return i},t.Control.Rotate=t.Control.extend({options:{position:"topleft",behavior:"reset",closeOnZeroBearing:!0,enabled:!1},onAdd:function(i){this._map=i;var e=t.DomUtil.create("div","leaflet-control-rotate leaflet-bar"),o=t.DomUtil.create("a","leaflet-control-rotate-toggle",e);o.href="#",o.setAttribute("role","button");var a="toggle"===this.options.behavior?"Map rotation":"Reset rotation";return o.title=a,o.setAttribute("aria-label",a),o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="22" height="22" fill-rule="evenodd" clip-rule="evenodd" style="display:block;transform-origin:center;transform-box:fill-box"><path fill="#ebebeb" stroke="#333" stroke-width=".6" d="m11.81.44 3.6 11.27h-7.2z"/><path fill="#b95358" stroke="#333" stroke-width=".6" d="m11.81 23.18-3.6-11.27h7.2z"/></svg>',this._needle=o.firstChild,this._link=o,this._container=e,t.DomEvent.disableClickPropagation(e),t.DomEvent.on(o,"click",this._onClick,this),i.on("rotate",this._updateDisplay,this),"toggle"===this.options.behavior?this.options.enabled?this._enableRotation():this._disableRotation():this._updateDisplay(),e},onRemove:function(i){i.off("rotate",this._updateDisplay,this),t.DomEvent.off(this._link,"click",this._onClick,this)},_onClick:function(i){t.DomEvent.stop(i),"toggle"===this.options.behavior?this._enabled?this._disableRotation():this._enableRotation():this._map.setBearing(0)},_disableRotation:function(){this._enabled=!1,this._map.dragRotate&&this._map.dragRotate.disable(),this._map.touchGestures&&this._map.touchGestures.disable(),this._map.touchZoom&&this._map.touchZoom.enable(),this._map.shiftKeyRotate&&this._map.shiftKeyRotate.disable(),this._map.setBearing(0),this._updateDisplay()},_enableRotation:function(){this._enabled=!0,this._map.dragRotate&&this._map.options.dragRotate&&this._map.dragRotate.enable(),this._map.touchGestures&&this._map.options.touchRotate&&(this._map.touchGestures.enable(),this._map.touchZoom&&this._map.touchZoom.disable()),this._map.shiftKeyRotate&&this._map.options.shiftKeyRotate&&this._map.shiftKeyRotate.enable(),this._updateDisplay()},_updateDisplay:function(){if(this._map&&this._link){var i=this._map.getBearing();this._needle&&(this._needle.style[t.DomUtil.TRANSFORM]="rotate("+-i+"deg)"),"toggle"===this.options.behavior?this._enabled?t.DomUtil.removeClass(this._container,"leaflet-control-rotate--inactive"):t.DomUtil.addClass(this._container,"leaflet-control-rotate--inactive"):this.options.closeOnZeroBearing&&(this._container.style.display=0===i?"none":"")}}}),t.control.rotate=function(i){return new t.Control.Rotate(i)},t.Map.addInitHook(function(){if(this.options.rotate&&this.options.rotateControl){var i=!0===this.options.rotateControl?{}:this.options.rotateControl;this.rotateControl=t.control.rotate(i),this.addControl(this.rotateControl)}}),t.Map.mergeOptions({preventPageGestures:!0}),t.Map.addInitHook(function(){if(this.options.preventPageGestures){var t=["gesturestart","gesturechange","gestureend"],i=function(t){t.preventDefault()};t.forEach(function(t){document.addEventListener(t,i,{passive:!1})}),this.on("unload",function(){t.forEach(function(t){document.removeEventListener(t,i,{passive:!1})})})}});const x=document.createElement("style");x.textContent=[".leaflet-rotate-pane { position: absolute; top: 0; left: 0; will-change: transform; }",".leaflet-norotate-pane { position: absolute; top: 0; left: 0; z-index: 600; }"].join("\n"),document.head.appendChild(x)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomickigrzegorz/leaflet-rotate",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Leaflet map rotation engine: bearing, heading-up, touch/drag/keyboard rotate, compass control.",
5
5
  "type": "module",
6
6
  "publishConfig": {