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

Create a hover effect for labels #5299

Closed
Roxyi opened this issue Sep 14, 2017 · 6 comments
Closed

Create a hover effect for labels #5299

Roxyi opened this issue Sep 14, 2017 · 6 comments

Comments

@Roxyi
Copy link

Roxyi commented Sep 14, 2017

Hi, I am trying to create a hover effect for labels. My idea is that we can create two layers using the same label data and add them to the map. One layer will be the labels displayed on the map and the other one will be the hover effect layer. When hovering over a label, we can get the properties of that label and use properties like "id" or "name" to filter the hover effect layer.
Here is what I have got so far: hover effect test

There are three problems:

  1. The hover effect does not always work.
  2. The respond of the hover effect is slow in low zoom levels. It is faster when you zoom in.
  3. The hover effect will be easily gone because I used "mouseenter" and "mouseleave" on the label layer. You may notice that if you move your mouse to the space between letters, the hover effect will be gone. Only when you move your mouse exactly on the letters, you will see the hover effect.

I wonder if there is a better way to create a hover effect for labels. Also, is there any way to create polygons like the collision boxes for the text labels.

Any help will be appreciated.

@jfirebaugh
Copy link
Contributor

That's probably the best way for now. See #200 for a request for a built-in feature for this.

@Roxyi
Copy link
Author

Roxyi commented Sep 14, 2017

@jfirebaugh Thank you! The pseudo-class is already a built-in feature but not released to the public now? Where can I send a request for that built-in feature?

@anandthakker
Copy link
Contributor

@Roxyi It's not (yet) a built-in feature -- issue #200 is the request to add it; that would be the place to watch for further discussion/progress.

@ryanbaumann
Copy link
Contributor

Using a debounce function with layer filters can help a bit for your hover use case in the meantime @roti https://bl.ocks.org/ryanbaumann/0d72890cea4f97e0dbd10ea3cf7189b2

@Roxyi
Copy link
Author

Roxyi commented Sep 15, 2017

@anandthakker Thank you! Got it.

@Roxyi
Copy link
Author

Roxyi commented Sep 15, 2017

@ryanbaumann That's amazing. The debounce function helps improve the performance a lot. Thank you!

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

No branches or pull requests

4 participants