Rotate feature interaction for OpenLayers 3
Plugin adds interaction that allows to rotate vector features around some anchor.
Installation
Install it thought NPM:
npm install ol3-rotate-feature
Or download the latest version archive and add it with script tag:
Usage
Plugin is packed into UMD wrapper, import it with CommonJS or ES6:
;const RotateFeatureInteraction = ;
In Browser environment it is available as ol.interaction.RotateFeature
.
Options
Option | Type | Description |
---|---|---|
features | ol.Collection<ol.Feature> | The features the interaction works on. Required. |
style | ol.style.Style | Array<ol.style.Style> | ol.style.StyleFunction | undefined | Style of the overlay with interaction helper features. |
angle | number | undefined | Initial angle in radians (positive is counter-clockwise), applied for features already added to collection. Default is 0 . |
anchor | number[] | ol.Coordinate | undefined | Initial anchor coordinate. Default is center of features extent. |
Methods
// Set current angle of interaction features.RotateFeatureInteractionprototype
// Returns current angle of interaction features.RotateFeatureInteractionprototype : number
// Set current anchor position.RotateFeatureInteractionprototype
// Returns current anchor position.RotateFeatureInteractionprototype : number | olCoordinate | undefined
Events
All events triggered by the interaction are instances of RotateFeatureEvent
.
Members
- features ol.Collection The features being rotated.
- angle number Current angle in radians.
- anchor ol.Coordinate Current anchor position.
Event | Arguments | Description |
---|---|---|
rotatestart | RotateFeatureEvent | Triggered upon feature rotate start. |
rotating | RotateFeatureEvent | Triggered upon feature rotating. |
rotateend | RotateFeatureEvent | Triggered upon feature rotation end. |
Example usage:
;; const point = name: 'point' geometry: 23842670573564973 7557371884852641;const line = name: 'line' geometry: -6036972100018249 -23943260826165066 419043320404443 29305638287811787;const polygon = name: 'polygon' geometry: -14482348171434438 6661491741627443 -9541458663080638 6221214458704827 -11473786738129886 33007084819848104 -14482348171434438 6661491741627443; const map = view: center: 0 0 zoom: 2 layers: source: layer: 'osm' source: projection: 'EPSG:33857' features: point line polygon target: 'map' projection: 'EPSG:3857'; const features = ;const select = ;const rotate = features: select; rotate;rotate;rotate; map;map;
Example of usage in Browser environment in index.html
.
Getting total angle or last anchor coordinates after rotation:
rotate;
License
MIT (c) 2016, Vladimir Vershinin