-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Added support for multiline labels using explicit newline character. #4306
Added support for multiline labels using explicit newline character. #4306
Conversation
Thanks @dwhipps! It looks like you have a jsHint error |
Hannah, I can't see the error on my end when running 'npm release' or 'npm tests-non-webgl' Can you point me to the file/line? The "details" link in providing the Travis CI build log isn't very helpful. |
// Subtract maxGlyphHeight for backwards compatibility | ||
heightOffset += (totalHeight * scale) - maxGlyphHeight; | ||
} | ||
else if (verticalOrigin === VerticalOrigin.TOP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dwhipps this is causing the jsHint error, because this block is empty. You can just remove it.
You can run jsHint with npm run jsHint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, update the formatting in the block above this while you're in there. It should be
} else if () {
I managed to fix the error. Not sure what the "bug bash" tag means. Do I have anything else to do? |
Thanks @dwhipps, we're a little busy around here this week so I'm not sure if we'll have a chance to review this right away. I looked through and the code looks fine to me, but one of the graphics guys with a better understanding of the changes here will do a more thorough review to get this merged. |
I know this code pretty well and this is a long overdue, mostly straightforward, change. I'll try and get it merged by the end of the week. As for the |
I've discovered problems with this and have not yet been able to resolve them. It would recommend NOT pulling this until I've figured out what's going on. |
Thanks for the heads up @dwhipps I had a few edge cases I wanted to be sure to check myself as well, so glad you're on the ball! Getting good font measurements in the browser is way harder than it should be (especially getting the same results cross-browser) |
Red Herring. The new multiline labels code was not causing the issues I'm seeing (I'll report those separately.) As far as I can tell, it works pretty well. |
@mramato I'm a little late to the party here, but I'm curious why measuring text has to be so hard. Can't we just ask the browser to do it? Here's how I did it recently in a similar situation: In short: Create a One thing to keep in mind is that the measurement will be affected by the inherited CSS wherever you add the element, but you can deal with that pretty easily just by adding a Worked well for my use-case (word wrapping in an SVG), anyway. |
@dwhipps is this ready to be reviewed or were there still some things you wanted to change? |
Yeah, this is ready to go. |
It's been a while and I would need to look into it, but we also need to account for letter placement, i.e. letters that go below the baseline, like lowercase y. It's not just simple width/height we need to worry about. |
I don't think this should be an issue. The size of the Change that o to a y or an R and notice that the height of the span doesn't change. If you need to know the exact baseline position within that span for some reason, I don't know how to do that offhand, though I bet it can be done. But I can't really think of why you'd need to know that. |
I think the main issue with your approach is the wasted space above the y. I'm less concerned about the memory/texture usage and more concerned with how that affects origin/offset positioning (though I admit it may not matter). @shunter was actually the original author for most of the current label code, so hopefully he can chime in with some thoughts. I'm fine with trying to approach you are suggesting, especially if it simplifies the code. |
@dwhipps Check out the below code snippet and screenshot, I would expect the point to be dead center. It is in master (but without the new lines obviously). We need to make sure all of the various origin combinations work as expected. var viewer = new Cesium.Viewer('cesiumContainer');
viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
point:{
color: Cesium.Color.BLUE,
pixelSize:15,
verticalOrigin : Cesium.VerticalOrigin.CENTER,
horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
},
label : {
text : 'aa aa\naa aa\naa aa\naa aa',
verticalOrigin : Cesium.VerticalOrigin.CENTER,
horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
}
}); |
Keeping up to date with master
Hmm. Well, now I've merge in master (just to keep things up to date) and the "Point" has disappeared. Can you confirm? |
Starying up to date... again.
Looks like the "Point" is not drawing on the latest Chrome or Safari on Sierra, but it is working on FireFox... |
I just checked out your branch @dwhipps and the point it still drawing for me in Chrome |
@dwhipps you have a jsHint error: Source/Scene/LabelCollection.js |
|
@mramato @dwhipps The I want to take a shot at creating a |
@emackey Good Luck! Let me know if you need anything. I'm around most of the day tomorrow. |
Thanks @emackey, sounds like you have it under control! |
…kgrounds Conflicts: Source/Scene/LabelCollection.js
Nice, GitHub allowed me to push to your branch since this PR is open. @dwhipps take a look at what changed here, and also try setting One intentional change I made is that @mramato I think this is ready. Code I added should be reviewed. Thanks. |
Updated doc & a demo. This is ready. |
var maxY = 0; | ||
var lastLineWidth = 0; | ||
var maxLineWidth = 0; | ||
var lineWidths = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a scratch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My hope is we don't need a scratch in this case. This function only gets called when the glyphs all need to be repositioned, which is an expensive operation we try to avoid (using the delay tactics you pointed out in the label background PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
if (glyphIndex < glyphLength - 1) { | ||
var nextGlyph = glyphs[glyphIndex + 1]; | ||
glyphPixelOffset.x += ((dimensions.width - dimensions.bounds.minx) + nextGlyph.dimensions.bounds.minx) * scale * resolutionScale; | ||
if (defined(backgroundBillboard) && (text.split('\n').join('').length > 0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more memory efficient way to do this?
text.split('\n').join('').length > 0
If so, does it matter here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too is part of repositionAllGlyphs
and typically happens only when there is some substantial change made to the label.
Tests and Sandcastle look good. Is coverage for the new code solid? Just those trivial questions. I'd like to get this into master soon for some use before the 1.29 release. Does anyone else want to look at this? |
Ah, I see this was already merged; I had the window open from earlier today. 👍 |
does it able to have richtext? |
Hi @arafat5549, |
I've added support for multiline text in Labels using explicit newline characters, per this issue:
#2402
I revived and (very slightly) improved the code written by @Andre-Nunes in this pull request:
#2575
I've tested and ensured that single-line labels have the same positioning (i.e. this maintains backwards compatibility)