Leaflet - Polyline measuring

HTML

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<link rel="stylesheet" href="http://leaflet.github.io/Leaflet.draw/leaflet.draw.css">
<script src="http://leaflet.github.io/Leaflet.draw/leaflet.draw.js"></script>
<button id="drawPolyline">Draw</button>
<button id="clearMap">Clear</button>
<div id="map"></div>

CSS

#map {
    width: 100%;
    height: 600px
}

JavaScript

(function () {
    var __onAdd = L.Polyline.prototype.onAdd,
        __onRemove = L.Polyline.prototype.onRemove,
        __updatePath = L.Polyline.prototype._updatePath,
        __bringToFront = L.Polyline.prototype.bringToFront;

    L.Polyline.include({
      onAdd: function (map) {
          __onAdd.call(this, map);
          this._textRedraw();
      },
      
      onRemove: function (map) {
          __onRemove.call(this, map);
      },
      
      bringToFront: function () {
          __bringToFront.call(this);
          this._textRedraw();
      },
      
      _textRedraw: function () {
      		var textNodes = this._path.parentElement.getElementsByTagName('text'),
          		tnIndex;

					if (textNodes.length > 0) {
          		for (tnIndex = textNodes.length - 1; tnIndex >= 0; tnIndex -= 1) {
              		textNodes[tnIndex].parentNode.removeChild(textNodes[tnIndex]);
              }
          }
          
          if (this.options.measurements) {
              this.setText();
          }
      },
      
      setText: function () {
      		var path = this._path,
            	points = this.getLatLngs(),
            	pathSeg,
            	prevPathSeg,
            	center,
            	angle,
            	rotation,
            	textNode;
          
          /* 
           * If not in SVG mode or Polyline not added to map yet return
           * setText will be called by onAdd, using value stored in this._text
           */
          if (!L.Browser.svg || typeof this._map === 'undefined') {
              return this;
          }

          for (pathSeg = 0; pathSeg < path.pathSegList.length; pathSeg += 1) {
          		if (pathSeg > 0) {
              		prevPathSeg = path.pathSegList[pathSeg - 1];
                  center = this._calcCenter(
                      prevPathSeg.x,
                      prevPathSeg.y,
                      path.pathSegList[pathSeg].x,
                      path.pathSegList[pathSeg].y
                  );                ...