question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with width of text label

See original GitHub issue

I’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: image but finally, it will become: image 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ahocevarcommented, Jan 24, 2020

@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).

0reactions
Doskiicommented, Apr 14, 2021

@dawidr Ok, so after some more headbanging against my desk I’ve noticed that if I remove my display: flex from the body element it fixes the problem (but breaks my site of-course). However if I put a div just below the body and give it flex 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/

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found