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

Improve diffing of styles containing "visibility": "visible" #8005

Merged
merged 4 commits into from
Mar 8, 2019

Conversation

lucaswoj
Copy link
Contributor

@lucaswoj lucaswoj commented Mar 7, 2019

When I execute this code:

const style = {
    version: 8,
    sources: {},
    layers: [{id: 'background', layout: {visibility: 'visible'}]
}
const map = new Map({style, ...});
map.setStyle(style)

I expect setStyle to do a diff-based update which reduces to a no-op.

However what actually happens is that it produces a ['setLayoutProperty', 'visibility', null] command because we store visibility: 'visible' the same way as visibility: undefined and always serialize into the latter. map.getStyle().layers[0].layout.visibility is undefined.

It is expensive to run a large number of ['setLayoutProperty', 'visibility', null] commands.

Other properties do not behave like this. Visibility is a special case.

This PR correctly stores and serializes the state of visibility into either visible or undefined.

This may fix #7459
This may fix #7648

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • manually test the debug page

@lucaswoj
Copy link
Contributor Author

lucaswoj commented Mar 7, 2019

All callsites that use the visibility property check it as .visibility !== 'none' so this change should be okay.

Copy link
Contributor

@asheemmamoowala asheemmamoowala left a comment

Choose a reason for hiding this comment

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

👋 @lucaswoj

@@ -210,7 +209,7 @@ class StyleLayer extends Evented {
'paint': this._transitionablePaint && this._transitionablePaint.serialize()
};

if (this.visibility === 'none') {
if (this.visibility) {

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I’ve fixed this in a subsequent commit. Or I misunderstand. There’s a test that ensures it can be set to “visible”.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, I was viewing a single commit instead of all the changes.

@lucaswoj
Copy link
Contributor Author

lucaswoj commented Mar 8, 2019

Thanks @asheemmamoowala! I think you need to press the big green button 😄.

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.

2 participants