2014-11-17 30 views
1

我試圖在地圖上顯示自定義標記。標記是通過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]); 
      } 
     }); 

回答

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]);