2

I am trying to build a table in javascript from getfeatureinfo. I do this by this code:

function showInfo(evt) {
        var f = 0;
        var temstr = "";
        if(evt.features.length != 0){
            for (f = 0; f <= evt.features.length - 1; f++) {
                if(evt.features[f].gml.featureType == "amice_om_herk"){
                    temstr = temstr + "<b>" + "<center>Herkomstlocatie</center>" + "</b>";
                    temstr = temstr + "<table>";
                    temstr += "<tr>";
                    temstr = temstr += "<th>ID</th>" +  "<th>Houseletter</th>" +"<th>City</th>" +"<tr>";
                    for ( var key in evt.features[f].attributes) {
                        switch (key){
                        case 'afvlstrnum':
                            temstr += "<td>" 
                            + evt.features[f].attributes[key] + "</td>";
                            break;
                        case 'numtv_herk':
                            if (evt.features[f].attributes[key] != null){
                            temstr += "<td>"
                            + evt.features[f].attributes[key] + "</td>";
                            break;
                            }
                            else {
                                temstr += "<td></td>";
                                break;
                            }
                        case 'plts_herk':
                            if (evt.features[f].attributes[key] !== ""){
                            temstr += "<td>"
                            + evt.features[f].attributes[key] + "</td>";
                            break;
                            }

However, some attributes contain no value. In that case, the getfeatureinfo doesnt recognize the attribute name. So, when i build my table with and one of the cases for that particular cell is without a value, it skips the case, moves on to the next one and fills the cell with attribute value which should be in the next column. An image of what goes wrong:

enter image description here

Is there a possibility fill <td> with something like 'nodata' or fill it with nothing? I tried to make an if statement (as seen in the code), but since it never comes into the case when, for that cell, the attribute name doesnt exist, this wont work.

Your Answer

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

Browse other questions tagged or ask your own question.