EOX-A / EOxElements

A Web Component collection of geospatial UI elements, crafted by EOX.
https://eox-a.github.io/EOxElements/
MIT License
12 stars 2 forks source link

Trigger an event that signals when OL map has mounted #914

Closed StefanBrand closed 3 months ago

StefanBrand commented 5 months ago

Follow-up of #443 and #911


Currently it is not possible to find out when the .map property is no longer undefined, i.e. when the OL map has been instantiated. Having an event that is triggered after the OL map has been instantiated would make it possible to attach listeners to the OL map directly. There would be no need of bubbling up all events from the OL map, as discussed in #443. #911 could also be handled more easily from the client (while still being a possible candidate for inclusion in the eox-map).

santilland commented 5 months ago

I remembered seeing an event you can react to called 'loadend'. (https://eox-a.github.io/EOxElements/?path=/docs/elements-eox-map--docs#api at the end) Not sure if this is not working as expected or it is not triggering at the correct time? Or maybe something else all together? This should cover this issue in principle, right?

StefanBrand commented 5 months ago

My understanding is that loadend bubbles up the OL loadend event. For the use-cases of #443 and #911, this is not what we want. We would like to attach listeners for the moveend (#443) and loadstart (#911) events. However, it is not transparent at which point in time the .map property of the eox-map element references the OL map instance.

@viktoraronfarkas has proposed a mapmounted event or similarly named (mapinitialized, etc.), which would be fired when the LIT element is mounted.

RobertOrthofer commented 5 months ago

The map is mounted inside Lits firstUpdated-Hook (https://lit.dev/docs/v1/components/lifecycle/#firstupdated), this is also were we set the target of the map. I'm no Lit expert, but if we cannot listen to this natively we can emit the mapmounted-event there