0

I stumbled across this ESRI post about Conditional Field display with Arcade in Pop Ups. I am not well versed in HTML, but I could follow along well enough to understand the post.

However, how would I implement this in QGIS, specifically through the QGIS2WEB plugin?

I am examining the html output of the QGIS2WEB plugin (for both Open Layers and Leaflet), and an obvious intervention point is not jumping out at me.

Popups can sometimes have empty fields when there is no data, and I would like to hide these fields when there is no data!

5

If qgis2web has inline labels or header labels specified for popup fields then the resulting web map will display a the field label and a blank space for the null value. To fix this you will have to edit the qgis2web.js file

This is for an OpenLayers based web map. Starting near line 311 (your line may be different) change the entire if statement to look like the following:

if (layer.get('fieldImages')[currentFeatureKeys[i]] != "Photo") {
    if (currentFeature.get(currentFeatureKeys[i]) == null) {
        popupField = '';
    } else {
        popupField += (currentFeature.get(currentFeatureKeys[i]) != null ? 
               Autolinker.link(String(currentFeature.get(currentFeatureKeys[i]))) + '</td>' : '');
    }
} else {
    popupField += (currentFeature.get(currentFeatureKeys[i]) != null ? '<img src="images/' + currentFeature.get(currentFeatureKeys[i]).replace(/[\\\/:]/g, '_').trim()  + '" /></td>' : '');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.