Rotation Mode
Rotation Mode

The rotation is clockwise. It starts in the North with 0° and goes over East (90°) and South (180°) to West (270°).
The rotation center is the center (layer.getCenter()) of a Polygon with the LatLngs of the layer.
Rotation of Rectangles:
If a rotated rectangle is created programmatically, it is important to set the initial angle with setInitAngle(degrees).
const rect = L.rectangle(coords).addTo(map); // the Leaflet constructor always creates a non-rotated rectangle
rect.setLatLngs(coords); // setting the rotated coordinates
rect.pm.setInitAngle(angle);
You can enable Rotate Mode for all layers on a map like this:
map.pm.enableGlobalRotateMode();
The following methods are available on map.pm:
| Method | Returns | Description |
|---|---|---|
| enableGlobalRotateMode() | - | Enables global Rotate Mode. |
| disableGlobalRotateMode() | - | Disables global Rotate Mode. |
| toggleGlobalRotateMode() | - | Toggles global Rotate Mode. |
| globalRotateModeEnabled() | Boolean | Returns true if global Rotate Mode is enabled. false when disabled. |
| cancelGlobalRotateMode() | - | Reverts the layers to the state before changing. ⭐ |
The following methods are available for layers under layer.pm:
| Method | Returns | Description |
|---|---|---|
| enableRotate() | - | Enables Rotate Mode on the layer. |
| disableRotate() | - | Disables Rotate Mode on the layer. |
| rotateEnabled() | Boolean | Returns if Rotate Mode is enabled for the layer. |
rotateLayer(degrees) | - | Rotates the layer by x degrees. |
rotateLayerToAngle(degrees) | - | Rotates the layer to x degrees. |
| getAngle() | Degrees | Returns the angle of the layer in degrees. |
setInitAngle(degrees) | - | Set the initial angle of the layer in degrees. |
setRotationCenter(center) | - | Change the center of rotation. Pass null to use the shape's default center. |
| getRotationCenter() | LatLng | Returns the center of rotation. |
| cancel() | - | Reverts the layer to the state before changing. ⭐ |
The following events are available on a layer instance:
| Event | Params | Description | Output |
|---|---|---|---|
| pm:rotateenable | e | Fired when rotation is enabled for a layer. | layer, helpLayer, shape |
| pm:rotatedisable | e | Fired when rotation is disabled for a layer. | layer, shape |
| pm:rotatestart | e | Fired when rotation starts on a layer. | layer, helpLayer, startAngle, originLatLngs |
| pm:rotate | e | Fired when a layer is rotated. | layer, helpLayer, startAngle, angle, angleDiff, oldLatLngs, newLatLngs |
| pm:rotateend | e | Fired when rotation ends on a layer. | layer, helpLayer, startAngle, angle, originLatLngs, newLatLngs |
| pm:change | e | Fired coordinates of the layer changed. | layer, latlngs, shape |
| pm:cancel | e | Fired when the layer changes are canceled. ⭐ | layer |
The following events are available on a map instance:
| Event | Params | Description | Output |
|---|---|---|---|
| pm:globalrotatemodetoggled | e | Fired when Rotate Mode is toggled. | enabled, map |
| pm:rotateenable | e | Fired when rotation is enabled for a layer. | layer, helpLayer, shape |
| pm:rotatedisable | e | Fired when rotation is disabled for a layer. | layer, shape |
| pm:rotatestart | e | Fired when rotation starts on a layer. | layer, helpLayer, startAngle, originLatLngs |
| pm:rotate | e | Fired when a layer is rotated. | layer, helpLayer, startAngle, angle, angleDiff, oldLatLngs, newLatLngs |
| pm:rotateend | e | Fired when rotation ends on a layer. | layer, helpLayer, startAngle, angle, originLatLngs, newLatLngs |
| pm:globalcancel | e | Fired when cancel of a Mode is called. ⭐ | map |
Example
Loading...