首页 > 解决方案 > 集群标记上的过滤器 [HERE maps JS API]

问题描述

getClusterPresentation我用和创建了一个带有许多聚集标记的地图getNoisePresentation

我的数据是这样设置的:

{
 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')的特定集群标记并控制他的可见性。

谢谢你的帮助

标签: here-api

解决方案


当您创建 new时,您可以指定将与给定 DataPoint 关联的H.clustering.DataPoint可选参数opt_data 。有关 DataPoint 的更多信息,请参阅:DataPoint 类 apireference。然后回调中的noisePointgetNoisePresentation将包含此数据,您可以通过调用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)。


推荐阅读