|
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
|
|
|
i.style[L.DomUtil.TRANSFORM + 'Origin'] = '50% 50%'; |
|
18
|
|
|
}, |
|
19
|
|
|
|
|
20
|
|
|
_getShortestEndDegree: function (startDegrees, endDegrees) { |
|
21
|
|
|
var turnAngle = Math.abs(endDegrees - startDegrees); |
|
22
|
|
|
var turnAnglePositive = (endDegrees - startDegrees) >= 0; |
|
23
|
|
|
if (turnAngle <= 180) return endDegrees; |
|
|
|
|
|
|
24
|
|
|
var result = startDegrees + (360 - turnAngle) * (turnAnglePositive ? -1 : 1); |
|
25
|
|
|
return result; |
|
26
|
|
|
}, |
|
27
|
|
|
|
|
28
|
|
|
setIconAngle: function (iconAngle) { |
|
29
|
|
|
// find shortest angle to turn over |
|
30
|
|
|
this.options.iconAngle = this._getShortestEndDegree(this.options.iconAngle || 0, iconAngle); |
|
31
|
|
|
if (this._map) |
|
32
|
|
|
this.update(); |
|
|
|
|
|
|
33
|
|
|
}, |
|
34
|
|
|
|
|
35
|
|
|
_setPos: function (pos) { |
|
36
|
|
|
if (this._icon) |
|
37
|
|
|
this._icon.style[L.DomUtil.TRANSFORM] = ''; |
|
|
|
|
|
|
38
|
|
|
if (this._shadow) |
|
39
|
|
|
this._shadow.style[L.DomUtil.TRANSFORM] = ''; |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
_old__setPos.apply(this,[pos]); |
|
42
|
|
|
|
|
43
|
|
|
if (this.options.iconAngle) { |
|
44
|
|
|
var defaultIcon = new L.Icon.Default(); |
|
45
|
|
|
var a = this.options.icon.options.iconAnchor || defaultIcon.options.iconAnchor; |
|
46
|
|
|
var s = this.options.icon.options.iconSize || defaultIcon.options.iconSize; |
|
47
|
|
|
var i; |
|
48
|
|
|
if (this._icon) { |
|
49
|
|
|
i = this._icon; |
|
50
|
|
|
this._updateImg(i, a, s); |
|
51
|
|
|
} |
|
52
|
|
|
if (this._shadow) { |
|
53
|
|
|
if (this.options.icon.options.shadowAnchor) |
|
54
|
|
|
a = this.options.icon.options.shadowAnchor; |
|
|
|
|
|
|
55
|
|
|
s = this.options.icon.options.shadowSize; |
|
56
|
|
|
i = this._shadow; |
|
57
|
|
|
this._updateImg(i, a, s); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
}); |
|
62
|
|
|
}()); |
|
63
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.