0

マップにポリゴンを作成するために、jQuery.getJSON()ポリゴンとマルチポリゴンを含む geojson ファイルを読み込んでいます。次に、github プラグイン (loadgeojson) を使用して geojson を分析し、最終的にマップ上にポリゴンを作成します。

が呼び出される<div>直前に表示されるマップをオーバーレイする読み込み中の gif を配置します。jQuery.getJSON()

問題は外すタイミングです。すべてのポリゴンの表示プロパティをTrueに設定すると、ロード アニメーションが消えます。

<div>マップ上にポリゴンが表示されたときに を消したいです。でも、とりあえず、その少し前に消えます。そのため、低速のブラウザでは<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();
}           
4

1 に答える 1

0

最後に、コードを修正して、ポリゴンの作成後にマップを少しパンします。次に、ロード アニメーションを停止するアイドル リスナーをアクティブにします。

これは最も美しいコードではないかもしれませんが、機能します。

これは私が showFeature 関数に追加したものです

center = map.getCenter();
latLngCenter = new google.maps.LatLng(center.lat() + 0.0000001,center.lng() + 0.0000001);
map.panTo(latLngCenter);

そして、これはリスナーです

google.maps.event.addListener(map, 'idle', function() {
    // Stop loading animation
    dontShowLoadingAnimation();
});
于 2013-08-28T20:34:43.167 に答える