Skip to content

Commit

Permalink
Merge pull request #4572 from rldhont/backport-4514-to-release_3_7
Browse files Browse the repository at this point in the history
[Backport release_3_7] [Bugfix] JS config themes
  • Loading branch information
rldhont authored Jul 3, 2024
2 parents 4d5e66a + 669aa3b commit 21147b6
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 76 deletions.
12 changes: 10 additions & 2 deletions assets/src/legacy/switcher-layers-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,12 @@ var lizLayerActionButtons = function() {
lizMap.mainLizmap.state.baseLayers.selectedBaseLayerName = "project-background-color";
} else {
for (const baseLayer of lizMap.mainLizmap.state.baseLayers.getBaseLayers()) {
if (!baseLayer.layerConfig) {
continue;
}
if (themeSelected?.layers?.[baseLayer.layerConfig.id]) {
lizMap.mainLizmap.state.baseLayers.selectedBaseLayerName = baseLayer.name;
continue;
break;
}
}
}
Expand All @@ -350,9 +353,14 @@ var lizLayerActionButtons = function() {
);

// Activate first map theme on load
if ('activateFirstMapTheme' in lizMap.config.options && lizMap.config.options.activateFirstMapTheme == 'True') {
if (lizMap.mainLizmap.initialConfig.options.activateFirstMapTheme) {
$('#theme-selector li.theme:nth-child(1)').click();
}
const urlParameters = (new URL(document.location)).searchParams;
if (urlParameters.has('mapTheme')) {
const urlMapTheme = urlParameters.get('mapTheme');
$('#theme-selector li.theme').filter((i, e) => e.textContent == urlMapTheme).click();
}
}

featureTypes = lizMap.getVectorLayerFeatureTypes();
Expand Down
102 changes: 68 additions & 34 deletions assets/src/modules/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import { TooltipLayersConfig } from './config/Tooltip.js';
import { EditionLayersConfig } from './config/Edition.js';
import { TimeManagerLayersConfig } from './config/TimeManager.js';
import { FormFilterConfig } from './config/FormFilter.js';
import { ThemesConfig } from './config/Theme.js';
import { DatavizOptionsConfig, DatavizLayersConfig } from './config/Dataviz.js';
import { buildLayerTreeConfig } from './config/LayerTree.js';
import { buildLayerTreeConfig, LayerTreeGroupConfig } from './config/LayerTree.js';
import { buildLayersOrder } from './config/LayersOrder.js';

/**
Expand Down Expand Up @@ -59,15 +60,25 @@ export class Config {
this._hasMetadata = true;
this._metadata = null;
this._hasLocateByLayer = true;
this._locateByLayer = null;
this._hasAttributeLayers = true;
this._attributeLayers = null;
this._hasTimemanagerLayers = true;
this._timemanagerLayers = null;
this._hasRelations = true;
this._hasPrintTemplates = true;
this._hasTooltipLayers = true;
this._tooltipLayers = null;
this._hasEditionLayers = true;
this._editionLayers = null;
this._hasFormFilterLayers = true;
this._formFilterLayers = null;
this._hasLoginFilteredLayers = true;
this._hasThemes = true;
this._themes = null;
this._hasDatavizConfig = true;
this._datavizLayers = null;
this._datavizOptions = null;

const theConfig = deepFreeze(cfg);

Expand Down Expand Up @@ -108,7 +119,8 @@ export class Config {
'tooltipLayers',
'editionLayers',
'formFilterLayers',
'loginFilteredLayers'
'loginFilteredLayers',
'themes'
];
for (const prop of optionalConfigProperties) {
if (!theConfig.hasOwnProperty(prop)
Expand Down Expand Up @@ -231,13 +243,13 @@ export class Config {

/**
* Config locateByLayer
* @type {LocateByLayerConfig}
* @type {LocateByLayerConfig|null}
*/
get locateByLayer() {
if (this._locateByLayer != null) {
return this._locateByLayer;
}
if (this._hasLocateByLayer) {
if (this._locateByLayer != null) {
return this._locateByLayer;
}
this._locateByLayer = new LocateByLayerConfig(this._theConfig.locateByLayer);
}
return this._locateByLayer;
Expand All @@ -253,13 +265,13 @@ export class Config {

/**
* Config attribueLayers
* @type {AttributeLayersConfig}
* @type {AttributeLayersConfig|null}
*/
get attributeLayers() {
if (this._attributeLayers != null) {
return this._attributeLayers;
}
if (this._hasAttributeLayers) {
if (this._attributeLayers != null) {
return this._attributeLayers;
}
this._attributeLayers = new AttributeLayersConfig(this._theConfig.attributeLayers);
}
return this._attributeLayers;
Expand All @@ -275,13 +287,13 @@ export class Config {

/**
* Config timemanagerLayers
* @type {AttributeLayersConfig}
* @type {AttributeLayersConfig|null}
*/
get timemanagerLayers() {
if (this._timemanagerLayers != null) {
return this._timemanagerLayers;
}
if (this._hasTimemanagerLayers) {
if (this._timemanagerLayers != null) {
return this._timemanagerLayers;
}
this._timemanagerLayers = new TimeManagerLayersConfig(this._theConfig.timemanagerLayers);
}
return this._timemanagerLayers;
Expand Down Expand Up @@ -313,13 +325,13 @@ export class Config {

/**
* Config tooltipLayers
* @type {TooltipLayersConfig}
* @type {TooltipLayersConfig|null}
*/
get tooltipLayers() {
if (this._tooltipLayers != null) {
return this._tooltipLayers;
}
if (this._hasTooltipLayers) {
if (this._tooltipLayers != null) {
return this._tooltipLayers;
}
this._tooltipLayers = new TooltipLayersConfig(this._theConfig.tooltipLayers);
}
return this._tooltipLayers;
Expand All @@ -335,13 +347,13 @@ export class Config {

/**
* Config editionLayers
* @type {EditionLayersConfig}
* @type {EditionLayersConfig|null}
*/
get editionLayers() {
if (this._editionLayers != null) {
return this._editionLayers;
}
if (this._hasEditionLayers) {
if (this._editionLayers != null) {
return this._editionLayers;
}
this._editionLayers = new EditionLayersConfig(this._theConfig.editionLayers);
}
return this._editionLayers;
Expand All @@ -357,13 +369,13 @@ export class Config {

/**
* Config formFilterLayers
* @type {FormFilterConfig}
* @type {FormFilterConfig|null}
*/
get formFilterLayers() {
if (this._formFilterLayers != null) {
return this._formFilterLayers;
}
if (this.hasFormFilterLayers) {
if (this._formFilterLayers != null) {
return this._formFilterLayers;
}
this._formFilterLayers = new FormFilterConfig(this._theConfig.formFilterLayers);
}
return this._formFilterLayers;
Expand All @@ -377,6 +389,28 @@ export class Config {
return this._hasLoginFilteredLayers;
}

/**
* Themes config is defined
* @type {boolean}
*/
get hasThemes() {
return this._hasThemes;
}

/**
* Config themes
* @type {ThemesConfig|null}
*/
get themes() {
if (this.hasThemes) {
if (this._themes != null) {
return this._themes;
}
this._themes = new ThemesConfig(this._theConfig.themes);
}
return this._themes;
}

/**
* Dataviz locale
* @type {string}
Expand All @@ -395,27 +429,27 @@ export class Config {

/**
* Config datavizLayers
* @type {DatavizLayersConfig}
* @type {DatavizLayersConfig|null}
*/
get datavizLayers() {
if (this._datavizLayers != null) {
return this._datavizLayers;
}
if (this._hasDatavizConfig) {
if (this._datavizLayers != null) {
return this._datavizLayers;
}
this._datavizLayers = new DatavizLayersConfig(this._theConfig.datavizLayers.layers);
}
return this._datavizLayers;
}

/**
* Config datavizOptions
* @type {DatavizOptionsConfig}
* @type {DatavizOptionsConfig|null}
*/
get datavizOptions() {
if (this._datavizOptions != null) {
return this._datavizOptions;
}
if (this._hasDatavizConfig) {
if (this._datavizOptions != null) {
return this._datavizOptions;
}
this._datavizOptions = new DatavizOptionsConfig(this._theConfig.datavizLayers.dataviz);
}
return this._datavizOptions;
Expand Down
10 changes: 10 additions & 0 deletions assets/src/modules/config/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const optionalProperties = {
'use_native_zoom_levels': {type: 'boolean', nullable: true, default: null},
'hide_numeric_scale_value': {type: 'boolean', default: false},
'hideGroupCheckbox': { type: 'boolean', default: false },
'activateFirstMapTheme': { type: 'boolean', default: false }
};

/**
Expand Down Expand Up @@ -62,6 +63,7 @@ export class OptionsConfig extends BaseObjectConfig {
* @param {boolean} [cfg.use_native_zoom_levels] - does the map use native zoom levels ?
* @param {boolean} [cfg.hide_numeric_scale_value] - does the scale line hide numeric scale value ?
* @param {boolean} [cfg.hideGroupCheckbox] - are groups checkbox hidden ?
* @param {boolean} [cfg.activateFirstMapTheme] - is first map theme activated ?
*/
constructor(cfg) {
if (!cfg || typeof cfg !== "object") {
Expand Down Expand Up @@ -234,4 +236,12 @@ export class OptionsConfig extends BaseObjectConfig {
get hideGroupCheckbox() {
return this._hideGroupCheckbox;
}

/**
* Activate first map theme
* @type {boolean}
*/
get activateFirstMapTheme() {
return this._activateFirstMapTheme;
}
}
42 changes: 41 additions & 1 deletion assets/src/modules/config/Theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ export class LayerThemeConfig extends BaseObjectConfig {

const themeRequiredProperties = {
'layers': {type: 'object'},
'expandedGroupNode': {type: 'array'},
}

const themeOptionalProperties = {
'checkedGroupNode': {type: 'array', default: []},
'expandedGroupNode': {type: 'array', default: []},
'expandedLegendNode': {type: 'array', default: []},
}

/**
Expand Down Expand Up @@ -117,6 +119,14 @@ export class ThemeConfig extends BaseObjectConfig {
return [...this._layerConfigs];
}

/**
* The copy of the checked group nodes list
* @type {string[]}
*/
get checkedGroupNodes() {
return [...this._checkedGroupNode];
}

/**
* The copy of the expanded group nodes list
* @type {string[]}
Expand All @@ -125,6 +135,14 @@ export class ThemeConfig extends BaseObjectConfig {
return [...this._expandedGroupNode];
}

/**
* The copy of the expanded legend nodes list
* @type {string[]}
*/
get expandedLegendNodes() {
return [...this._expandedLegendNode];
}

/**
* Iterate through layer ids of the theme
* @generator
Expand All @@ -147,6 +165,17 @@ export class ThemeConfig extends BaseObjectConfig {
}
}

/**
* Iterate through the checked group nodes list
* @generator
* @yields {string} The next checked group node
*/
*getCheckedGroupNodes() {
for (const node of this._checkedGroupNode) {
yield node;
}
}

/**
* Iterate through the expanded group nodes list
* @generator
Expand All @@ -158,6 +187,17 @@ export class ThemeConfig extends BaseObjectConfig {
}
}

/**
* Iterate through the expanded legend nodes list
* @generator
* @yields {string} The next expanded legend node
*/
*getExpandedLegendNodes() {
for (const node of this._expandedLegendNode) {
yield node;
}
}

/**
* Get a layer config of the theme by layer id
* @param {string} layerId the layer id
Expand Down
1 change: 1 addition & 0 deletions lizmap/modules/view/controllers/map.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function index()
'filter',
'layerStyles',
'layerOpacities',
'mapTheme',
);
// Get redirection parameters
$redirectKeyParams = jEvent::notify('getRedirectKeyParams', array('repository' => $repository, 'project' => $project))->getResponse();
Expand Down
Loading

0 comments on commit 21147b6

Please sign in to comment.