集群标记过滤器 [HERE maps JS API]

Filters on clustered Marker [HERE maps JS API]

我用 getClusterPresentationgetNoisePresentation 创建了一个包含许多集群标记的地图。

我的数据是这样设置的:

{
 address: "Store 1 address",
 brands:["BRAND1", "BRAND4"],
 lat: "40.82346",
 lng: "5.2345",
 name: "Store 1 Name"
}, 
{
 address: "Store 2 address",
 brands:["BRAND2", "BRAND4"],
 lat: "40.82346",
 lng: "5.2345",
 name: "Store 2 Name"
}, 

我需要按品牌创建过滤器以显示/隐藏我的标记。我不知道该怎么做。如何访问具有特定品牌(例如:'BRAND2')的特定集群标记并控制其可见性。

感谢您的帮助

当您创建新的 H.clustering.DataPoint 时,您可以指定可选参数 opt_data,它将与给定的 DataPoint 相关联。有关 DataPoint 的更多信息,请参阅:DataPoint class apireference。 然后 getNoisePresentation 回调中的 noisePoint 将包含此数据,您可以通过调用 getData() 方法访问它。

// assume data is stored in "data" array, create new DataPoints array:
data.forEach(function(obj) {
  points.push(new H.clustering.DataPoint(obj.lat, obj.lng, undefined, obj));
})
.
.
.
// now we can work with this data in getNoisePresentation callback:
getNoisePresentation: function(noisePoint) {
  let data = noisePoint.getData(),
      visibility = data['brands'].includes('BRAND2');
  return new H.map.Marker(noisePoint.getPosition(), {
    min: noisePoint.getMinZoom(),
    visibility  
  });
}

在这里您可以找到关于 jsfiddle 的完整工作示例,如果放大地图,它会隐藏一个噪声点(商店 1)。