3liz / lizmap-web-client

Transfer a QGIS project on a server, Lizmap is providing the web interface to browse it
https://www.lizmap.com
Mozilla Public License 2.0
249 stars 141 forks source link

[Bug]: treecreated event is fired before layer tree is created #3965

Open mind84 opened 8 months ago

mind84 commented 8 months ago

What is the bug?

Hi, I noticed that the treecreated event fires before the new lizmap-treeview web component is added to the DOM, wich happen after uicreated event fires.

Se image below: treeview The treecreated event appears to be designed to only work with the old Lizmap 3.6 tree view.

Any chances to port this event in LWC >= 3.7 ?

Thanks!

Steps to reproduce the issue

add this external js to reproduce the issue:

layertree_event.js.zip

Versions

Versions :

Check Lizmap plugin

QGIS server version, only if the section above doesn't mention the QGIS Server version

No response

Operating system

Debian GNU/Linux trixie/sid

Browsers

Firefox, Chrome

Browsers version

last

Relevant log output

No response

cfsgarcia commented 1 month ago

Same problem occurs in LWC 3.7.8. $("lizmap-treeview") returns nothing after treecreated or uicreated have been fired.

To workaround this problem I created another event domtreeadded fired after lizmap-treeview was injected into the DOM.

-> lizmap-web-client-3.7.8/assets/src/legacy/map.js line 5019

document.getElementById('switcher-layers').insertAdjacentHTML('afterend', '<lizmap-treeview></lizmap-treeview>');
/**
 * Event when the tree has been added to DOM
 * @event domtreeadded
 */
self.events.triggerEvent("domtreeadded", self);

line 5050

// initializing the lizMap events
obj.events = new OpenLayers.Events(
    obj, null,
    ['domtreeadded','treecreated'