Skip to content

rework data model of LayerItem / LayerManager #2860

@taulinger

Description

@taulinger

The underlying model is not clearly defined in the LayerItem class. It is somehow made up of class properties and the general layer object, which are painfully mixed together.

The following approach is a suggestion to strictly separate the layer from the LayerItem specific properties:

const Default_Layer_Item_Properties = {
	label: '',
	collapsed: true,
	loading: false,
	keywords: []
};

/**
 * Child element of the LayerManager. Represents one layer and its state.
 *
 * Note: each time the active property of the layers s-o-s changes, `layerItem#layer` is called by the parent `LayerManager` element, which updates the internal model.
 *
 * @class
 * @fires collapse
 * @property {module:store/layers/layers_action~Layer} layer
 * @property {boolean} collapsed
 */
export class LayerItem extends AbstractMvuContentPanel {
	constructor() {
		super({
			layer: null,
			layerItemProperties: { ...Default_Layer_Item_Properties },
			layerSwipeActive: false
		});

and

set layer(layer) {
	
		const translate = (key) => this._translationService.translate(key);
		const geoResource = this._geoResourceService.byId(layer.geoResourceId);
		const keywords = [...this._geoResourceService.getKeywords(layer.geoResourceId)];
	
		if (geoResource instanceof GeoResourceFuture) {
			

			geoResource.onResolve((resolvedGeoR) => {
				this.signal(Update_Layer_And_LayerProperties, {
					layer: { ...layer },
					changedLayerItemProperties: {
						label: resolvedGeoR.label,
						loading: false,
				});
			});
		}

		this.signal(Update_Layer_And_LayerProperties, {
			layer: { ...layer },
			changedLayerItemProperties: {
				label: geoResource instanceof GeoResourceFuture ? translate('layerManager_loading_hint') : geoResource.label,
				loading: geoResource instanceof GeoResourceFuture,
				keywords,
			}
		});
}

set collapse(collapsed){
	this.signal(Update_Layer_Collapsed, collapsed);
}

The payload of the CustomEvent has to be re-defined and documented.
Also, the onCollapse callback is never used and can be removed

Metadata

Metadata

Labels

code qualityImprovement of code quality / houesekeeping

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions