@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
57 lines (56 loc) • 3.22 kB
JavaScript
import { htmlFor as uHtmlFor } from 'uhtml/keyed';
import { html as uHtml } from 'uhtml';
// SPDX-License-Identifier: Apache-2.0
import GirafeHTMLElement from '../../../base/GirafeHTMLElement.js';
import GroupLayer from '../../../models/layers/grouplayer.js';
import ThemeLayer from '../../../models/layers/themelayer.js';
class MobileGroupElementComponent extends GirafeHTMLElement {
templateUrl = null;
styleUrls = null;
template = () => {
return uHtml `<style>
.hidden{display:none}.gg-tabs{cursor:pointer;grid-auto-flow:column;padding-bottom:1rem;font-size:1rem;display:grid}.gg-tab{border:none;border-bottom:var(--app-standard-border);cursor:pointer;color:var(--text-color);background:0 0;padding:.5rem}.gg-tab.active{border-bottom:solid 1px var(--text-color)}button,input,select,textarea{font:inherit}.gg-icon-button,.gg-button{color:var(--text-color);cursor:pointer;background-color:#0000;border:none;flex-direction:column;justify-content:center;align-items:center;padding:0;display:flex}.gg-button{text-align:left}.gg-small{flex-direction:row}.gg-small img{width:calc(var(--app-standard-height) / 2.5);margin:0}.gg-small span{margin-left:.5rem;font-size:1rem}.girafe-button-big{filter:drop-shadow(0 0 8px #0000004d);background-color:var(--bkg-color);width:3.5rem;height:3.5rem;color:var(--text-color);border:none;border-radius:4rem;flex-direction:column;align-items:center;padding:.5rem;display:flex}.girafe-button-big img{width:95%;height:auto;padding:5%;overflow:hidden}.girafe-button-big:hover,.girafe-button-large:hover,.girafe-button-small:hover,.girafe-button-tiny:hover{background-color:var(--bkg-color)}
</style><style>
h3{text-align:center;font-variant:small-caps;background-color:var(--text-color);color:var(--bkg-color);padding:1rem;font-size:1rem}
</style>
<style>${this.customStyle}</style>
<h3 i18n="${this.group?.name}">${this.group?.name}</h3><div class="children">${(this.childLayers ?? []).map(layer => uHtmlFor(layer, layer.treeItemId) `<girafe-layer layerid="${layer.treeItemId}"></girafe-layer>`)}</div>
${this.htmlUnsafe(this.feedbackTemplateHtml ?? '')}`;
};
group;
/**
* Contains all childs recursively flattend for a better view in mobile
*/
childLayers = [];
static observedAttributes = [];
constructor() {
super('group-mobile');
}
render() {
super.render();
this.refreshGroup();
}
refreshGroup() {
const groupId = this.getAttribute('groupid');
if (groupId) {
this.group = this.context.layerManager.getTreeItem(groupId);
if (this.group) {
this.childLayers = this.context.layerManager.getFlattenedLayerTree(this.group.children).filter((l) => {
return !(l instanceof ThemeLayer || l instanceof GroupLayer);
});
}
}
super.refreshRender();
}
connectedCallback() {
super.connectedCallback();
MobileGroupElementComponent.observedAttributes.push('groupid');
this.render();
}
attributeChangedCallback(name) {
if (name === 'groupid') {
this.refreshGroup();
}
}
}
export default MobileGroupElementComponent;