0
votes

I have a map in leafletJS and when the icon moves along, I have the angle and I am using the Leaflet.RotatedMarker plugin to rotate the icon to face where its heading.

Does leaflet js have a plugin that can enable me to not supply the angle myself ...

L.marker([48.8631169, 2.3708919], {
    rotationAngle: 45
}).addTo(map);

...and instead use a function like gogle maps' computeheading() ?

Edit:

Does mapbox have a function like computeHeading

2

2 Answers

1
votes

https://github.com/bbecquet/Leaflet.RotatedMarker

js:

var boat_marker = L.marker([set_lat, set_long], {
  pid: guid(),
  // rotationAngle: 45,
  icon: boatIcon,
  draggable: true,
}).addTo(mymap);

function rotated_point() {
  boat_marker.setRotationAngle(90);
}
0
votes

No.

Leaflet has only a minimal set of geodesy-related functions. Functions to calculate headings, azymuths, geodesic distances or great circles are not needed for basic Leaflet functionality, and are not included.

A popular approach to this kind of problems is to rely on the javascript bindings of geographiclib for geodesy-related calculations (such as heading/azymuth), in the same way turf.js helps with geoprocessing of vector data.

Note that geographiclib is not a Leaflet plugin, but rather a generic set of geodesic functions. You will need to use a bit of care to get the latitude and longitude components of L.LatLngs, and fetch only the azymuth (and drop the distance) from the solution to the geodesic problem.