Right I've got this JS function
function AreaCompare(sql, UIDfield, Geogname, Table, sourceName, sourceID, destName, destID){
CompareObj = {};
CompareObj.sName = sourceName;
CompareObj.sID = sourceID;
CompareObj.dName = destName;
CompareObj.dID =destID;
sql.execute("select ST_Area(the_geom::geography)/1000000 as SA FROM "+Table+" where "+UIDfield+"="+sourceID)
.done(function(data) {
CompareObj.sArea=JSON.stringify(data.rows[0].sa);
sql.execute("select ST_Area(the_geom::geography)/1000000 as DA FROM "+Table+" where "+UIDfield+"="+destID)
.done(function(data) {
CompareObj.dArea=JSON.stringify(data.rows[0].da);
alert(JSON.stringify(CompareObj));
return CompareObj;
})
})
}
It appears to work correctly and the alert box flashes up with a readable version of the object that is as expected.
however when I examine the returned object it is undefined, essentially empty/null.
What trick am I missing a trick here? It originally thought it was something related to scope and the done
function.
I did allot of research and I realised I needed to nest the CartoDB SQL statements, but that didn't fix the problem.
Any suggestions?