2015-05-13 43 views
0

我需要在更新地圖上顯示的地圖文件中的餅圖大小(在按鈕單擊上)後刷新一個拓撲圖地圖。我無法刷新整個頁面或丟失數據。它在我改變縮放級別時起作用。我試過map.updateSize()(沒有效果),map.render()(TypeError「a」沒有定義),layer.redraw()。我不知道我是否缺少某些與openlayers相關的東西,或者如果這是我的javascript問題。我瀏覽了一些帖子,但似乎無法得到我的案例中的任何答案。更新圖表元素後刷新拓撲圖地圖

$(document).ready(function() { 
    map = new OpenLayers.Map('map' , 
    { maxExtent: new OpenLayers.Bounds({{bounds.0}}, {{bounds.1}}, {{bounds.2}}, {{bounds.3}}), 
    controls:[new OpenLayers.Control.Navigation(), 
       new OpenLayers.Control.LayerSwitcher(), 
       new OpenLayers.Control.PanZoomBar()], 
    numZoomLevels:20 
    } 
    ); 
    var mpLayer = new OpenLayers.Layer.MapServer('Zones Layer', '{{ mapserverpath }}', { 
       map:'{{mapFile}}', 
       layers:'all', 
       isBaseLayer: 'true' 
       },{ 
        singleTile: 'true' 
//     ratio: 2.0 
       } 
      ); 

    map.addLayers([mpLayer]); 
    //map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); 
    map.zoomToMaxExtent(); 

    map.events.register("click", map, qryDB); 

    $(document).on('click', '#bttnMinus', function(){ 
     pieFact*=0.5; 
     updatePieFact(); 
     mpLayer.redraw(); 
    }); 
    $(document).on('click', '#bttnPlus', function(){ 
     pieFact*=1.5; 
     updatePieFact(); 
     mpLayer.redraw(); 
    }); 
    $(document).on('click', '#bttnReset', function(){ 
     pieFact=1.0; 
     updatePieFact(); 
     mpLayer.redraw(); 
    }); 
}); 

回答

0

您可以嘗試在重新繪製之前調用"clearGrid()"函數。

「clearGrid()」函數Layer.GridLayer.MapServer繼承Layer.Grid)。它會破壞每個圖層的瓦片。

只是說「clearGrid()」不是APIMethod,所以它不應該以這種方式調用。

還有一個相似的問題/回答here

0

試試這個。它爲我工作。

$(window).trigger('resize');

此代碼再次設置屏幕。