2016-09-06 46 views
1

如何使用loadGeojson函數Gmaps攔截加載GeoJSON?我揹着MULTILINESTRING的gejson但需要幾秒鐘的時間出現在屏幕上,我需要添加加載用戶等待充電在使用Gmaps加載GeoJSON時顯示加載狀態

function load(){ 
    google.maps.event.addListener(myLayer, 'addfeature', function (e) { 
    map.setCenter(e.feature.getGeometry().getAt(0).getAt(0)); 
    });  

    myLayer.loadGeoJson("/data/myLayer.json"); 
    myLayer.setMap(map); 

    myLayer.setStyle(function(feature) { 
    return { 
     strokeColor: "#B00000", 
     strokeOpacity:0.8, 
     strokeWeight: 4 
    }; 
    }); 
} 

伊萬你的答案是解決我的問題。謝謝!但還是有一個疑問,只有當我創建一個新的地圖對象的工作:

...... 
    var map = new google.maps.Map(document.getElementById('map'), mapOptions); 
    cicloviasLayer.setMap(map); 

我不希望創建一個新的地圖,劇情在現有的地圖,我如何才能在這種情況下,加載運行?

回答

0

this SO answer描述:

使用CSS添加裝載giff圖像:

#map_canvas {background: transparent url(images/ajax-loading.gif) no-repeat center center;} 

一次地圖被加載,如圖jsfiddle它將dissappear。

+0

Ivan我需要更多的信息sbore加載一個地圖對象存在,我編輯我的問題 – csf

1

如果你看看the API reference,你會發現loadGeoJson有一個回調函數作爲第三個參數。因此,您可以在調用loadGeoJson之前顯示一個微調器,並在調用回調後立即隱藏它。