我正在尝试在地图上显示自定义标记。标记是使用API获得的每条记录动态创建的。图像托管在其他地方。但是,每当我尝试使用不显示的标记拉起地图时,只显示默认标记。我想知道我是否对标记设置有问题:
var dynamicIcon = [];
var dIcon = [];
var weatherMarker = [];
$.getJSON('http://api.openweathermap.org/data/2.5/box/city?bbox=1.89,49.05,2.86,48.63,10&cluster=yes', function(data)
{
var i=0;
while(i < data.list.length-1)
{
dynamicIcon[i] = L.Icon.Default.extend({
options:{
iconURL:'http://openweathermap.org/img/w/'+data.list[i].weather[0].icon+'.png',
}
});
dIcon[i] = new dynamicIcon[i]();
weatherMarker[i] = new L.marker([data.list[i].coord.lat, data.list[i].coord.lon], {icon: dIcon[i]}, {draggable:false});
map.addLayer(weatherMarker[i]);
}
});
答案 0 :(得分:1)
显然我做错了;像这样工作:
dynamicIcon[i] = new L.Icon({
iconUrl:'http://openweathermap.org/img/w/'+data.list[i].weather[0].icon+'.png',
});
weatherMarker[i] = new L.marker([data.list[i].coord.lat, data.list[i].coord.lon], {
icon:dynamicIcon[i] });
map.addLayer(weatherMarker[i]);