Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tngan/1ab61415063d4c078c215f6909801bc8 to your computer and use it in GitHub Desktop.
Save tngan/1ab61415063d4c078c215f6909801bc8 to your computer and use it in GitHub Desktop.
Smooth animation of changing Leaflet marker's position on setLatLng
// just include d3js and add animaDur in ms to marker's option
L.SVG.prototype._setPath = function(layer,path){
if(layer.options.animaDur)
d3.select(layer._path).transition().duration(layer.options.animaDur).ease('linear').attr('d',path)
else
layer._path.setAttribute('d', path);
}
@ngjermundshaug
Copy link

Correct code:

L.SVG.prototype._setPath = function (layer, path) {
      if (layer.options.animaDur) {
        d3.select(layer._path).transition().duration(layer.options.animaDur).ease(d3.easeLinear).attr('d', path);
      }
      else {
        layer._path.setAttribute('d', path);
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment