Skip to content

Commit

Permalink
Updating build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtoye committed Sep 15, 2013
1 parent 41df0d0 commit 2f2905d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 57 deletions.
125 changes: 69 additions & 56 deletions dist/leaflet.draw-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ L.Draw.Polyline = L.Draw.Feature.extend({
},

_updateGuide: function (newPos) {
newPos = newPos || this._map.latLngToLayerPoint(this._currentLatLng);

var markerCount = this._markers.length;

if (markerCount > 0) {
newPos = newPos || this._map.latLngToLayerPoint(this._currentLatLng);

// draw the guide line
this._clearGuides();
this._drawGuide(
Expand Down Expand Up @@ -489,29 +489,12 @@ L.Draw.Polyline = L.Draw.Feature.extend({
_getMeasurementString: function () {
var currentLatLng = this._currentLatLng,
previousLatLng = this._markers[this._markers.length - 1].getLatLng(),
distance, distanceStr;
distance;

// calculate the distance from the last fixed point to the mouse position
distance = this._measurementRunningTotal + currentLatLng.distanceTo(previousLatLng);

if (this.options.metric) {
// show metres when distance is < 1km, then show km
if (distance > 1000) {
distanceStr = (distance / 1000).toFixed(2) + ' km';
} else {
distanceStr = Math.ceil(distance) + ' m';
}
} else {
distance *= 1.09361;

if (distance > 1760) {
distanceStr = (distance / 1760).toFixed(2) + ' miles';
} else {
distanceStr = Math.ceil(distance) + ' yd';
}
}

return distanceStr;
return L.GeometryUtil.readableDistance(distance, this.options.metric);
},

_showErrorTooltip: function () {
Expand Down Expand Up @@ -575,6 +558,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({
}
});


L.Draw.Polygon = L.Draw.Polyline.extend({
statics: {
TYPE: 'polygon'
Expand Down Expand Up @@ -640,32 +624,13 @@ L.Draw.Polygon = L.Draw.Polyline.extend({
},

_getMeasurementString: function () {
var area = this._area,
areaStr;
var area = this._area;

if (!area) {
return null;
}

if (this.options.metric) {
if (area >= 10000) {
areaStr = (area * 0.0001).toFixed(2) + ' ha';
} else {
areaStr = area.toFixed(2) + ' m&sup2;';
}
} else {
area *= 0.836127; // Square yards in 1 meter

if (area >= 3097600) { //3097600 square yards in 1 square mile
areaStr = (area / 3097600).toFixed(2) + ' mi&sup2;';
} else if (area >= 4840) {//48040 square yards in 1 acre
areaStr = (area / 4840).toFixed(2) + ' acres';
} else {
areaStr = Math.ceil(area) + ' yd&sup2;';
}
}

return areaStr;
return L.GeometryUtil.readableArea(area, this.options.metric);
},

_shapeIsValid: function () {
Expand All @@ -680,7 +645,7 @@ L.Draw.Polygon = L.Draw.Polyline.extend({

var latLngs = this._poly.getLatLngs();

this._area = L.PolygonUtil.geodesicArea(latLngs);
this._area = L.GeometryUtil.geodesicArea(latLngs);
},

_cleanUpShape: function () {
Expand All @@ -701,10 +666,12 @@ L.SimpleShape = {};

L.Draw.SimpleShape = L.Draw.Feature.extend({
options: {
repeatMode: true
repeatMode: false
},

initialize: function (map, options) {
this._endLabelText = L.drawLocal.draw.handlers.simpleshape.tooltip.end;

L.Draw.Feature.prototype.initialize.call(this, map, options);
},

Expand Down Expand Up @@ -759,7 +726,7 @@ L.Draw.SimpleShape = L.Draw.Feature.extend({

this._tooltip.updatePosition(latlng);
if (this._isDrawing) {
this._tooltip.updateContent({ text: L.drawLocal.draw.handlers.simpleshape.tooltip.end });
this._tooltip.updateContent({ text: this._endLabelText });
this._drawShape(latlng);
}
},
Expand Down Expand Up @@ -798,9 +765,10 @@ L.Draw.Rectangle = L.Draw.SimpleShape.extend({
// Save the type so super can fire, need to do this as cannot do this.TYPE :(
this.type = L.Draw.Rectangle.TYPE;

this._initialLabelText = L.drawLocal.draw.handlers.rectangle.tooltip.start;

L.Draw.SimpleShape.prototype.initialize.call(this, map, options);
},
_initialLabelText: L.drawLocal.draw.handlers.rectangle.tooltip.start,

_drawShape: function (latlng) {
if (!this._shape) {
Expand Down Expand Up @@ -833,18 +801,19 @@ L.Draw.Circle = L.Draw.SimpleShape.extend({
fillColor: null, //same as color by default
fillOpacity: 0.2,
clickable: true
}
},
metric: true // Whether to use the metric meaurement system or imperial
},

initialize: function (map, options) {
// Save the type so super can fire, need to do this as cannot do this.TYPE :(
this.type = L.Draw.Circle.TYPE;

this._initialLabelText = L.drawLocal.draw.handlers.circle.tooltip.start;

L.Draw.SimpleShape.prototype.initialize.call(this, map, options);
},

_initialLabelText: L.drawLocal.draw.handlers.circle.tooltip.start,

_drawShape: function (latlng) {
if (!this._shape) {
this._shape = new L.Circle(this._startLatLng, this._startLatLng.distanceTo(latlng), this.options.shapeOptions);
Expand All @@ -861,6 +830,7 @@ L.Draw.Circle = L.Draw.SimpleShape.extend({

_onMouseMove: function (e) {
var latlng = e.latlng,
metric = this.options.metric,
radius;

this._tooltip.updatePosition(latlng);
Expand All @@ -871,8 +841,8 @@ L.Draw.Circle = L.Draw.SimpleShape.extend({
radius = this._shape.getRadius().toFixed(1);

this._tooltip.updateContent({
text: 'Release mouse to finish drawing.',
subtext: 'Radius: ' + radius + ' m'
text: this._endLabelText,
subtext: 'Radius: ' + L.GeometryUtil.readableDistance(radius, this.options.metric)
});
}
}
Expand Down Expand Up @@ -1589,11 +1559,7 @@ L.LatLngUtil = {
}
};

/*
* L.PolygonUtil contains different utility functions for Polygons.
*/

L.PolygonUtil = {
L.GeometryUtil = {
// Ported from the OpenLayers implementation. See https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Geometry/LinearRing.js#L270
geodesicArea: function (latLngs) {
var pointsCount = latLngs.length,
Expand All @@ -1612,6 +1578,53 @@ L.PolygonUtil = {
}

return Math.abs(area);
},

readableArea: function (area, isMetric) {
var areaStr;

if (isMetric) {
if (area >= 10000) {
areaStr = (area * 0.0001).toFixed(2) + ' ha';
} else {
areaStr = area.toFixed(2) + ' m&sup2;';
}
} else {
area *= 0.836127; // Square yards in 1 meter

if (area >= 3097600) { //3097600 square yards in 1 square mile
areaStr = (area / 3097600).toFixed(2) + ' mi&sup2;';
} else if (area >= 4840) {//48040 square yards in 1 acre
areaStr = (area / 4840).toFixed(2) + ' acres';
} else {
areaStr = Math.ceil(area) + ' yd&sup2;';
}
}

return areaStr;
},

readableDistance: function (distance, isMetric) {
var distanceStr;

if (isMetric) {
// show metres when distance is < 1km, then show km
if (distance > 1000) {
distanceStr = (distance / 1000).toFixed(2) + ' km';
} else {
distanceStr = Math.ceil(distance) + ' m';
}
} else {
distance *= 1.09361;

if (distance > 1760) {
distanceStr = (distance / 1760).toFixed(2) + ' miles';
} else {
distanceStr = Math.ceil(distance) + ' yd';
}
}

return distanceStr;
}
};

Expand Down
Loading

0 comments on commit 2f2905d

Please sign in to comment.