Problem with width of text label
See original GitHub issueI’m using OpenLayers v6.1.1 and for some reason, from time to time, after a few refreshes of the page, the background of the text label gets the wrong height. It should look like this: but finally, it will become: which is wrong.
Here is a piece of code I’m using to generate this style:
style = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: icon
}),
});
if (SOME_CONDITION) {
style.setText(new ol.style.Text({
font: 'bold 11px Arial, Helvetica, sans-serif',
fill : new ol.style.Fill({
color : 'white',
}),
backgroundFill: new ol.style.Fill({
color : highlighted ? 'rgba(250, 44, 47, 0.8)' : 'rgba(119, 118, 115, 0.8)'
}),
padding: [2, 2, 2, 2],
text: name,
offsetY: -5
}));
}
layer = new ol.layer.Vector({
source: my_source
style: getFeatureStyle() //above code is used insode of this function to set the style for all features on this layer
});
Is this a bug or I’m doing something wrong?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:16 (6 by maintainers)
Top Results From Across the Web
css label width not taking effect - Stack Overflow
I believe labels are inline, and so they don't take a width. ... label { padding-left:26px; width:125px; text-transform: uppercase; ...
Read more >Text length exceeding a label's width causing the data not to ...
The problem is that the text isn't displayed if it cannot fit into actual XRLabel bounds (both vertically and horizontally), and the XRLabel....
Read more >C38: Using CSS width, max-width and flexbox to fit labels and ...
Define the width and max-width property for labels and inputs so they enlarge or shrink in the available space and respond to zoom...
Read more >Width is not applied when Label is used for the TextBox
The floating label element has a default width in the CSS, and the custom Width value from the TelerikTextBox Width parameter is not...
Read more >Size (Width and Height) of Label components do not update ...
I have a label (well, a FontAwesome "Ellipsis h", but it's really just a label) in my prototype. When I change the font...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dawidr I just updated the master build, so you can now get the latest from https://openlayers.org/en/master/build/ol.js (js) and https://openlayers.org/en/master/css/ol.css (css).
@dawidr Ok, so after some more headbanging against my desk I’ve noticed that if I remove my
display: flex
from thebody
element it fixes the problem (but breaks my site of-course). However if I put adiv
just below thebody
and give itflex
the problem is gone. It seem to have something to do with body having flex. I don’t understand why this would be a problem but oh well. I’ve reported it as a new issue #12213, though I don’t know if this issue is related to yours or not as you mentioned it only happening sometimes 🤔In my case I can’t just change the structure of the website whenever I feel like so I’ll try to figure out another way. If you’re interested this is basically what happened for me: https://jsfiddle.net/Doskii/29hxu4bd/