Created
January 7, 2015 19:11
-
-
Save bigdragon1977/e7e7707c329e8f5f7d28 to your computer and use it in GitHub Desktop.
Arrows in Leaflet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arrowPolyline = L.Polyline.extend({ | |
| addArrows: function(){ | |
| var points = this.getLatLngs() | |
| for (var p = 0; p +1 < points.length; p++){ | |
| var diffLat = points[p+1]["lat"] - points[p]["lat"] | |
| var diffLng = points[p+1]["lng"] - points[p]["lng"] | |
| var center = [points[p]["lat"] + diffLat/2,points[p]["lng"] + diffLng/2] | |
| var angle = 360 - (Math.atan2(diffLat, diffLng)*57.295779513082) | |
| var arrowM = new L.marker(center,{ | |
| icon: new L.divIcon({ | |
| className : "arrowIcon", | |
| iconSize: new L.Point(30,30), | |
| iconAnchor: new L.Point(15,15), | |
| html : "<div style = 'font-size: 20px; -webkit-transform: rotate("+ angle +"deg)'>➨</div>" | |
| }) | |
| }).addTo(map); | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment