From 9f1b928f89bc35122fae7ee0b9b24f9c2e725936 Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Tue, 2 Jan 2018 10:45:44 -0300 Subject: [PATCH] add number of nodes information to measurement panel --- data/core.yaml | 1 + dist/locales/en.json | 3 ++- modules/ui/panels/measurement.js | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 9999cdc983..d087073a19 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -318,6 +318,7 @@ en: location: Location metric: Metric imperial: Imperial + node_count: Number of nodes geometry: point: point vertex: vertex diff --git a/dist/locales/en.json b/dist/locales/en.json index 283774bf32..ace6c355a3 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -397,7 +397,8 @@ "centroid": "Centroid", "location": "Location", "metric": "Metric", - "imperial": "Imperial" + "imperial": "Imperial", + "node_count": "Number of nodes" } }, "geometry": { diff --git a/modules/ui/panels/measurement.js b/modules/ui/panels/measurement.js index 7de2a601d6..48a6546bd7 100644 --- a/modules/ui/panels/measurement.js +++ b/modules/ui/panels/measurement.js @@ -42,6 +42,14 @@ export function uiPanelMeasurement(context) { return result; } + function nodeCount(feature) { + if (feature.type === 'LineString') return feature.coordinates.length; + + if (feature.type === 'Polygon') { + return feature.coordinates[0].length - 1; + } + } + function displayLength(m) { var d = m * (isImperial ? 3.28084 : 1), @@ -170,6 +178,15 @@ export function uiPanelMeasurement(context) { (closed ? t('info_panels.measurement.closed') + ' ' : '') + t('geometry.' + geometry) ); + if (entity.type !== 'relation') { + list + .append('li') + .text(t('info_panels.measurement.node_count') + ':') + .append('span') + .text(nodeCount(feature) + ); + } + if (closed) { var area = steradiansToSqmeters(entity.area(resolver)); list @@ -179,6 +196,7 @@ export function uiPanelMeasurement(context) { .text(displayArea(area)); } + list .append('li') .text(lengthLabel + ':') @@ -193,7 +211,6 @@ export function uiPanelMeasurement(context) { centroid[1].toFixed(OSM_PRECISION) + ', ' + centroid[0].toFixed(OSM_PRECISION) ); - var toggle = isImperial ? 'imperial' : 'metric'; selection