2013-07-22 37 views
0

嗨我使用JQVMap在國家的工具提示中顯示一些值。當該值不是0時,該國爲綠色。但我有一些問題。要啓動該功能,我使用以下代碼。我通過div得到的數據。所有作品都很好。如果我進行選擇(使用日期選擇器),數據將在地圖上的工具提示中更新。所以正確的值被賦予地圖。但是如果我改變爲另一個例如值爲0的日子,那麼地圖仍然是彩色的,因爲值大於0.因此,不是新的 - >舊的地圖。例如,如果我創建一個manuell站點(使用F5),它將顯示具有正確值的正確映射。更新JQVMap - 帶有新值的地圖(顏色變化)

我能做些什麼才能使它工作?

代碼初始:

initJQVMAP: function() { 

    var showMap = function (name) { 
     jQuery('.vmaps').hide(); 
     jQuery('#vmap_' + name).show(); 
    } 

    var setMap = function (name) { 
     var data = { 
      map: 'world_en', 
      backgroundColor: null, 
      borderColor: '#333333', 
      borderOpacity: 0.5, 
      borderWidth: 1, 
      color: '#c6c6c6', 
      enableZoom: true, 
      hoverColor: '#244671', 
      hoverOpacity: null, 
      values: sample_data, 
      normalizeFunction: 'linear', 
      scaleColors: ['#cfe9d3', '#3cc051'], 
      selectedColor: '#244671', 
      selectedRegion: null, 
      showTooltip: true, 
      onLabelShow: function (event, label, code) { 

      } 
     }; 

     data.map = name + '_en'; 
     var map = jQuery('#vmap_' + name); 
     if (!map) { 
      return; 
     } 
     map.width(map.parent().parent().width()); 
     map.show(); 
     map.vectorMap(data); 
     map.hide(); 
    } 

    setMap("world"); 
    setMap("europe"); 
    setMap("germany"); 
    showMap("world"); 


    jQuery('#regional_stat_world').click(function() { 
     showMap("world"); 
    }); 

    jQuery('#regional_stat_usa').click(function() { 
     showMap("usa"); 
    }); 

    jQuery('#regional_stat_europe').click(function() { 
     showMap("europe"); 
    }); 
    jQuery('#regional_stat_russia').click(function() { 
     showMap("russia"); 
    }); 
    jQuery('#regional_stat_germany').click(function() { 
     showMap("germany"); 
    }); 

    $('#region_statistics_loading').hide(); 
    $('#region_statistics_content').show(); 
}, 

的代碼來更新值:

$('#div_session_write').load('sessionstart.php?datum1=' + Date.today().add({ 
     days: -29 
    }).toString('yyyy-MM-dd') +'&datum2=' + Date.today().toString('yyyy-MM-dd')); 
    $('#geodaten').load('geodata.php'); 

我想我必須重新繪製或重新加載它...但如何?

+0

沒有人知道嗎? – TrivoXx

回答

0

我認爲你不應該使用加載函數。如果你在async中使用ajax,false可以正常工作。

onLabelShow: function(event, label, code) { 
    myUrl="data/13historical_"+v_mapa+".php"; 
    $.ajax({ 
     url: myUrl, 
     dataType: 'json', 
     async: false, 
     success: function(data) { 
      $.each(data.votacionData.votaciones.details[0].detail, function(i) { 
       if (this[0]==code) { 
        code.replace(/ /g, '_'); 
        theTable='<table cellpadding=2 border=0 class="hoverTable">'; 
        theTable += "<tr><td><h1 style='color: white'>"+this[1]+"</h1></td></tr>"; 
        theTable += "<tr><td>Ganador</td><td>"+this[2]+"</td></tr>"; 
        theTable += "<tr><td>Votos</td><td>"+this[3]+"</td></tr>"; 
        theTable += "<tr><td>Segundo</td><td>"+this[8]+"</td></tr>"; 
        theTable += "<tr><td>Votos</td><td>"+this[9]+"</td></tr>"; 
        theTable += "</table>"; 
       } 
      }); 
     } 
    }); 
    label[0].innerHTML = v_mapa + " \n " + theTable; 
}