Skip to content

Commit

Permalink
Allow to define which layers to hide to end user within Table of Cont…
Browse files Browse the repository at this point in the history
…ents (#625)

* get toc layerstree configuration attribute to sho or not layer on toc.
In case of toc === false, if layer is visible on map and returned from queryresult, selection is hide

* jsdoc

---------

Co-authored-by: Raruto <Raruto@users.noreply.github.com>
  • Loading branch information
volterra79 and Raruto authored May 9, 2024
1 parent b39725f commit c9e6da3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
82 changes: 49 additions & 33 deletions src/app/core/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,65 +79,66 @@ function Layer(config={}, options={}) {
this.config.urls.featurecount = project.getUrl('featurecount');

/**
* Custom parameters based on project qgis version
* Custom parameters based on a project qgis version
*/
this.config.searchParams = { I: 0, J: 0 };
}

// dinamic layer values useful for layerstree
const defaultstyle = config.styles && config.styles.find(style => style.current).name;

/**
* @TODO make it simpler, `this.config` and `this.state` are essentially duplicated data
*/
this.state = {

id: config.id,
id: config.id,

title: config.title,
title: config.title,

selected: config.selected || false,
selected: config.selected || false,

disabled: config.disabled || false,
disabled: config.disabled || false,

metadata: config.metadata,
metadata: config.metadata,

metadata_querable: this.isBaseLayer() ? false: this.isQueryable({onMap:false}),
metadata_querable: this.isBaseLayer() ? false: this.isQueryable({onMap:false}),

openattributetable: this.isBaseLayer() ? false: this.canShowTable(),

removable: config.removable || false,
removable: config.removable || false,

downloadable: this.isDownloadable(),
downloadable: this.isDownloadable(),

source: config.source,
source: config.source,

styles: config.styles,
styles: config.styles,

defaultstyle,

/**
* state of if is in editing (setted by editing plugin)
*/
inediting: false,
inediting: false,

infoformat: this.getInfoFormat(),
infoformat: this.getInfoFormat(),

infoformats: this.config.infoformats || [],
infoformats: this.config.infoformats || [],

projectLayer: true,
projectLayer: true,

geolayer: false,
geolayer: false,

/**
* Reactive selection attribute
*/
selection: {
active: false
},
selection: { active: false },

/**
* Reactive filter attribute
*/
filter: {
active: false,
active: false,

/**
* @since 3.9.0 whether filter is set from a previously saved filter
Expand All @@ -150,34 +151,49 @@ function Layer(config={}, options={}) {
*
* @since 3.9.0
*/
filters: config.filters || [],
filters: config.filters || [],

attributetable: {
pageLength: null
},
attributetable: { pageLength: null },


visible: config.visible || false,
visible: config.visible || false,

tochighlightable: false,
tochighlightable: false,

/**
* @type {number}
*
* @since 3.8.0
*/
featurecount: config.featurecount,
featurecount: config.featurecount,

/**
* @type { boolean | Object<number, number> }
*
* @since 3.8.0
*/
stylesfeaturecount: config.featurecount && defaultstyle && {
[defaultstyle]: config.featurecount
},
name: config.name, /** since 3.10.0 **/
expanded: config.expanded, /** since 3.10.0 **/
stylesfeaturecount: config.featurecount && defaultstyle && { [defaultstyle]: config.featurecount },

/**
* @type { string }
*
* @since 3.10.0
*/
name: config.name,

/**
* @type { boolean }
*
* @since 3.10.0
*/
expanded: config.expanded,

/**
* @type { boolean } whether to show layer on TOC (default: true)
*
* @since 3.10.0
*/
toc: 'boolean' === typeof config.toc ? config.toc: true,

};

Expand Down Expand Up @@ -1016,7 +1032,7 @@ proto.getUrl = function(type) {
* @param url.type
* @param url.url
*/
proto.setUrl = function({type, url}={}) {
proto.setUrl = function({ type, url } = {}) {
this.config.urls[type] = url;
};

Expand Down
3 changes: 2 additions & 1 deletion src/app/gui/queryresults/queryresultsservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class QueryResultsService extends G3WObject {
}

// Lookup for layer selection status (active).
if (undefined !== layer.selection.active) {
if (layer.toc && undefined !== layer.selection.active) {
this._setActionSelection(layer);
}

Expand Down Expand Up @@ -1028,6 +1028,7 @@ class QueryResultsService extends G3WObject {
atlas: this.getAtlasByLayerId(id),
rawdata: rawdata ? rawdata : null,
error: error ? error : '',
toc: external || layer.state.toc, //@since v3.10.0
};

return layerObj;
Expand Down
1 change: 1 addition & 0 deletions src/components/CatalogTristateTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<template>

<li
v-if = "isGroup || !layerstree.projectLayer || layerstree.toc"
class = "tree-item"
@contextmenu.prevent.stop = "showContextMenu"
@click.stop = "onTreeItemClick"
Expand Down
1 change: 1 addition & 0 deletions src/components/QueryResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
</span>
<span
v-if = "
layer.toc &&
layer.id !== '__g3w_marker' &&
layer.features.length > 1 &&
(layer.external || (layer.source && layer.source.type !== 'wms'))
Expand Down

0 comments on commit c9e6da3

Please sign in to comment.