簡體   English   中英

更新圖表元素后刷新openlayers地圖

[英]Refresh openlayers map after updating chart element

更新地圖上顯示的地圖文件中的餅圖大小(單擊按鈕時)后,我需要刷新openlayers地圖。 我無法刷新整個頁面,否則會丟失數據。 當我更改縮放級別時,它可以工作。 我已經嘗試了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();
    });
});

您可以嘗試在重之前調用“ clearGrid()”函數。

“ clearGrid()”Layer.Grid的功能( Layer.MapServer繼承自Layer.Grid )。 它將破壞圖層的每個圖塊。

只需指出“ clearGrid()”不是APIMethod,因此不應以這種方式調用它。

國內也有類似的問題/答案在這里

嘗試這個。 它為我工作。

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

此代碼再次設置屏幕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM