-
Notifications
You must be signed in to change notification settings - Fork 22
Option for unit preference #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,7 @@ export default { | |
| showScaleLine: false, | ||
| showExampleAnnotations: true, | ||
| draftAnnotationUsesLabelColor: true, | ||
| preferredUnit: 'auto', | ||
| imagesArea: null, | ||
| openTab: null, | ||
| userUpdatedVolareResolution: false, | ||
|
|
@@ -593,6 +594,9 @@ export default { | |
| case 'draftAnnotationUsesLabelColor': | ||
| this.draftAnnotationUsesLabelColor = value; | ||
| break; | ||
| case 'preferredUnit': | ||
| this.preferredUnit = value; | ||
| break; | ||
|
Comment on lines
89
to
+599
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is never used. The components read the value directly from the settings instead. Either pass this as a prop (or use prop drilling) or remove it here and keep using Settings directly. |
||
| } | ||
| }, | ||
| handleAnnotationModeChange(mode, data) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ import MeasureComponent from '../mixins/measureComponent.vue'; | |
| import Polygon from '@biigle/ol/geom/Polygon'; | ||
| import Circle from '@biigle/ol/geom/Circle'; | ||
| import LineString from '@biigle/ol/geom/LineString'; | ||
| import { UnitNames, UnitMultipliers } from '../utils'; | ||
| import Settings from '../stores/settings'; | ||
|
|
||
| /** | ||
| * Tooltip showing length/area of the hovered annotations. | ||
|
|
@@ -28,10 +30,13 @@ export default { | |
| }, | ||
| computed: { | ||
| areaUnitMultipliers() { | ||
| return this.unitMultipliers.map(function (multiplier) { | ||
| return UnitMultipliers.map(function (multiplier) { | ||
| return Math.pow(multiplier, 2); | ||
| }); | ||
| }, | ||
| preferredUnit() { | ||
| return Settings.get('preferredUnit'); | ||
|
yannik131 marked this conversation as resolved.
|
||
| } | ||
| }, | ||
| methods: { | ||
| updateGeometries(features) { | ||
|
|
@@ -68,7 +73,7 @@ export default { | |
| if (this.hasArea) { | ||
| area *= Math.pow(this.pxWidthInMeter, 2); | ||
| let index = this.unitNearest(area, this.areaUnitMultipliers, 1e-3); | ||
| unit = this.unitNames[index] + '²'; | ||
| unit = UnitNames[index] + '²'; | ||
| area = area / this.areaUnitMultipliers[index]; | ||
| } | ||
|
|
||
|
|
@@ -79,22 +84,27 @@ export default { | |
|
|
||
| if (this.hasArea) { | ||
| length = length * this.pxWidthInMeter; | ||
| let index = this.unitNearest(length, this.unitMultipliers); | ||
| unit = this.unitNames[index]; | ||
| length = length / this.unitMultipliers[index]; | ||
| let index = this.unitNearest(length, UnitMultipliers); | ||
| unit = UnitNames[index]; | ||
| length = length / UnitMultipliers[index]; | ||
| } | ||
|
|
||
| return this.formatMeasurement(length, unit); | ||
| return this.formatMeasurement(length, unit, 1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should change the number of decimals to 3 too? What do you think? |
||
| }, | ||
| formatMeasurement(measurement, unit, decimals) { | ||
| decimals = Math.pow(10, decimals || 1); | ||
| return (Math.round(measurement * decimals) / decimals) + ' ' + unit; | ||
| return new Intl.NumberFormat("en-US", { | ||
| maximumSignificantDigits: decimals | ||
| }).format(measurement) + ' ' + unit; | ||
| }, | ||
| unitNearest(measurement, multipliers, min) { | ||
| if (measurement === 0) { | ||
| return multipliers.length - 1; | ||
| } | ||
|
|
||
| if (UnitNames.indexOf(this.preferredUnit) !== -1) { | ||
| return UnitNames.indexOf(this.preferredUnit); | ||
| } | ||
|
Comment on lines
100
to
+106
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is a preferred unit it should be used even if the measurement is 0. |
||
|
|
||
| min = min || 1; | ||
| let tmpMeasurement; | ||
| let i; | ||
|
|
@@ -115,6 +125,11 @@ export default { | |
| this.updateGeometries(features); | ||
| } | ||
| }, | ||
| preferredUnit() { | ||
| if (this.show) { | ||
| this.updateGeometries(this.features); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| </script> | ||
Uh oh!
There was an error while loading. Please reload this page.