code: function (p, p1, p2, sqDist) {
  		var x = p1.x,
  		    y = p1.y,
  		    dx = p2.x - x,
  		    dy = p2.y - y,
  		    dot = dx * dx + dy * dy,
  		    t;
  
  		if (dot > 0) {
  			t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
  
  			if (t > 1) {
  				x = p2.x;
  				y = p2.y;
  			} else if (t > 0) {
  				x += dx * t;
  				y += dy * t;
  			}
  		}
  
  		dx = p.x - x;
  		dy = p.y - y;
  
  		return sqDist ? dx * dx + dy * dy : new L.Point(x, y);
  	}
docs: return closest point on segment or distance to that point