I'm getting my data like this:
$.ajax({
url: 'php/get_all_attri.php',
type: 'GET',
dataType: 'JSON',
data: {
col_name: firstSel
},
success: function(data) {
var total_statement = {};
$.each(data, function(i, data) {
console.log(data.attri_1);
});
}
});
In the console, this returns the possible values for my query such as 18 19 20 21, etc.
They can also be strings like TRUE FALSE.
What I need is for these values to create statements that are used to build a map using cartoDB/leaflet. Here's the function:
function goMap3() {
var layerSource = {
user_name: 'me',
type: 'cartodb',
sublayers: [{
sql: "SELECT cartodb_id, the_geom_webmercator FROM mytable where attribute='" + attr_value + "'",
cartocss: "#location_fusion_table {marker-fill:#1d5492;marker-width:5;marker-line-width: 0.3;marker-line-color:#fff;marker-allow-overlap: true;"}
}, ]
};
cartodb.createLayer(map_object, layerSource, options)
.addTo(map_object);
}
What I need to happen is for this entire part to be written as many times as there are different values returned by my AJAX.
{
sql: "SELECT cartodb_id, the_geom_webmercator FROM mytable where attribute='" + attr_value + "'",
cartocss: "#location_fusion_table {marker-fill:#1d5492;marker-width:5;marker-line-width: 0.3;marker-line-color:#fff;marker-allow-overlap: true;"}
},
In this case, attr_value
is what needs to be replaced each time with the values from AJAX. This would allow my entire function to look something like this:
function goMap3() {
var layerSource = {
user_name: 'me',
type: 'cartodb',
sublayers: [{
sql: "SELECT cartodb_id, the_geom_webmercator FROM mytable where attribute='17'",
cartocss: "#location_fusion_table {marker-fill:#1d5492;marker-width:5;marker-line-width: 0.3;marker-line-color:#fff;marker-allow-overlap: true;"}
},
{
sql: "SELECT cartodb_id, the_geom_webmercator FROM mytable where attribute='18'",
cartocss: "#location_fusion_table {marker-fill:#1d5492;marker-width:5;marker-line-width: 0.3;marker-line-color:#fff;marker-allow-overlap: true;"}
},
{
sql: "SELECT cartodb_id, the_geom_webmercator FROM mytable where attribute='19'",
cartocss: "#location_fusion_table {marker-fill:#1d5492;marker-width:5;marker-line-width: 0.3;marker-line-color:#fff;marker-allow-overlap: true;"}
},]
};
cartodb.createLayer(map_object, layerSource, options)
.addTo(map_object);
}
In summary: I'm trying to figure out how I end up with that last function that I have in my question. I need to make a number of those "sublayers" to match the number of values returned from my AJAX and those values filled in the correct area in the sublayer statements.