-
Notifications
You must be signed in to change notification settings - Fork 75
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
Annotation labels #719
Annotation labels #719
Conversation
This adds a new feature type, `geo.textFeature`, where the data items have a position, text, and styling. Currently, this is only available for the canvas renderer, and not all styles are hooked through. Annotations now have `label`, `showLabel`, `labelStyle`, and `description` properties. The annotation layer has a `showLabels` option for toggling all labels. Update documentation of annotation.js and annotationLayer.js. This needs to process and pass through styles to the renderer. It needs to generate a synthetic font style if the font substyles are used. It needs to support rotation, scaling, and offset on text features. It needs tests. The annotation example should allow label adjustments, including determining where placement is based from. Placement basis needs to be an annotation option.
This handles font substyles, such as fontSize. This is exposed in the annotations example. This also handles textAlign, textBaseline, color, and textOpacity. Much of the infrastructure for other text styles is in place.
This adds a utility function to combine a color with an optional opacity and an opacity value into a single color with opacity value.
Better handle blanks in the annotations example. Show a show label option in the annotations example.
Remove the direction property -- it isn't supported by Firefox and only obscurely supported by Chrome.
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.
Looking very good @manthey now I am just going through the code and details.
@@ -0,0 +1,207 @@ | |||
var inherit = require('./inherit'); |
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.
the API is nice @manthey
* @private | ||
*/ | ||
var m_this = this, | ||
m_defaultFont = 'bold 16px sans-serif', |
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.
should we use font size 12? as default which I have seen is more common but perhaps 12 is too small?
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 picked bold 16px sans-serif
because I thought it was a good default for the annotations. Generally, I think a text feature will be used for labels not blocks of text, so a larger size is more likely to be appropriate. I could be persuaded otherwise.
Do we want |
Add a pug linting test.
src/canvas/textFeature.js
Outdated
/* If any of the font styles other than `font` have values, then we need to | ||
* construct a single font value from the subvalues. Otherwise, we can | ||
* skip it. */ | ||
fontFromSubValues = ['fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'lineHeight', 'fontFamily'].some(function (key) { |
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.
worth wrapping the line?
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.
Done.
@@ -4,7 +4,7 @@ | |||
position: absolute; | |||
left: 10px; | |||
top: 80px; | |||
z-index: 1; | |||
z-index: 1000; |
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 might know the answer..but any more insight on why this change might be useful.
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.
When layers are children of other layers, we set a z-index on them. When we have multiple layers, this conflicts with the z-index context of the controls. The easy solution is to move the controls to an arbitrary high z-index. It might be better to ensure that the map is a stacking context, which on some browsers would be adding css isolation: isolate
, but that doesn't work everywhere and other methods of creating a stacking context involve altering css properties on the map div which might be undesirable in general (we could do so in the examples, though).
src/annotation.js
Outdated
@@ -1229,18 +1444,33 @@ lineRequiredFeatures[lineFeature.capabilities.basic] = [annotationState.create]; | |||
registerAnnotation('line', lineAnnotation, lineRequiredFeatures); | |||
|
|||
/** | |||
* Point annotation class | |||
* Point annotation classa. |
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.
classa? --> class?
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.
Dumb typo.
* is treated as a double-click when working with annotations. | ||
* @param {number} [options.adjacentPointProximity=5] The minimum distance in | ||
* @param {object} [args] Layer options. | ||
* @param {number} [args.dblClickTime=300] The delay in milliseconds that is |
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 am wondering if 300ms is longer than usual but this is not something for this PR
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.
iOS uses 300 ms, Windows uses 500 ms.
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.
good to know, thanks
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.
👍
Switch from jade to pug.
Support annotation labels.
This adds a new feature type,
geo.textFeature
, where the data items have a position, text, and styling. Currently this is only available for the canvas renderer. Annotations now havelabel
,showLabel
,labelStyle
, anddescription
properties. The annotation layer has ashowLabels
option for toggling all labels. This supports rotation, scaling, offset, shadows, and strokes on text features.The annotation example exposes all of these options.
Documentation and tests are fully updated.