Skip to content

Commit

Permalink
avoid polluting user-defined styles (scene.config.styles) with blend/…
Browse files Browse the repository at this point in the history
…base default styles
  • Loading branch information
bcamper committed Jan 4, 2020
1 parent 4fc6b91 commit 824ec12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 0 additions & 12 deletions src/scene/scene_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,6 @@ export default SceneLoader = {
};
}

// Add default blend/base style pairs as needed
const blends = ['opaque', 'add', 'multiply', 'overlay', 'inlay', 'translucent'];
const bases = ['polygons', 'lines', 'points', 'text'];
for (const blend of blends) {
for (const base of bases) {
const style = blend + '_' + base;
if (config.styles[style] == null) {
config.styles[style] = { base, blend };
}
}
}

return { config, bundle };
}

Expand Down
16 changes: 15 additions & 1 deletion src/styles/style_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,27 @@ export class StyleManager {
}

// Called to create and initialize styles
build (styles) {
build (styles_defs) {
const styles = { ...styles_defs }; // copy to avoid modifying underlying object

// Un-register existing styles from cross-thread communication
if (this.styles) {
Object.values(this.styles)
.forEach(s => WorkerBroker.removeTarget(s.main_thread_target));
}

// Add default blend/base style pairs as needed
const blends = ['opaque', 'add', 'multiply', 'overlay', 'inlay', 'translucent'];
const bases = ['polygons', 'lines', 'points', 'text'];
for (const blend of blends) {
for (const base of bases) {
const style = blend + '_' + base;
if (styles[style] == null) {
styles[style] = { base, blend };
}
}
}

// Sort styles by dependency, then build them
let style_deps = Object.keys(styles).sort(
(a, b) => this.inheritanceDepth(a, styles) - this.inheritanceDepth(b, styles)
Expand Down

0 comments on commit 824ec12

Please sign in to comment.