如何在小冊子中旋轉標記?我會有很多標記,全部都有旋轉角度。旋轉小冊子中的標記
我試過在Leaflet on GitHub從runanet/coomsie這個解決方案,但沒有任何反應和我的標記:
L.Marker.RotatedMarker= L.Marker.extend({
_reset: function() {
var pos = this._map.latLngToLayerPoint(this._latlng).round();
L.DomUtil.setPosition(this._icon, pos);
if (this._shadow) {
L.DomUtil.setPosition(this._shadow, pos);
}
if (this.options.iconAngle) {
this._icon.style.WebkitTransform = this._icon.style.WebkitTransform + ' rotate(' + this.options.iconAngle + 'deg)';
this._icon.style.MozTransform = 'rotate(' + this.options.iconAngle + 'deg)';
this._icon.style.MsTransform = 'rotate(' + this.options.iconAngle + 'deg)';
this._icon.style.OTransform = 'rotate(' + this.options.iconAngle + 'deg)';
}
this._icon.style.zIndex = pos.y;
},
setIconAngle: function (iconAngle) {
if (this._map) {
this._removeIcon();
}
this.options.iconAngle = iconAngle;
if (this._map) {
this._initIcon();
this._reset();
}
}
});
var rotated = new L.Marker.RotatedMarker([63.42, 10.39]);
rotated.setIconAngle(90);
rotated.addTo(map);
任何其他的想法和解決方案? (在Windows上使用Firefox 16進行測試。)
您的回答幫了我很多,只剩下一個問題:其實我的圖標在第一次繪製時根本不旋轉。試着用「setIconAngle」改變點擊的角度,這個測試對你在代碼中的改變非常有效。但爲什麼我的iconAngle不是第一次使用? – sindrejh
使用this._reset()將標記中的onAdd函數擴展爲解決方法,以便從頭開始旋轉圖標。 – sindrejh
有用的代碼和答案。我已經實施了這個解決方案 - 但我有一個問題。無論何時我在地圖上放大/縮小,標記的旋轉角度都會重置爲0度。你有同樣的問題嗎?當地圖放大/縮小時,標記是否有任何重置其角度的原因? –