make sure popup container is an even number of pixels wide#3258
make sure popup container is an even number of pixels wide#3258mollymerp wants to merge 1 commit into
Conversation
|
Did you ever come to an understanding of the root cause of this bug? An adjustment to the translation is preferable to an adjustment to the width. There are legitimate use cases for odd # widths. I could see a developer being confused that the width they set on their popup was overwritten by GL JS whenever the map moves. |
|
Changing the translation unfortunately doesn't make the blurriness go away. I think the bug has something to do with this. |
|
The reason to use The effect of this change is to fix the width at a particular point in time. It's probably slightly better than using Looking around the web for other solutions to the blurriness issue, it seems that there's a vague consensus that a) this is browser-specific and a browser bug when it occurs and b) there's not really any good workaround. |
|
Based on discussion with the rest of the maintainers, we've determined this is a bug in certain browsers and we should not fix the width of the popups in the gl-js codebase, so I'll close this PR. If this issue is affecting you, you can fix the blurriness by setting your popup's width to a fixed, even number of pixels. |
|
Just for reference I think this is the Chrome bug https://bugs.chromium.org/p/chromium/issues/detail?id=521364 |
|
Sorry for a super late comment on this one but it's the best place I could find. I understand why this was closed and why you've chosen to not implement a fix...however, for those us us with many, dynamic sized (or content variant) popups...this issue is a pretty tough one to work around. Setting a fixed, even pixel width means the popups can't size themselves to fit their content. We've found by setting And seeing as the practical upshot of this is a +/-1px variance on any width you set on it...I for one would really like to see this fix implemented. |
|
@mikeomeara1 I can't believe we had to do this but here is how we worked around it: new mapboxgl.Popup({offset: 15})
.on('open', function (pop) {
var _container = pop.target._container;
if(_container.offsetWidth % 2 !== 0){
_container.style.width = (_container.offsetWidth + 1) + "px";
}
});Hope it helps |
|
@LTC-fperrin That's fantastic. Agreed though, it's kind of crazy that this is necessary...but in any case, that puts us into a much better spot than we were. Thanks so much for sharing. |
|
@mollymerp @mikeomeara1 I just realised that's exactly what this PR is about. It should be /reopened /merged ! |
|
This is the workaround I'm using with Vue (the popup is a Vue component) mounted () {
// odd width popups are blurry on Chrome, this enforces even widths
if (Math.ceil(this.$el.clientWidth) % 2) {
this.$el.style.width = (Math.ceil(this.$el.clientWidth) + 1) + 'px'
}
} |
Removing Don't apply will-change to too many elements. The browser already tries as hard as it can to optimize everything... Looks like adding this property to pop-up (could be a lot of them) not a good idea. |


Popups with a width of an odd number of pixels appear blurry on non-retina screens. This PR ensures that the containers are an even number of pixels. At first I thought this might be related to odd-pixel transforms in placing the popup element, but ensuring even dimensions did not fix the blurriness problem.
Right now I have this code in
popup.js, but I can definitely move to a separateutil/dom.jsfunction.Here's a gif that demonstrates the behavior
ref #3249
Launch Checklist