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

Use none to avoid hit detection of text fills #14992

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

tschaub
Copy link
Member

@tschaub tschaub commented Aug 11, 2023

Following up on #14943 (comment), this changes syntax for avoiding hit detection on text fills when using the flat literal syntax.

We're adding support for expressions in styles in #14780. Currently, the types supported by expressions do not include null or undefined. We may need to add support for this, but I'm going to avoid it until there is a compelling case.

Instead of 'text-fill-color': null, this change makes it so 'text-fill-color': 'none' will results in a text where the fill is not hit detected.

@@ -4,7 +4,7 @@

#### Hit detection with Text fill

Hit detection of fill for Text styles is now consistent with that for Circle and RegularShape styles. Transparent `fill` and `backgroundFill` is detected, with no hit detection over unfilled shapes. To get the previous behavior in Text styles where a transparent fill may have been used to avoid the default fill specify `fill: null`. If using FlatStyle notation specify `'text-fill-color': null`.
Hit detection of fill for Text styles is now consistent with that for Circle and RegularShape styles. Transparent `fill` and `backgroundFill` is detected, with no hit detection over unfilled shapes. To get the previous behavior in Text styles where a transparent fill may have been used to avoid the default fill specify `fill: null`. If using FlatStyle notation specify `'text-fill-color': 'none'`.
Copy link
Member Author

@tschaub tschaub Aug 11, 2023

Choose a reason for hiding this comment

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

These upgrade notes are not clear to me. Would it be true to say the following?


Previously, text labels with transparent fills were not hit detected. Now, you can control whether a transparent fill in a text label is hit detected or not.

To create a text style with a transparent fill that will be hit detected, use a fill with 'transparent' as the color.

// transparent fill, will be hit detected
const style = Style({
  text: new Text({
    fill: new Fill({
      color: 'transparent',
    }),
    stroke: new Stroke({
      color: 'red',
      width: 2,
    }),
  }),
});

Or, if using the flat literal style syntax:

// transparent fill, will be hit detected
const style = {
  'text-fill-color': 'transparent',
  'text-stroke-color': 'red',
  'text-stroke-width': 2,
}

By contrast, if you want a transparent fill that will not be hit detected, do the following:

// no fill, will not be hit detected
const style = Style({
  text: new Text({
    fill: null,
    stroke: new Stroke({
      color: 'red',
      width: 2,
    }),
  }),
});

Or, if using the flat literal style syntax:

// no fill, will not be hit detected
const style = {
  'text-fill-color': 'none',
  'text-stroke-color': 'red',
  'text-stroke-width': 2,
}

Copy link
Member

Choose a reason for hiding this comment

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

Yes, having this in the upgrade notes instead of what's currently there would make it much clearer.

@github-actions
Copy link

📦 Preview the website for this branch here: https://deploy-preview-14992--ol-site.netlify.app/.

Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

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

Thanks, @tschaub! Your suggestion for new wording in the release notes is very good. Please change.

@tschaub tschaub merged commit cbb1086 into openlayers:main Aug 11, 2023
@tschaub tschaub deleted the fill-none branch August 11, 2023 15:50
Hit detection of fill for Text styles is now consistent with that for Circle and RegularShape styles. Transparent `fill` and `backgroundFill` is detected, with no hit detection over unfilled shapes. To get the previous behavior in Text styles where a transparent fill may have been used to avoid the default fill specify `fill: null`. If using FlatStyle notation specify `'text-fill-color': null`.
Previously, text labels with transparent fills were not hit detected. Now, you can control whether a transparent fill in a text label is hit detected or not.

To create a text style with a transparent fill that will be hit detected, simply exclude the `fill` or use a fill with `'transparent'` as the color.
Copy link
Contributor

@mike-000 mike-000 Aug 11, 2023

Choose a reason for hiding this comment

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

excluding the fill will default to #333, not transparent

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.

3 participants