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

Marker centering cannot adapt to changing marker sizes #5133

Closed
peterqliu opened this issue Aug 10, 2017 · 2 comments
Closed

Marker centering cannot adapt to changing marker sizes #5133

peterqliu opened this issue Aug 10, 2017 · 2 comments
Labels

Comments

@peterqliu
Copy link
Contributor

peterqliu commented Aug 10, 2017

We currently center the marker DOM element on its pivot, by assessing its height and width and incorporating them into the CSS transform translations (I think it's this snippet of code).

This is great if the marker stays static, but if its size changes at all after instantiation (from content changes, hover interactions, etc), the element is still translated based on its original size, causing the element to go off-center from its pivot.

The solution I'm currently using (and am proposing for the Marker class) is to separate the translation and centering duties, by introducing a child element to tackle the latter. The proposed boilerplate looks like this:

<div class='marker mapboxgl-marker'>
  <div class='marker-centerer'>
    //user's marker content would go here
  </div>
</div>

If we style .marker-centerer with transform:translateX(-50%) translateY(-50%), it will automatically translate itself by a percentage of its own size, thereby making it adaptable to all future size changes.

@jfirebaugh
Copy link
Contributor

I don't think we even need to add any wrappers. Just replacing the calculated 50% offset with transform: translate(-50%, -50%) should work; that's basically what Popup does.

@peterqliu
Copy link
Contributor Author

peterqliu commented Aug 13, 2017

edit: figured it out

@jfirebaugh to my knowledge, CSS transforms don't accept compound transforms of the same type, hence the wrapping. A quick experiment with the dev console seems to confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants