Skip to content
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

Merged
merged 13 commits into from
Jul 26, 2017
Merged

Annotation labels #719

merged 13 commits into from
Jul 26, 2017

Conversation

manthey
Copy link
Contributor

@manthey manthey commented Jul 17, 2017

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 have label, showLabel, labelStyle, and description properties. The annotation layer has a showLabels 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.

manthey added 10 commits July 6, 2017 15:17
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.
Copy link
Member

@aashish24 aashish24 left a 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');
Copy link
Member

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',
Copy link
Member

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?

Copy link
Contributor Author

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.

@manthey
Copy link
Contributor Author

manthey commented Jul 21, 2017

Do we want showLabels to default to true? If so, anything that currently uses annotations that switches to the new code will suddenly have labels, which could either be good or bad depending on what that program expects.

Add a pug linting test.
/* 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth wrapping the line?

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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).

@@ -1229,18 +1444,33 @@ lineRequiredFeatures[lineFeature.capabilities.basic] = [annotationState.create];
registerAnnotation('line', lineAnnotation, lineRequiredFeatures);

/**
* Point annotation class
* Point annotation classa.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classa? --> class?

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know, thanks

Copy link
Member

@aashish24 aashish24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@manthey manthey merged commit 6798308 into master Jul 26, 2017
@manthey manthey deleted the annotation-labels branch July 26, 2017 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants