leaflet-rotate 0.4.0 → 0.5.1
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 +85 -5
- package/dist/leaflet-rotate-src.js +1325 -254
- package/dist/leaflet-rotate-src.js.map +4 -4
- package/dist/leaflet-rotate.js +1 -1
- package/dist/leaflet-rotate.js.map +4 -4
- package/lib/debug.js +62 -88
- package/lib/debug.min.js +16 -1
- package/misc/leaflet-heat-rotate.js +7 -0
- package/package.json +1 -1
- package/src/control/Rotate.js +160 -103
- package/src/dom/DomUtil.js +23 -12
- package/src/dom/Draggable.js +5 -0
- package/src/geo/LatLngBounds.js +5 -0
- package/src/geometry/Bounds.js +5 -0
- package/src/geometry/Point.js +17 -3
- package/src/index.js +4 -1
- package/src/layer/DivOverlay.js +34 -5
- package/src/layer/Popup.js +14 -3
- package/src/layer/Tooltip.js +16 -0
- package/src/layer/marker/Icon.js +12 -0
- package/src/layer/marker/Marker.js +86 -7
- package/src/layer/tile/GridLayer.js +38 -3
- package/src/layer/vector/Renderer.js +88 -34
- package/src/map/Map.js +578 -116
- package/src/map/handler/CompassBearing.js +34 -1
- package/src/map/handler/ContainerMutation.js +18 -1
- package/src/map/handler/ShiftKeyRotate.js +204 -13
- package/src/map/handler/TouchGestures.js +108 -10
- package/src/map/handler/TouchPitch.js +53 -0
- package/src/map/handler/TouchRotate.js +18 -1
- package/src/map/handler/TouchZoom.js +21 -1
- package/test/features/example.feature +8 -4
- package/test/features/gestures.feature +4 -0
- package/test/features/rotation.feature +60 -0
- package/test/index.html +342 -186
- package/test/steps/bearing.steps.js +535 -0
- package/test/steps/example.steps.js +56 -29
- package/test/steps/gestures.steps.js +55 -0
- package/test/support/hooks.js +4 -16
package/README.md
CHANGED
|
@@ -19,6 +19,90 @@ _For a working example see the following [demo](https://raruto.github.io/leaflet
|
|
|
19
19
|
</p>
|
|
20
20
|
</blockquote>
|
|
21
21
|
|
|
22
|
+
### How to use
|
|
23
|
+
|
|
24
|
+
Load Leaflet first, then the plugin. For example, using the published CDN build:
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9/dist/leaflet.css">
|
|
28
|
+
<script src="https://unpkg.com/leaflet@1.9/dist/leaflet.js"></script>
|
|
29
|
+
<script src="https://unpkg.com/leaflet-rotate@0.5.1/dist/leaflet-rotate.js"></script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or if you want to test it with [`2.0.0-alpha.1`](https://github.com/Leaflet/Leaflet/releases/tag/v2.0.0-alpha.1):
|
|
33
|
+
|
|
34
|
+
```html
|
|
35
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet.css">
|
|
36
|
+
<script src="https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet-global-src.js"></script>
|
|
37
|
+
<script>globalThis.L = globalThis.leaflet;</script>
|
|
38
|
+
<script src="https://unpkg.com/leaflet-rotate@0.5.1/dist/leaflet-rotate.js"></script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Now, you can enable rotation in the map options. Bearing and pitch values are in degrees:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const map = L.map('map', {
|
|
45
|
+
rotate: true,
|
|
46
|
+
bearing: 30,
|
|
47
|
+
pitch: 20,
|
|
48
|
+
rotateControl: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
map.setBearing(90);
|
|
52
|
+
map.setPitch(35);
|
|
53
|
+
console.log(map.getBearing(), map.getPitch());
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Map options
|
|
57
|
+
|
|
58
|
+
| Option | Default | Description |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `rotate` | `false` | Enables map rotation and pitch. |
|
|
61
|
+
| `bearing` | `0` | Initial map bearing, in degrees. |
|
|
62
|
+
| `pitch` | `0` | Initial map pitch, in degrees (clamped to `0`–`85`). |
|
|
63
|
+
| `pitchMaxDistance` | `3` | Far plane for pitched maps, in multiples of the map height: farther areas (and anything beyond the horizon) are not loaded and are covered by the `.leaflet-pitch-sky` element. Lower values load fewer tiles. |
|
|
64
|
+
| `rotateControl` | `true` | Adds the rotation control. Set to `false` to hide it, or pass options such as `{ closeOnZeroBearing: false }`. |
|
|
65
|
+
| `shiftKeyRotate` | `true` | Enables bearing changes with Shift + mouse wheel. |
|
|
66
|
+
| `pitchDrag` | `true` | Enables bearing and pitch changes with Ctrl + mouse drag or right-button drag. |
|
|
67
|
+
| `touchRotate` | `false` | Enables rotation with a two-finger touch gesture. |
|
|
68
|
+
| `touchPitch` | `false` | Enables pitch changes by dragging two fingers vertically. |
|
|
69
|
+
| `compassBearing` | `false` | Makes the bearing follow the device compass. On iOS, enable it from a user gesture (e.g. `map.compassBearing.enable()` in a button click) so that the orientation permission can be requested. |
|
|
70
|
+
|
|
71
|
+
#### Map methods and events
|
|
72
|
+
|
|
73
|
+
| API | Description |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `map.setBearing(degrees, options?)` | Sets the bearing. Use `{ animate: true, duration: 0.5 }` for an animated change; `duration` is in seconds. |
|
|
76
|
+
| `map.getBearing()` | Returns the current bearing in degrees. |
|
|
77
|
+
| `map.setPitch(degrees, options?)` | Sets the pitch, clamped to `0`–`85` degrees. Accepts the same animation options as `setBearing`. |
|
|
78
|
+
| `map.getPitch()` | Returns the current pitch in degrees. |
|
|
79
|
+
| `map.resetNorth(options?)` | Animates the bearing back to `0` (pass `{ animate: false }` to skip the animation). |
|
|
80
|
+
| `map.resetNorthPitch(options?)` | Animates both bearing and pitch back to `0`. |
|
|
81
|
+
| `rotate` event | Fired when the bearing changes. |
|
|
82
|
+
| `pitch` event | Fired when the pitch changes. |
|
|
83
|
+
|
|
84
|
+
#### Rotation control
|
|
85
|
+
|
|
86
|
+
The control is available as `L.Control.Rotate` or `L.control.rotate(options)`. Click it to reset bearing and pitch (`map.resetNorthPitch()`), drag it horizontally to rotate and vertically to change the pitch. The map option `rotateControl` adds it automatically.
|
|
87
|
+
|
|
88
|
+
| Option | Default | Description |
|
|
89
|
+
| --- | --- | --- |
|
|
90
|
+
| `position` | `'topleft'` | Leaflet control position. |
|
|
91
|
+
| `closeOnZeroBearing` | `true` | Hides the control when both bearing and pitch are zero. |
|
|
92
|
+
| `visualizePitch` | `true` | Tilts the icon with the pitch; when `false`, clicking only resets the bearing and dragging only rotates. |
|
|
93
|
+
|
|
94
|
+
#### Marker options
|
|
95
|
+
|
|
96
|
+
| Option / method | Description |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `rotation` | Marker icon rotation in radians. |
|
|
99
|
+
| `rotateWithView` | Rotates the icon with the map bearing. |
|
|
100
|
+
| `keepUpright` | With `rotateWithView: true`, flips the icon as needed to keep it readable while preserving line alignment. |
|
|
101
|
+
| `scale` | Optional scale applied to the marker icon. |
|
|
102
|
+
| `marker.setRotation(radians)` | Updates the marker's icon rotation. |
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
22
106
|
### Build Guide
|
|
23
107
|
|
|
24
108
|
Within your local development environment:
|
|
@@ -41,15 +125,11 @@ After that you can start developing inside the `src` and `test` folders (eg. ope
|
|
|
41
125
|
|
|
42
126
|
Be aware that this library overrides notable parts of leaflet core via the [L.Class.include()](https://leafletjs.com/examples/extending/extending-1-classes.html) function in order to make the rotate feature usable as a standalone plug-in.
|
|
43
127
|
|
|
44
|
-
For [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) or [heatmap.js's Leaflet plugin](https://github.com/pa7/heatmap.js/tree/master/plugins/leaflet-heatmap), load `misc/leaflet-heat-rotate.js` after the heatmap plugin. It adapts heat redraw coordinates to the rotated pane.
|
|
45
|
-
|
|
46
|
-
Markers with `rotateWithView: true` can use `keepUpright: true` to remain readable while preserving their line alignment.
|
|
47
|
-
|
|
48
128
|
Initial changes to this project have been apported by comparing the following branches: [https://github.com/Leaflet/Leaflet/compare/main...fnicollet:rotate-master](https://github.com/Leaflet/Leaflet/compare/main...fnicollet:rotate-master) (ref: [bac6c7d](https://github.com/fnicollet/Leaflet/tree/4ab6342f74516e7087dcd2ae786c721f36addf9e))
|
|
49
129
|
|
|
50
130
|
---
|
|
51
131
|
|
|
52
132
|
**Compatibile with:**
|
|
53
|
-
[](http://leafletjs.com/reference.html) [](http://leafletjs.com/reference.html)
|
|
54
134
|
|
|
55
135
|
**Contributors:** [IvanSanchez](https://github.com/IvanSanchez), [Fnicollet](https://github.com/fnicollet/Leaflet/tree/rotate-master), [Hyperknot](https://github.com/hyperknot), [Raruto](https://github.com/Raruto/leaflet-rotate)
|