Skip to content

Commit

Permalink
Set the background layer from the them at page load
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed Jan 12, 2018
1 parent 9fd5afb commit c4da277
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
35 changes: 16 additions & 19 deletions contribs/gmf/src/controllers/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ gmf.AbstractController = function(config, $scope, $injector) {
this.gmfThemeManager.setThemeName('', true);
if (evt.type !== gmf.AuthenticationEventType.READY) {
this.updateCurrentTheme_(previousThemeName);
} else {
// initialize default background layer
this.setDefaultBackground_(null, true);
}
// Reload themes when login status changes.
this.gmfThemes_.loadThemes(roleId);
Expand Down Expand Up @@ -416,7 +413,7 @@ gmf.AbstractController = function(config, $scope, $injector) {
$scope.$root.$on(gmf.ThemeManagerEventType.THEME_NAME_SET, (event, name) => {
this.gmfThemes_.getThemeObject(name).then((theme) => {
if (theme) {
this.setDefaultBackground_(theme, false);
this.setDefaultBackground_(theme);
}
});
});
Expand Down Expand Up @@ -590,31 +587,31 @@ gmf.AbstractController.prototype.initLanguage = function() {

/**
* @param {gmfThemes.GmfTheme} theme Theme.
* @param {boolean} use_permalink Get background from the permalink.
* @private
*/
gmf.AbstractController.prototype.setDefaultBackground_ = function(theme, use_permalink) {
gmf.AbstractController.prototype.setDefaultBackground_ = function(theme) {
this.gmfThemes_.getBgLayers(this.dimensions).then((layers) => {
let layer;

if (use_permalink) {
// get the background from the permalink
layer = this.permalink_.getBackgroundLayer(layers);
}
// get the background from the permalink
layer = this.permalink_.getBackgroundLayer(layers);

if (!layer) {
// get the background from the user settings
layer = gmf.AbstractController.getLayerByLabels(layers, this.gmfUser.functionalities.default_basemap);
if (!layer && theme) {
// get the background from the theme
layer = gmf.AbstractController.getLayerByLabels(layers, theme.functionalities.default_basemap);
}
if (!layer) {
// fallback to the layers list, use the second one because the first is the blank layer.
layer = layers[1];
}
}
goog.asserts.assert(layer);

if (!layer) {
// get the background from the theme
layer = gmf.AbstractController.getLayerByLabels(layers, theme.functionalities.default_basemap);
}

if (!layer) {
// fallback to the layers list, use the second one because the first is the blank layer.
layer = layers[1];
}

goog.asserts.assert(layer);
this.backgroundLayerMgr_.set(this.map, layer);
});
};
Expand Down
9 changes: 4 additions & 5 deletions contribs/gmf/src/services/permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ gmf.Permalink = function($timeout, $rootScope, $injector, ngeoDebounce,

if (this.gmfThemeManager_) {
this.rootScope_.$on(gmf.ThemeManagerEventType.THEME_NAME_SET, (event, name) => {
this.setThemeInUrl_();
this.setThemeInUrl_(name);
});
}

Expand Down Expand Up @@ -835,10 +835,10 @@ gmf.Permalink.prototype.themeInUrl_ = function(pathElements) {


/**
* @param {string} themeName Theme name.
* @private
*/
gmf.Permalink.prototype.setThemeInUrl_ = function() {
const themeName = this.gmfThemeManager_ ? this.gmfThemeManager_.getThemeName() : null;
gmf.Permalink.prototype.setThemeInUrl_ = function(themeName) {
if (themeName) {
const pathElements = this.ngeoLocation_.getPath().split('/');
goog.asserts.assert(pathElements.length > 1);
Expand Down Expand Up @@ -922,8 +922,7 @@ gmf.Permalink.prototype.initLayers_ = function() {
const themeName = this.defaultThemeName();

if (this.gmfThemeManager_ && this.gmfThemeManager_.modeFlush) {
// Set theme in stealth mode, we just want to set the theme name, not more.
this.gmfThemeManager_.setThemeName(`${themeName}`, true);
this.gmfThemeManager_.setThemeName(`${themeName}`);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions contribs/gmf/src/services/thememanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,10 @@ gmf.ThemeManager.prototype.isLoading = function() {

/**
* @param {string} name The new theme name.
* @param {boolean=} opt_stealth Don't emit an event is true
* @export
*/
gmf.ThemeManager.prototype.setThemeName = function(name, opt_stealth) {
gmf.ThemeManager.prototype.setThemeName = function(name) {
this.themeName_ = name;
if (!opt_stealth) {
this.$rootScope_.$emit(gmf.ThemeManagerEventType.THEME_NAME_SET, name);
}
this.$rootScope_.$emit(gmf.ThemeManagerEventType.THEME_NAME_SET, name);
};


Expand Down

0 comments on commit c4da277

Please sign in to comment.