-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add vertical-align
in format expression
#900
base: main
Are you sure you want to change the base?
Add vertical-align
in format expression
#900
Conversation
…-spec into issue-832-format-expression-vertical-align
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #900 +/- ##
==========================================
+ Coverage 92.78% 92.80% +0.01%
==========================================
Files 107 107
Lines 4739 4752 +13
Branches 1346 1352 +6
==========================================
+ Hits 4397 4410 +13
Misses 342 342 ☔ View full report in Codecov by Sentry. |
…-spec into issue-832-format-expression-vertical-align
I would like to cover questions from the meeting on Nov 13th: Using HTMLI did check, and it is possible to use HTML to display vertically aligned labels. This approach works for MapLibre GL JS, however it does not cover multiple platforms. There are more advantages of using format expression over custom HTML layer:
Format expression already gives possibility to create rich labels on the map, easily, without having to implement own custom solution. Having the possibility to align elements vertically in my opinion is good supplement to format expression. In some cases necessary to make full benefit from it. Sample use caseOur team created a sample mock how the labels look like with and without vertical alignment. |
Thanks for taking the time to work through these pieces @stanislawpuda-tomtom! In my opinion, those advantages are sufficient to merit including in the spec—especially for collision detection and performance reasons. |
I have changed |
Are you sure about the places where you added the code? |
@HarelM @lseelenbinder |
@@ -69,10 +70,21 @@ export class FormatExpression implements Expression { | |||
if (!textColor) return null; | |||
} | |||
|
|||
let verticalAlign = null; | |||
if (arg['vertical-align']) { | |||
if (typeof arg['vertical-align'] === 'string' && !VERTICAL_ALIGN_OPTIONS.includes(arg['vertical-align'] as VerticalAlign)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this if be moved to the parse code to keep this as clean as the other if statements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try to move it to parse - however then it shouldn't be placed in parse fn itself, but I found that it is better to add enum
validation, like for array in other places.
However, to make it possible there are multiple changes that has to be made. Moreover the validation for enum is a bit different, because other validations are based on types, and enum validation requires access to the value, so it is possible to compare with enum values.
You can see how it looks here: tomtom-forks#2
After making this try I actually think that having it in format.ts
, as it is now, is better and much simpler. Also in similar fashion the validation is implemented for interpolate
expression (link to the file).
null, | ||
null, | ||
null, | ||
section.verticalAlign ? section.verticalAlign.evaluate(ctx) : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different than other properties? Why not passing null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the instantiation of FormattedSection
for image. All other properties are null, because they only applies to text (font
etc.), but vertical-align
can be applied to both image and text section.
@@ -1,19 +1,24 @@ | |||
import type {Color} from '../../expression/types/color'; | |||
import type {ResolvedImage} from '../types/resolved_image'; | |||
|
|||
export const VERTICAL_ALIGN_OPTIONS = ['bottom', 'center', 'top'] as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be defined in the v8 spec file and not here?
"example": { | ||
"syntax": { | ||
"method": ["value", "{ \"text-font\": string, \"text-color\": color, \"font-scale\": number }", "..."], | ||
"method": ["value", "{ \"text-font\": string, \"text-color\": color, \"font-scale\": number, \"vertical-align\": string }", "..."], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put enum possible values instead of string? Not sure how the handled in different places...
I've added details on my concerns regarding the current code. Let me know if this is clearer now. |
@HarelM It is clear - I'll cover them. Thank you! |
Related issue #832.
This PR introduces vertical align property to format expression. It enables to specify how each section should be positioned in relation to biggest element in line. There are three possible options:
Launch Checklist
CHANGELOG.md
under the## main
section.