lib/leaflet.draw/src/draw/handler/Draw.Polygon.js in leaflet-js-0.6.beta4 vs lib/leaflet.draw/src/draw/handler/Draw.Polygon.js in leaflet-js-0.7.0

- old
+ new

@@ -4,10 +4,11 @@ }, Poly: L.Polygon, options: { + showArea: false, shapeOptions: { stroke: true, color: '#f06eaa', weight: 4, opacity: 0.5, @@ -42,29 +43,50 @@ } } }, _getTooltipText: function () { - var text; + var text, subtext; + if (this._markers.length === 0) { - text = 'Click to start drawing shape.'; + text = L.drawLocal.draw.handlers.polygon.tooltip.start; } else if (this._markers.length < 3) { - text = 'Click to continue drawing shape.'; + text = L.drawLocal.draw.handlers.polygon.tooltip.cont; } else { - text = 'Double click to close this shape.'; + text = L.drawLocal.draw.handlers.polygon.tooltip.end; + subtext = this._getMeasurementString(); } + return { - text: text + text: text, + subtext: subtext }; }, + _getMeasurementString: function () { + var area = this._area; + + if (!area) { + return null; + } + + return L.GeometryUtil.readableArea(area, this.options.metric); + }, + _shapeIsValid: function () { return this._markers.length >= 3; }, _vertexAdded: function () { - //calc area here + // Check to see if we should show the area + if (this.options.allowIntersection || !this.options.showArea) { + return; + } + + var latLngs = this._poly.getLatLngs(); + + this._area = L.GeometryUtil.geodesicArea(latLngs); }, _cleanUpShape: function () { var markerCount = this._markers.length; @@ -74,6 +96,6 @@ if (markerCount > 2) { this._markers[markerCount - 1].off('dblclick', this._finishShape, this); } } } -}); \ No newline at end of file +});