2 * Based on comments by @runanet and @coomsie
3 * https://github.com/CloudMade/Leaflet/issues/386
5 * Wrapping function is needed to preserve L.Marker.update function
8 var _old__setPos
= L
.Marker
.prototype._setPos
;
10 _updateImg: function (i
, a
, s
) {
11 a
= L
.point(s
).divideBy(2)._subtract(L
.point(a
));
13 transform
+= ' translate(' + -a
.x
+ 'px, ' + -a
.y
+ 'px)';
14 transform
+= ' rotate(' + this.options
.iconAngle
+ 'deg)';
15 transform
+= ' translate(' + a
.x
+ 'px, ' + a
.y
+ 'px)';
16 i
.style
[L
.DomUtil
.TRANSFORM
] += transform
;
19 _getShortestEndDegree: function (startDegrees
, endDegrees
) {
20 var turnAngle
= Math
.abs(endDegrees
- startDegrees
);
21 var turnAnglePositive
= (endDegrees
- startDegrees
) >= 0;
22 if (turnAngle
<= 180) return endDegrees
;
23 var result
= startDegrees
+ (360 - turnAngle
) * (turnAnglePositive
? -1 : 1);
27 setIconAngle: function (iconAngle
) {
28 // find shortest angle to turn over
29 this.options
.iconAngle
= this._getShortestEndDegree(this.options
.iconAngle
|| 0, iconAngle
);
34 _setPos: function (pos
) {
36 this._icon
.style
[L
.DomUtil
.TRANSFORM
] = '';
38 this._shadow
.style
[L
.DomUtil
.TRANSFORM
] = '';
40 _old__setPos
.apply(this,[pos
]);
42 if (this.options
.iconAngle
) {
43 var defaultIcon
= new L
.Icon
.Default();
44 var a
= this.options
.icon
.options
.iconAnchor
|| defaultIcon
.options
.iconAnchor
;
45 var s
= this.options
.icon
.options
.iconSize
|| defaultIcon
.options
.iconSize
;
49 this._updateImg(i
, a
, s
);
52 if (this.options
.icon
.options
.shadowAnchor
)
53 a
= this.options
.icon
.options
.shadowAnchor
;
54 s
= this.options
.icon
.options
.shadowSize
;
56 this._updateImg(i
, a
, s
);