Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions dist/leaflet.draw-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({
clickable: true
},
metric: true, // Whether to use the metric meaurement system or imperial
nautical: false, //Whether to use nautical miles
showLength: true, // Whether to display distance in the tooltip
zIndexOffset: 2000 // This should be > than the highest z-index any map layers
},
Expand Down Expand Up @@ -565,7 +566,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({
// calculate the distance from the last fixed point to the mouse position
distance = this._measurementRunningTotal + currentLatLng.distanceTo(previousLatLng);

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

_showErrorTooltip: function () {
Expand Down Expand Up @@ -1809,28 +1810,29 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, {
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;
}
readableDistance: function (distance, isMetric, isNmi) {
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 if (isNmi) {
distance *= 0.00053996; // nautical miles in 1 meter
distanceStr = (distance).toFixed(2) + ' nmi';
} else {
distance *= 1.09361;
if (distance > 1760) {
distanceStr = (distance / 1760).toFixed(2) + ' miles';
} else {
distanceStr = Math.ceil(distance) + ' yd';
}
}

return distanceStr;
}
});

L.Util.extend(L.LineUtil, {
Expand Down
4 changes: 2 additions & 2 deletions dist/leaflet.draw.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/draw/handler/Draw.Polyline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({
clickable: true
},
metric: true, // Whether to use the metric meaurement system or imperial
nautical: false, //Whether to use nautical miles
showLength: true, // Whether to display distance in the tooltip
zIndexOffset: 2000 // This should be > than the highest z-index any map layers
},
Expand Down Expand Up @@ -378,7 +379,7 @@ L.Draw.Polyline = L.Draw.Feature.extend({
// calculate the distance from the last fixed point to the mouse position
distance = this._measurementRunningTotal + currentLatLng.distanceTo(previousLatLng);

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

_showErrorTooltip: function () {
Expand Down
43 changes: 22 additions & 21 deletions src/ext/GeometryUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,27 @@ L.GeometryUtil = L.extend(L.GeometryUtil || {}, {
return areaStr;
},

readableDistance: function (distance, isMetric) {
var distanceStr;
readableDistance: function (distance, isMetric, isNmi) {
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 if (isNmi) {
distance *= 0.00053996; // nautical miles in 1 meter
distanceStr = (distance).toFixed(2) + ' nmi';
} else {
distance *= 1.09361;
if (distance > 1760) {
distanceStr = (distance / 1760).toFixed(2) + ' miles';
} else {
distanceStr = Math.ceil(distance) + ' yd';
}
}

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;
}
return distanceStr;
}
});