此处Map JS集群标记删除选项

时间:2019-09-24 07:14:51

标签: here-api

在使用群集层显示标记的地图上,在API调用上加载重新加载数据时,我需要清除地图中的群集标记,请对此问题提供帮助,使用当前方法(map.removeObjects(map。 getObjects())正常工作,但我需要删除默认的群集标记

请找到以下代码:

 startClustering(map, data) {
    // First we need to create an array of DataPoint objects,
    // for the ClusterProvider
    // tslint:disable-next-line:ter-prefer-arrow-callback
    const dataPoints = data.map(function (item) {
      console.log('item>>>>', item);
      return new H.clustering.DataPoint(item.y, item.x);
    });

    const clusteredDataProvider = new H.clustering.Provider(dataPoints, {
      clusteringOptions: {
        // Maximum radius of the neighbourhood
        eps: 1,
        // minimum weight of points required to form a cluster
        minWeight: 2,
      },
    });

    // Create a layer tha will consume objects from our clustering provider
    const clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);
    // To make objects from clustering provder visible,
    // we need to add our layer to the map
    map.addLayer(clusteringLayer);

  }

在调用此功能之前,我需要删除此群集标记

1 个答案:

答案 0 :(得分:0)

最简单的方法是保留对要删除的群集层的引用,然后通过以下方式删除它:

给出一个名为clusteringLayer的引用:

  

map.removeLayer(clusteringLayer);

使用map.getLayers()检索所有地图图层并通过map.removerLayer(<layerRef>)删除每个图层的另一种选择可能会删除您不希望删除的图层。