0

Google マップ プロジェクトでは、すべてのマーカーを配列に読み込んでいるので、すべてのマーカーをマップに配置した後で MarkerClusterer に使用できます。すべてのマーカーが表示されていますが、MarkerClusterer はクラスター化されていません。デバッグ後、配列が空であることがわかりましたが、その理由がわかりません。

var matLocation = null; 
var markers = [];

//setup the makers
function loadMarkers()
{
    //load array with markers
    startLoadingMarkers();

    //add markercluster to page so we markers will get clustered
    var markerCluster = new MarkerClusterer(map, markers);
    markerCluster.maxZoom_ = 14;        

    //More stuff
}


/*
* Load the markers from the source
*/
function startLoadingMarkers()
{
    //empty markers
    for(i in markers)
    {
        var marker = markers[i];
        marker.setMap(null);
    }
    markers = [];

    $.get( 'load some marker source', function(data) { 
        matLocation = jQuery.parseJSON(data);
        LoadMarker(1);
    });
}


/*
* Load the marker one by one
*/
function LoadMarker(nextIndex)
{
    if(nextIndex < matLocation.locations.length){
       var arrItem = matLocation.locations[nextIndex];

       //Put the marker on the map (all working fine)

       //add to array
       markers.push(marker);

       //go to next
       LoadMarker((nextIndex + 1));
    }
    //ARRAY IS STILL FILLED HERE
}

配列は の反復ごとに入力され、すべての反復の最後にコンテンツが含まれます。しかし、MarkerClusterer を起動したい場合、マーカー配列は空で、内容がありません。

ここで何が起こっているか知っている人はいますか?

4

1 に答える 1

0

loadMarkersあなたが電話すると、これstartLoadingMarkersは次のことを行います:

markers = [];

assする前にグローバルマーカーを空にしているようですMarkerClusterer(map, markers)

于 2013-10-09T07:55:08.160 に答える