我正在尝试遍历返回的 JSON 对象并根据 x 和 y 坐标绘制热图。这是我设置热图的方法:
function getHeatMap() {
heatLayer = new HeatmapLayer({
config: {
"useLocalMaximum": true,
"radius": 40,
"gradient": {
0.45: "rgb(000,000,255)",
0.55: "rgb(000,255,255)",
0.65: "rgb(000,255,000)",
0.95: "rgb(255,255,000)",
1.00: "rgb(255,000,000)"
}
},
"map": map,
"domNodeId": "heatLayer",
"opacity": 0.85
});
$.ajax({
url: "index.aspx/getBusCommuter",
type: "POST",
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var parsed = JSON.parse(data.d);
var data = [];
$.each(parsed, function (i, jsondata) {
var coordXicon = jsondata.BusStopX;
var coordYicon = jsondata.BusStopY;
data = [
{
attributes: {},
geometry: {
spatialReference: { wkid: 102100 },
type: "point",
x: coordXicon,
y: coordYicon
}
}
];
});
heatLayer.setData(data);
map.addLayer(heatLayer);
},
error: function (request, state, errors) {
}
});
}
基本上,JSON 对象只会循环到最后一组 JSON 对象并仅绘制最后一组而不是全部。我想知道我的逻辑的哪一部分是错误的。
提前致谢。