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

Fix bug where yellow icon is shown when icon tag is empty #5819 #5821

Merged
merged 35 commits into from
Oct 23, 2017

Conversation

josh-bernstein
Copy link
Contributor

Fixes #5819

@cesium-concierge
Copy link

Welcome to the Cesium community @josh-bernstein!

Can you please send in a Contributor License Agreement (CLA) so that we can review and merge this pull request?

I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.

I am a bot who helps you make Cesium awesome! Thanks again.

@josh-bernstein
Copy link
Contributor Author

My machine's autoformatter made more changes than I meant to

@josh-bernstein josh-bernstein reopened this Sep 7, 2017
@josh-bernstein
Copy link
Contributor Author

I have updated CHANGES.md.

@hpinkos
Copy link
Contributor

hpinkos commented Sep 7, 2017

Thanks @josh-bernstein! Make sure you send over a CLA so we can review this. We'll probably also want to add a unit test for this particular case.

@tfili do you want to review?

@tfili
Copy link
Contributor

tfili commented Sep 12, 2017

Thanks @josh-bernstein. It looks good, but as Hannah mentioned we would want a unit test. It can probably just load a kml chunk and then verify that there isn't an image in the entity.

@josh-bernstein
Copy link
Contributor Author

@tfili Thanks for the response! Can you please tell me where the test file is located?

@biomassives
Copy link

biomassives commented Sep 12, 2017 via email

@tfili
Copy link
Contributor

tfili commented Sep 12, 2017

@josh-bernstein All tests are located in the Specs folder at the same location as in the Source folder. In this case Specs/DataSources/KmlDataSourceSpec.js

@josh-bernstein
Copy link
Contributor Author

@hpinkos @tfili I have added unit test. I am still waiting on my company to fill out the CLA.

@mramato
Copy link
Contributor

mramato commented Sep 27, 2017

@josh-bernstein thanks again for this PR. Is there any update on the CLA?

@josh-bernstein
Copy link
Contributor Author

@mramato My company says they should be sending it this week!

@mramato
Copy link
Contributor

mramato commented Sep 27, 2017

Awesome! Thanks.

@pjcozzi
Copy link
Contributor

pjcozzi commented Sep 28, 2017

We now have a CLA from @josh-bernstein, thanks!

@josh-bernstein can you please add yourself to CONTRIBUTORS.md under the corporate CLA section?

@@ -1111,10 +1111,6 @@ define([
entity.billboard = billboard;
}

if (!defined(billboard.image)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing this, it fixes your case, but breaks the case where there isn't an icon style at all. In that case Google Earth does show a yellow push pin.

Changing the if to something like

if (!defined(styleEntity.billboard) && !defined(billboard.image)) {

will only set the default image if an icon style wasn't defined, which I believe is the correct behavior in both cases.

expect(source.entities);
expect(source.entities.values.length).toEqual(1);
expect(source.entities._entities._array.length).toEqual(1);
expect(!source.entities._entities._array[0]._billboard._image);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to expect it to be something. This would probably be toBeUndefined().

Also add a test for the other case where no icon style is specified at all, to verify there is the default push pin.

@josh-bernstein
Copy link
Contributor Author

@tfili When I look at my code changes for CHANGES.md, it does not show anything removed. I did remove my change from the 1.38 version, maybe that's what you're seeing.

Also, my unit tests pass locally. I see that Travis is failing, but I'm not sure what is causing those errors.

@tfili
Copy link
Contributor

tfili commented Oct 17, 2017

@josh-bernstein Are you sure you are running all the tests? It fails for me locally and stepping into the code, I don't know how it would pass anywhere.
In the Styles: inline styles take precedance over shared styles test, what is happening is

  • The <IconStyle> gets processed with the href of http://test.invalid
  • Then the inline style gets processed. This doesn't have a href. The styles are merged and this is where you have a problem.
    • In master since image is undefined in the inline style, the billboard fallsback to the IconStyle.image and is set to http://test.invalid
    • In you branch since image is undefined, you set it to the pushpin and that's how it remains, so the test fails because it expects billboard.image to be http://test.invalid but instead it is a canvas element.
  • We need to push off figuring out what to use till processPositionGraphics once all the potential styles have been merged.
  • The cases we have are
    • CORRECT
      • Style has no IconStyle - Shows yellow pushpin
        • entity.billboard is undefined
      • Style has IconStyle with Icon - Uses the Icon
        • entity.billboard contains image
      • Style has IconStyle with empty Icon - Show nothing
        • entity.billboard is defined but with no image
    • INCORRECT
      • Style has IconStyle with no Icon - Shows nothing but should show yellow pushping
        • entity.billboard is defined but with no image

My suggestion would be in processBillboardIcon, that if you don't have a Icon or a color then you don't create a billboard at all. Then it would fallback to the yellow pushpin since entity.billboard would be undefined. This adds an additional case however, which would be no Icon but has a color. You would need to account and write a test for this additional case.


My mistake about CHANGES.md. I guess I was looking at an intermediate change. Looks fine in your branch.


You don't need to close the PR when you are working on it. It won't be merged till all the tests pass and comments are addressed anyway. Just comment again once it is ready.

@josh-bernstein
Copy link
Contributor Author

@tfili Thank you for comment. I believe I have addressed all the concerns you raised. I have once again made significant code changes to KmlDataSource.js, so please re-review code.

@josh-bernstein
Copy link
Contributor Author

josh-bernstein commented Oct 20, 2017

Actually I think I'm still failing this test

load works with a KMZ file

EDIT: I thought I saw an error once, but I have since been unable to reproduce.

EDIT: The error I saw once was I timeout error. It was with one of the kmz tests, but I am not positive which one. I have tried to run all tests twice since that and have not been able to reproduce

@josh-bernstein
Copy link
Contributor Author

@tfili I'm not sure why the Travis builds keep failing. When I look at the errors, none look related to my branch. Also, when I run the tests locally with master branch checked out, I get errors. So I do not believe that any of these errors are related to my branch. Therefore, I believe my branch is good to go.

Please let me know if you have thoughts.

@@ -729,6 +729,12 @@ define([

var iconNode = queryFirstNode(node, 'Icon', namespaces.kml);
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false, query);

// If icon tags are present but blank, we do not want to show an icon
if (defined(iconNode) && !defined(icon)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing the icon variable as a temporary with a different type, even though fine in Javascript, isn't best practice. I would just use a separate variable.

Then you can simplify everything like this

var blankIcon = defined(iconNode) && !defined(icon);

...

if (!defined(billboard.image) && !blankIcon) {
              billboard.image = dataSource._pinBuilder.fromColor(Color.YELLOW, 64);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blankIcon would be set in the processBillboardIcon method, while the check if (!defined(billboard.image) && !blankIcon) would need to happen in processPositionGraphics method.

Therefore, I believe the only ways to incorporate your suggestions would be to make blankIcon a global variable or a property of billboard. Is either of these ways better than the current way?

@tfili
Copy link
Contributor

tfili commented Oct 23, 2017

@josh-bernstein Looks good. I've seen that test fail before. I restarted the build. Hopefully it resolves itself. Other than that I just have the one comment on your new code.

@josh-bernstein
Copy link
Contributor Author

@tfili Please see my reply to your comment

@hpinkos
Copy link
Contributor

hpinkos commented Oct 23, 2017

@josh-bernstein I fixed the failing test in master. If you merge that into your branch, it should pass. Thanks!

@josh-bernstein
Copy link
Contributor Author

Awesome thanks @hpinkos

@josh-bernstein
Copy link
Contributor Author

Actually @hpinkos it appears that master is already merged into my branch

@tfili
Copy link
Contributor

tfili commented Oct 23, 2017

@josh-bernstein My mistake.

Also, it looks like you merged master in 4 hours ago, but the fix wasn't merge until 2 hours ago. Could you merge it in so the tests pass.

@josh-bernstein
Copy link
Contributor Author

@tfili When I do git pull origin master it says 'already up-to-date'.
Same if I checkout master, git pull, then go back to my branch and try to merge.

@hpinkos
Copy link
Contributor

hpinkos commented Oct 23, 2017

@josh-bernstein Make sure you're fetching master from our repo: https://help.github.com/articles/syncing-a-fork/

@josh-bernstein
Copy link
Contributor Author

@hpinkos Thank you for the instructions, but I think I'm missing something.

I've tried different combinations of git fetch upstream, git fetch AnalyticalGraphicsInc, git pull upstream master, git pull AnalyticalGraphicsInc:master`, but they all give errors.

Any advice would be appreciated.

Thank you.

@hpinkos
Copy link
Contributor

hpinkos commented Oct 23, 2017

@josh-bernstein make sure you set upstream first
git remote add upstream [email protected]:AnalyticalGraphicsInc/cesium.git

@josh-bernstein
Copy link
Contributor Author

@hpinkos @tfili Ok, I merged master. Let's see if that works.

@josh-bernstein
Copy link
Contributor Author

Oh no, it failed again!

@@ -1140,6 +1146,8 @@ define([

if (!defined(billboard.image)) {
billboard.image = dataSource._pinBuilder.fromColor(Color.YELLOW, 64);
} else if (billboard.image == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josh-bernstein this is why CI failed on eslint. == should be ===

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hpinkos This condition is only true in the desired cases if I use ==, not ===.
I could remove this 'else if' block altogether and it will still function correctly. I just think it is more intuitive to set the value back from false to undefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do } else if (!billboard.image) { instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what is the value of billboard.image here? Is it 'false' instead of false?
In that case, do } else if (billboard.image === 'false') {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You explicitly set billboard.image to false. === should work in this case because the type and value will match.

Copy link
Contributor Author

@josh-bernstein josh-bernstein Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hpinkos billboard.image instanceof ConstantProperty throws error saying ConstantProperty is undefined. However, everything seems to work if I do } else if (billboard.image && !billboard.image.getValue()) {

Copy link
Contributor

@hpinkos hpinkos Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the top of the file, require in ConstantProperty. See how we require in CompositePositionProperty in this file for an example. We want to make sure it's a constant property because other property types require an argument passed into getValue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hpinkos In what other situation would billboard.image be defined but have a value of false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I had to double check throughout the code but it looks like if it is defined it will always be a ConstantProperty. So we can safely just do } else if (!billboard.image.getValue()) {. I was just being cautious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hpinkos Ok sounds good. Thanks for checking it out!

@josh-bernstein
Copy link
Contributor Author

@tfili @hpinkos Looks like it's good now!

@hpinkos
Copy link
Contributor

hpinkos commented Oct 23, 2017

Thanks for fixing this @josh-bernstein!

@hpinkos hpinkos merged commit ae9be87 into CesiumGS:master Oct 23, 2017
@josh-bernstein
Copy link
Contributor Author

@hpinkos My pleasure!

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

Successfully merging this pull request may close these issues.

8 participants