从 google 个地图中删除标记簇 [不仅仅是标记]

Delete marker clusters from google maps [not just the markers]

在我的 phonegapp/cordova 应用程序中,我使用 google 地图工具,有时我需要更改上面显示的点。 我找到了一些有用的代码 here 来从我使用的 google 地图中删除我的标记。

我的问题我也使用标记簇,但我这里有一个奇怪的问题。

对于我的地图,我使用这些设置:

{
    showControls: true,
    key: { google: "XXXXXX" },
    center: center,
    width: "100%",
    height: "95%",
    zoom: zoom,
    provider: "google",
    mapType: "satellite",
    autoAdjust: false,
    onReady: SetMap
}

其中 SetMap 和其他调用的函数是:

var mmm = null;
var markerCluster = null;

// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
    setMapOnAll(null);
}

// Sets the map on all markers in the array.
function setMapOnAll(map) {
    for (var i = 0; i < markerCluster.markers_.length; i++) {
        markerCluster.markers_[i].setMap(map);
    }
}

function SetMap (s) {

    if (mmm == null)
        mmm = s.originalMap;
    else {
        clearMarkers();
        markerCluster.markers_ = [];
    }
    var map = mmm;
    var markers = [];
    for (var i = 0; i < pointsOnMapList.length; i++) {
        var data = pointsOnMapList[i];
        var latLng = new google.maps.LatLng(data.location[0], data.location[1]);
        var marker = createMarker(latLng, data.title, map, data.idimp);
        markers.push(marker);
    }
    markerCluster = new MarkerClusterer(map, markers, { imagePath: 'images/m' });
}

更新数据集时,只需调用 SetMap 函数即可。

这 "almost" 有效。我的目标是在用户过滤后更改地图中的点。我从我的 api 获得了一个新数据集,我必须擦除地图并用我的新点再次填充它。

示例:假设我有这张地图:

然后,我过滤我的地图点,我在同一张地图上得到新旧点:

然后,就像魔术一样,如果我只是改变地图缩放比例,旧点就会消失!

注意:当我过滤我的数据集时,单个标记被删除,而不改变缩放比例。此问题仅适用于标记簇。我怎样才能删除它们?

刚找到线索。 以这种方式编辑我的代码:

function SetMap (s) {
    if (mmm == null)
        mmm = s.originalMap;
    else {
        markerCluster.clearMarkers();
    }
    var map = mmm;
    var markers = [];
    for (var i = 0; i < pointsOnMapList.length; i++) {
        var data = pointsOnMapList[i];
        var latLng = new google.maps.LatLng(data.location[0], data.location[1]);
        var marker = createMarker(latLng, data.title, map, data.idimp);
        markers.push(marker);
    }
    markerCluster = new MarkerClusterer(map, markers, { imagePath: 'images/m' });
}

有效,所有标记和簇都已删除!!!