I was looking for a way to re-initalise a map, for example: the map is already rendered with the shortcode in a popup, and needs to be shown when the popup is active.
map.invalidateSize() with a timeout does the trick, is this the way to go?
export const Maps = () => {
return {
active: true,
init() {},
setActive() {
this.active = !this.active;
if (window.WPLeafletMapPlugin) {
// window.WPLeafletMapPlugin.init();
const mapsFound = window.WPLeafletMapPlugin.maps;
for (var i = 0, len = mapsFound.length; i < len; i++) {
var map = mapsFound[i];
setTimeout(function () {
map.invalidateSize();
}, 600);
}
}
},
};
};
// export all blocks
export default { Maps };
I was looking for a way to re-initalise a map, for example: the map is already rendered with the shortcode in a popup, and needs to be shown when the popup is active.
map.invalidateSize() with a timeout does the trick, is this the way to go?