Skip to main content

Rotation Mode

Rotation Mode

Rotation Feature

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:

MethodReturnsDescription
enableGlobalRotateMode()-Enables global Rotate Mode.
disableGlobalRotateMode()-Disables global Rotate Mode.
toggleGlobalRotateMode()-Toggles global Rotate Mode.
globalRotateModeEnabled()BooleanReturns true if global Rotate Mode is enabled. false when disabled.

The following methods are available for layers under layer.pm:

MethodReturnsDescription
enableRotate()-Enables Rotate Mode on the layer.
disableRotate()-Disables Rotate Mode on the layer.
rotateEnabled()BooleanReturns 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()DegreesReturns 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()LatLngReturns the center of rotation.

The following events are available on a layer instance:

EventParamsDescriptionOutput
pm:rotateenableeFired when rotation is enabled for a layer.layer, helpLayer, shape
pm:rotatedisableeFired when rotation is disabled for a layer.layer, shape
pm:rotatestarteFired when rotation starts on a layer.layer, helpLayer, startAngle, originLatLngs
pm:rotateeFired when a layer is rotated.layer, helpLayer, startAngle, angle, angleDiff, oldLatLngs, newLatLngs
pm:rotateendeFired when rotation ends on a layer.layer, helpLayer, startAngle, angle, originLatLngs, newLatLngs
pm:changeeFired coordinates of the layer changed.layer, latlngs, shape

The following events are available on a map instance:

EventParamsDescriptionOutput
pm:globalrotatemodetoggledeFired when Rotate Mode is toggled.enabled, map
pm:rotateenableeFired when rotation is enabled for a layer.layer, helpLayer, shape
pm:rotatedisableeFired when rotation is disabled for a layer.layer, shape
pm:rotatestarteFired when rotation starts on a layer.layer, helpLayer, startAngle, originLatLngs
pm:rotateeFired when a layer is rotated.layer, helpLayer, startAngle, angle, angleDiff, oldLatLngs, newLatLngs
pm:rotateendeFired when rotation ends on a layer.layer, helpLayer, startAngle, angle, originLatLngs, newLatLngs

Example

Loading...