here-api - 集群标记上的过滤器 [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')的特定集群标记并控制他的可见性。
谢谢你的帮助
解决方案
当您创建 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)。
推荐阅读
- amazon-ec2 - 在 Amazon Linux EC2 中安装 minikube kubernates 时出错
- python - 在 lpthw ex42 中没有获得 self.start_scene
- android - 如何修复使用 AMAP SDK 的不合规 Android 应用
- jquery - 使用 jQuery 隐藏 Div 并滚动到锚点
- python - 如何使用python连接文件夹中的所有音频(.wav)文件?
- go - 如何从 http.Request 的响应中读取文件内容
- google-chrome-extension - 如何在 Chrome.i18n 消息字符串中添加换行符
- javascript - 如何在 htmlstring 中传递 javascript 数组的值以更改 innerHTML
- javascript - React hook:父函数如何访问子函数的状态:如果单击按钮,父应用程序会读取子函数的状态
- powershell - 为什么这个 powershell 代码片段不起作用?