Skip to content
Snippets Groups Projects
Commit fe74997c authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Leaflet.Marker.rotate
This is a plugin for [Leaflet](http://leafletjs.com/). It allows Markers
(map icons) to be rotated using a CSS transform. Rotation is set in degrees.
It is based on comments by users coomsie and runanet on
[Leaflet/issues/386](https://github.com/Leaflet/Leaflet/issues/386).
/*
* Extend Leaflet's Marker to allow setting a rotation in degrees.
*
* Based on comments by @runanet and @coomsie
* https://github.com/Leaflet/Leaflet/issues/386
*
* Wrapping function is needed to preserve L.Marker.update function
*/
(function () {
var _old__setPos = L.Marker.prototype._setPos;
L.Marker.include({
_updateImg: function(i, a, s) {
a = L.point(s).divideBy(2)._subtract(L.point(a));
var transform = '';
transform += ' translate(' + -a.x + 'px, ' + -a.y + 'px)';
transform += ' rotate(' + this.options.iconAngle + 'deg)';
transform += ' translate(' + a.x + 'px, ' + a.y + 'px)';
i.style[L.DomUtil.TRANSFORM] += transform;
},
setIconAngle: function (iconAngle) {
this.options.iconAngle = iconAngle;
if (this._map) this.update();
},
_setPos: function (pos) {
if (this._icon) {
this._icon.style[L.DomUtil.TRANSFORM] = "";
}
if (this._shadow) {
this._shadow.style[L.DomUtil.TRANSFORM] = "";
}
_old__setPos.apply(this,[pos]);
if (this.options.iconAngle) {
var a = this.options.icon.options.iconAnchor;
var s = this.options.icon.options.iconSize;
var i;
if (this._icon) {
i = this._icon;
this._updateImg(i, a, s);
}
}
}
});
}());
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment