I have an ajax link getting data from GeoServer. When a user selects features on a map, a new bounding box is calculate and sent via Ajax to GeoServer and the features within that bounding box are sent back.
I have a handleJson function for the selected features returned from GeoServer:
function handleJson(data) {
selectedFeature = L.geoJson(data, {
onEachFeature: function (feature, layer) {
for(name in feature.properties){
document.getElementById("properties").innerHTML = document.getElementById("properties").innerHTML +
"<tr><td>" + name + "<td>" + feature.properties[name] + "<td>";
}
},
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
radius: 5,
color: '#3006e8',
weight: 5,
opacity: 1,
fillOpacity: 1
});
}
});
Currently I can get all of the data back in this format (just plunked right onto the map itself):
Name: George Costanza
Occupation: Bra Salesman/Kruger Industrial Smoothing
Strengths: Lying
Weaknesses: He was in the pool.
This is fine if you only have one feature selected, but if you have multiple, it needs to be in a format closer to microsoft excel with rows and columns like this:
Name Occupation Strengths Weaknesses
person1 person1 job person1 strength person1 weakness
person2 person2 job person2 strength person2 weakness
person3 person3 job person3 strength person3 weakness
I have tried various for loops and putting things to arrays, but I cannot get get it to work. forEachFeature just keeps copying what would be the column name (the "key" in the key:value pair). I need the column names set up once and then just get the data associated (the "value" in the key:value pair). Is this possible?
UPDATE TO SHOW WHAT IT CURRENTLY DOES:
Name: Person Person
Occupation: Some Job
Strengths: Some Strength
Weaknesses: Some Weakness
Name: Other Person
Occupation: Some OTHER Job
Strengths: Some OTHER Strength
Weaknesses: Some OTHER weakness
Name: Other Person 2
Occupation: sadfsadds
Strengths: Lasdfafffd
Weaknesses: asdasfdsadf
"<tr><td>" + name + "<td>" + feature.properties[name] + "<td>"with ` "<tr><td>" + name + "</td><td>" + feature.properties[name] + "</td></tr>"` (Don't know if it will solve it...)