0
要在我的地圖中創建多邊形,我正在使用jQuery.getJSON()
來加載包含多邊形和多面體的geojson文件。然後我用github插件(loadgeojson)分析geojson,最後在地圖上創建多邊形。創建和顯示多邊形之間的延遲
我把一個<div>
與一個加載gif疊加在jQuery.getJSON()
被調用之前出現的地圖。
問題是要刪除它的時機。當所有的多邊形可見屬性設置爲真我使加載動畫消失。
我希望<div>
在多邊形出現在地圖上時消失。但目前來看,它在這之前就消失了一些。所以在較慢的瀏覽器中,消失和出現多邊形之間存在相對較大的延遲。
我試圖把一個監聽器放在一個事件上,但是我找不到與我想要的相對應的事件。
如何在地圖上顯示多邊形時及時刪除加載動畫?
這裏是我的代碼:
function readJSON(id){
showLoadingAnimation();
// If .json hasn't been read
if(stockArray[id].length == 0) {
$.getJSON(id + ".json", function(data){
showFeature(data, id)
})
}
}
function showFeature(geojson, elemtype){
currentFeature_or_Features = new GeoJSON(geojson, elemtype, options);
if (currentFeature_or_Features.type && currentFeature_or_Features.type == "Error"){
return;
}
// Display object
if (currentFeature_or_Features.length){
for (var i = 0; i < currentFeature_or_Features.length; i++){
if(currentFeature_or_Features[i].length){
for(var j = 0; j < currentFeature_or_Features[i].length; j++){
// Display multipolygon
currentFeature_or_Features[i][j].setMap(map);
// Mouse events for multipolygons
mouseEventsMulti(i,j,elemtype);
}
}
else{
// Display polygons, polylines and points
currentFeature_or_Features[i].setMap(map);
// Mouse events for polygons, polylines and points
mouseEventsSimple(i,elemtype)
}
}
} else {
currentFeature_or_Features.setMap(map)
}
// Stop loading animation
dontShowLoadingAnimation();
}
什麼是你的代碼是什麼樣子?您可以嘗試使用空閒事件來檢測多邊形何時完成渲染。 – geocodezip
我已更新我的問題以包含代碼。我已經嘗試了閒置事件。當地圖加載完成後,會調用空閒事件。但是當我加載多邊形時,加載屏幕不會消失(該事件不會被調用)。 – Rethi