fixup: allow aynchronous popups

This commit is contained in:
Yohan Boniface 2024-12-12 15:30:06 +01:00
parent 7670989798
commit 8a929d2352

View file

@ -21,23 +21,23 @@ export default function loadPopup(name) {
const Popup = BasePopup.extend({ const Popup = BasePopup.extend({
initialize: function (feature) { initialize: function (feature) {
this.feature = feature this.feature = feature
this.container = DomUtil.create('div', 'umap-popup') BasePopup.prototype.initialize.call(this, {}, feature.ui)
this.format() this.getContentFromTemplate()
BasePopup.prototype.initialize.call(this, {}, feature)
this.setContent(this.container)
}, },
format: async function () { getContentFromTemplate: async function () {
const container = DomUtil.create('div', 'umap-popup')
const name = this.feature.getOption('popupTemplate') const name = this.feature.getOption('popupTemplate')
this.content = await loadTemplate(name, this.feature, this.container) this.content = await loadTemplate(name, this.feature, container)
const elements = this.container.querySelectorAll('img,iframe') const elements = container.querySelectorAll('img,iframe')
for (const element of elements) { for (const element of elements) {
this.onElementLoaded(element) this.onElementLoaded(element)
} }
if (!elements.length && this.container.textContent.replace('\n', '') === '') { if (!elements.length && container.textContent.replace('\n', '') === '') {
this.container.innerHTML = '' container.innerHTML = ''
DomUtil.add('h3', '', this.container, this.feature.getDisplayName()) DomUtil.add('h3', '', container, this.feature.getDisplayName())
} }
this.setContent(container)
}, },
onElementLoaded: function (el) { onElementLoaded: function (el) {