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

[Backport release_3_8] [Bugfix] JS config themes #4571

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -107,7 +118,8 @@ export class Config {
'tooltipLayers',
'editionLayers',
'formFilterLayers',
'loginFilteredLayers'
'loginFilteredLayers',
'themes'
];
for (const prop of optionalConfigProperties) {
if (!theConfig.hasOwnProperty(prop)
Expand Down Expand Up @@ -230,13 +242,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 @@ -252,13 +264,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 @@ -274,13 +286,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 @@ -312,13 +324,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 @@ -334,13 +346,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 @@ -356,13 +368,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 @@ -376,6 +388,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 @@ -394,27 +428,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 },
'wms_single_request_for_all_layers' : { type:'boolean', default: false }
};

Expand Down Expand Up @@ -63,6 +64,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 ?
* @param {boolean} [cfg.wms_single_request_for_all_layers] - are layers loaded as single WMS image ?
*/
constructor(cfg) {
Expand Down Expand Up @@ -237,6 +239,14 @@ export class OptionsConfig extends BaseObjectConfig {
return this._hideGroupCheckbox;
}

/**
* Activate first map theme
* @type {boolean}
*/
get activateFirstMapTheme() {
return this._activateFirstMapTheme;
}

/**
* The layers are loaded as a single WMS image
* @type {boolean}
Expand Down
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
Loading