show line and polygon measurements while drawing / editing
This commit is contained in:
parent
60fb67516d
commit
ee6724cddb
2 changed files with 34 additions and 13 deletions
|
@ -1250,21 +1250,34 @@ L.U.Editable = L.Editable.extend({
|
||||||
|
|
||||||
drawingTooltip: function (e) {
|
drawingTooltip: function (e) {
|
||||||
var content;
|
var content;
|
||||||
var readableDistance;
|
|
||||||
if (e.layer instanceof L.Marker) content = L._('Click to add a marker');
|
if (e.layer instanceof L.Marker) content = L._('Click to add a marker');
|
||||||
else if (e.layer instanceof L.Polyline) {
|
else if (e.layer instanceof L.Polyline) {
|
||||||
if (!e.layer.editor._drawnLatLngs.length) {
|
// when drawing a Polyline or Polygon
|
||||||
if (e.layer instanceof L.Polygon){
|
if (e.layer.editor._drawnLatLngs) {
|
||||||
content = L._('Click to start drawing a polygon');
|
// when drawing first point
|
||||||
} else if (e.layer instanceof L.Polyline) {
|
if (!e.layer.editor._drawnLatLngs.length) {
|
||||||
content = L._('Click to start drawing a line');
|
if (e.layer instanceof L.Polygon){
|
||||||
|
content = L._('Click to start drawing a polygon');
|
||||||
|
} else if (e.layer instanceof L.Polyline) {
|
||||||
|
content = L._('Click to start drawing a line');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var readableDistance = e.layer.getMeasure(e.latlng);
|
||||||
|
if (e.layer.editor._drawnLatLngs.length < e.layer.editor.MIN_VERTEX) {
|
||||||
|
// when drawing second point
|
||||||
|
content = L._('Click to continue drawing ({distance})', { distance: readableDistance });
|
||||||
|
} else {
|
||||||
|
// when drawing third point (or more)
|
||||||
|
content = L._('Click last point to finish shape ({distance})', { distance: readableDistance });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var tempLatLngs = e.layer.editor._drawnLatLngs.slice();
|
// when moving an existing point
|
||||||
tempLatLngs.push(e.latlng);
|
if (e.layer instanceof L.Polygon){
|
||||||
var length = L.GeoUtil.lineLength(this.map, tempLatLngs);
|
content = L._('Polygon area: {area}', { area: e.layer.getMeasure() });
|
||||||
readableDistance = L.GeoUtil.readableDistance(length, this.map.measureTools.getMeasureUnit());
|
} else if (e.layer instanceof L.Polyline) {
|
||||||
content = L._('Click last point to finish shape ({distance})', {distance: readableDistance});
|
content = L._('Line distance: {distance}', { distance: e.layer.getMeasure() });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (content) {
|
if (content) {
|
||||||
|
|
|
@ -853,8 +853,16 @@ L.U.Polyline = L.Polyline.extend({
|
||||||
return 'polyline';
|
return 'polyline';
|
||||||
},
|
},
|
||||||
|
|
||||||
getMeasure: function () {
|
getMeasure: function (extraPoint) {
|
||||||
var length = L.GeoUtil.lineLength(this.map, this._defaultShape());
|
var polyline;
|
||||||
|
if (extraPoint){
|
||||||
|
var tmpLatLngs = this.editor._drawnLatLngs.slice();
|
||||||
|
tmpLatLngs.push(extraPoint);
|
||||||
|
polyline = tmpLatLngs;
|
||||||
|
} else {
|
||||||
|
polyline = this._defaultShape();
|
||||||
|
}
|
||||||
|
var length = L.GeoUtil.lineLength(this.map, polyline);
|
||||||
return L.GeoUtil.readableDistance(length, this.map.measureTools.getMeasureUnit());
|
return L.GeoUtil.readableDistance(length, this.map.measureTools.getMeasureUnit());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue