我使用P5.JS库创建一个应用程序,该库显示每个国家的当前天气颜色的dinamic地图,这是我到目前为止:
var colors = [];
var paises = ["AR", "BR", "CL", "CO", "GY", "PE", "PY", "UY", "BO", "VE", "EC", "GF", "SR"];
var datacoor;
var url1 = "https://chart.googleapis.com/chart?";
var arg1 = "cht=map&chs=600x500&chld="
var arg2 = "&chco=";
//var URL = url1+arguments;
var img;
function setup () {
createCanvas(500, 600);
img = createImg("https://chart.googleapis.com/chart?cht=map&chs=600x500&chld=AR|BR|CL|CO|GY|PE|PY|UY|BO|VE|EC|GF|SR&chco=B3BCC0|5781AE");
img.hide();
for (var a = 0; a < paises.length; a++){
colors.append(colors, color(getColor(paises[a])));
}
}
function draw () {
background(255);
noStroke();
fill(30);
textSize(35);
//text("zz ", 15, 45);
if (img) {
imageMode(CENTER);
image(img, width/2, height/2);
}
}
function onData (response) {
datacoor = response;
console.log(datacoor);
}
function getColor (loc) {
var pais = loc;
var lat;
var long;
if (data1.hasOwnProperty(pais)) {
lat = data1.pais.lat;
console.log(lat);
}
}
这是问题所在:
function getColor (loc) {
var pais = loc;
var lat;
var long;
//data1 is a variable with the list of all countries and their coordinates
if (data1.hasOwnProperty(pais)) {
lat = data1.pais.lat;
console.log(lat);
}
}
它寻找对象“pais”而不是变量“pais”中的对象,我该如何解决这个问题?任何帮助表示赞赏
答案 0 :(得分:1)