Skip to content

Commit

Permalink
Fix expanded for categorized symbology in group as layer
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Oct 17, 2024
1 parent e4073b8 commit bd2218e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion assets/src/components/Treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class Treeview extends HTMLElement {

this._symbolTemplate = symbol =>
html`
<li class="symbol${this._isInScale(symbol) ? '' : ' not-in-scale'}${symbol.ruleKey && !symbol.checked ? ' not-visible' : ''}">
<li class="symbol ${symbol.type}${this._isInScale(symbol) ? '' : ' not-in-scale'}${symbol.ruleKey && !symbol.checked ? ' not-visible' : ''}">
${(symbol.childrenCount)
? html`
<div class="expandable ${symbol.expanded ? 'expanded' : ''}" @click=${() => symbol.expanded = !symbol.expanded}></div>`
Expand Down
11 changes: 11 additions & 0 deletions assets/src/modules/state/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ export class LayerItemState extends EventDispatcher {
});
}, 'symbol.expanded.changed');
}
} else if (this.symbology instanceof LayerGroupSymbology) {
const self = this;
this.symbology.addListener(evt => {
self.dispatch({
type: 'layer.symbol.expanded.changed',
name: self.name,
title: evt.title,
ruleKey: evt.ruleKey,
expanded: evt.expanded,
});
}, 'symbol.expanded.changed');
}
this.dispatch({
type: this.mapType + '.symbology.changed',
Expand Down
1 change: 1 addition & 0 deletions assets/src/modules/state/MapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class MapItemState extends EventDispatcher {
this.dispatch.bind(this),
layerItemState.mapType + '.opacity.changed'
);
layerItemState.addListener(this.dispatch.bind(this), 'layer.symbol.expanded.changed');
} else {
layerItemState.addListener(this.dispatch.bind(this), 'layer.visibility.changed');
layerItemState.addListener(this.dispatch.bind(this), 'layer.symbology.changed');
Expand Down
42 changes: 32 additions & 10 deletions assets/src/modules/state/Symbology.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ export class BaseObjectSymbology extends EventDispatcher {

/**
* Create a base symbology instance based on a node object provided by QGIS Server
* @param {object} node - the QGIS node symbology
* @param {string} node.title - the node title
* @param {object} node - the QGIS node symbology
* @param {string} node.title - the node title
* @param {string} [node.type] - the node type
* @param {object} [requiredProperties] - the required properties definition
* @param {object} [optionalProperties] - the optional properties definition
* @param {object} [optionalProperties] - the optional properties definition
*/
constructor(node, requiredProperties = { 'title': { type: 'string' } }, optionalProperties = {}) {

constructor(node, requiredProperties = { 'title': { type: 'string' } }, optionalProperties = {})
{
if (!node.hasOwnProperty('type')) {
node.type = 'icon';
}
if (!requiredProperties.hasOwnProperty('type')) {
requiredProperties['type'] = { type: 'string' };
}
if (!requiredProperties.hasOwnProperty('title')) {
requiredProperties['title'] = { type: 'string' };
}
Expand All @@ -104,6 +111,14 @@ export class BaseObjectSymbology extends EventDispatcher {
applyConfig(this, node, requiredProperties, optionalProperties)
}

/**
* The symbology type
* @type {string}
*/
get type() {
return this._type;
}

/**
* The symbology title
* @type {string}
Expand All @@ -121,14 +136,15 @@ export class BaseObjectSymbology extends EventDispatcher {
export class BaseIconSymbology extends BaseObjectSymbology {
/**
* Create a base icon symbology instance based on a node object provided by QGIS Server
* @param {object} node - the QGIS node symbology
* @param {string} node.icon - the png image in base64
* @param {string} node.title - the node title
* @param {object} node - the QGIS node symbology
* @param {string} node.icon - the png image in base64
* @param {string} node.title - the node title
* @param {string} [node.type] - the node type
* @param {object} [requiredProperties] - the required properties definition
* @param {object} [optionalProperties] - the optional properties definition
*/
constructor(node, requiredProperties={}, optionalProperties = {}) {

constructor(node, requiredProperties={}, optionalProperties = {})
{
if (!requiredProperties.hasOwnProperty('icon')) {
requiredProperties['icon'] = { type: 'string' };
}
Expand Down Expand Up @@ -211,6 +227,9 @@ export class SymbolIconSymbology extends BaseIconSymbology {
* @param {boolean} node.checked - the node is checked by default
*/
constructor(node) {
if (!node.hasOwnProperty('type')) {
node.type = 'icon';
}
super(node, symbolIconProperties, symbolIconOptionalProperties)
this._childrenRules = []
}
Expand Down Expand Up @@ -280,6 +299,9 @@ const symbolRuleOptionalProperties = Object.assign(
*/
export class SymbolRuleSymbology extends SymbolIconSymbology {
constructor(node) {
if (!node.hasOwnProperty('type')) {
node.type = 'rule';
}
super(node, symbolRuleProperties, symbolRuleOptionalProperties)
this._parentRule = null;
this._childrenRules = [];
Expand Down

0 comments on commit bd2218e

Please sign in to comment.