Skip to content

Commit

Permalink
Fix JS Dataviz: When dataviz is not available
Browse files Browse the repository at this point in the history
In embed mode the error is generated because the dataviz elements are not available.
```
TypeError: elem is null
    isInViewport dataviz.js:23
    getPlots dataviz.js:146
    uicreated dataviz.js:774
    triggerEvent OpenLayers.js:246
    init map.js:5034
map.js:5039:28
    init map.js:5039
```
  • Loading branch information
rldhont committed Jul 11, 2024
1 parent e2bb302 commit 27805de
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lizmap/www/assets/js/dataviz/dataviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ let lizDataviz = function () {
// initialize plot info
dv.plots[i] = { 'json': null, 'filter': null, 'show_plot': true, 'cache': null, 'data_fetched': false };
if (!(optionToBoolean(dv.config.layers[i]['only_show_child']))) {
let plotContainerId = `dataviz_plot_${i}`;

// Add plot container
addPlotContainer(i);
}
Expand All @@ -143,6 +141,10 @@ let lizDataviz = function () {
if (!(optionToBoolean(dv.config.layers[i]['only_show_child']))) {
// Get the plot data and display it if the container is visible
let elem = document.getElementById(plotContainerId);
// skip the element if it does not exist
if (elem === null) {
continue;
}
if (isInViewport(elem) || getViewPercentage(elem) > 0) {
getPlot(i, null, plotContainerId);
}
Expand Down

0 comments on commit 27805de

Please sign in to comment.