[PLUGINS] +clavettes et dependances
[lhc/web/clavette_www.git] / www / plugins / gis / lib / leaflet / plugins / Marker.Rotate.js
1 /*
2 * Based on comments by @runanet and @coomsie
3 * https://github.com/CloudMade/Leaflet/issues/386
4 *
5 * Wrapping function is needed to preserve L.Marker.update function
6 */
7 (function () {
8 var _old__setPos = L.Marker.prototype._setPos;
9 L.Marker.include({
10 _updateImg: function(i, a, s) {
11 a = L.point(s).divideBy(2)._subtract(L.point(a));
12 var transform = '';
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;
17 },
18
19 setIconAngle: function (iconAngle) {
20 this.options.iconAngle = iconAngle;
21 if (this._map)
22 this.update();
23 },
24
25 _setPos: function (pos) {
26 if (this._icon)
27 this._icon.style[L.DomUtil.TRANSFORM] = '';
28 if (this._shadow)
29 this._shadow.style[L.DomUtil.TRANSFORM] = '';
30
31 _old__setPos.apply(this,[pos]);
32
33 if (this.options.iconAngle) {
34 var a = this.options.icon.options.iconAnchor;
35 var s = this.options.icon.options.iconSize;
36 var i;
37 if (this._icon) {
38 i = this._icon;
39 this._updateImg(i, a, s);
40 }
41 if (this._shadow) {
42 if (this.options.icon.options.shadowAnchor)
43 a = this.options.icon.options.shadowAnchor;
44 s = this.options.icon.options.shadowSize;
45 i = this._shadow;
46 this._updateImg(i, a, s);
47 }
48 }
49 }
50 });
51 }());