javascript - 必应地图 - 无法在 clusteredPinCallback 中设置和访问图钉属性
问题描述
我在客户端的 Bing 地图有问题。
- 我的地图上的标记代表一座建筑物,里面有公寓的数量。我正在使用自定义图钉实现 - SVG 图像 + 文本(公寓数量)。引脚正在正确渲染。
- 我需要提供自定义集群解决方案。我需要显示集群网格内所有公寓的总和,而不是显示带有内部标记数量的集群图标。
- 我发现有一个称为 map 的方法
clusteredPinCallback
,它可以访问数组,其中包含每个单个cluster grid
. - 我正在尝试提供公寓的数量作为图钉选项参数,例如
text
,title
等等,但没有一个是正确设置的。
const extendedPins = pins.map((pinItem, index) => {
const options = {
icon: 'https://www.bingmapsportal.com/Content/images/poi_custom.png',
title: 123,
text: 123
};
return new Microsoft.Maps.Pushpin(pin, options);
});
clusterLayer = new Microsoft.Maps.ClusterLayer(extendedPins, {
clusteredPinCallback: createCustomClusteredPin,
gridSize: 80
});
map.layers.insert(clusterLayer);
});
const createCustomClusteredPin = (cluster) => {
console.warn(cluster)
}
解决方案
似乎有两个问题:
图钉的文本和标题需要是字符串,而您传递的是数字。
在
clusteredPinCallback
中,集群的图钉已经创建,因此您可以通过setOptions
调用对其进行自定义。
尝试在您的示例中替换相同的函数:
function createCustomClusteredPin(cluster) {
cluster.setOptions({
icon: 'https://www.bingmapsportal.com/Content/images/poi_custom.png',
title: "123",
text: "123"
});
}
推荐阅读
- android - 如何将 ArrayList 添加到 SQLite 数据库中?
- vulkan - 在 Vulkan 中取消映射后,我可以刷新设备内存吗?
- c# - .Net Core、c# 和 Fitnesse Fit 固定装置
- java - 删除应用程序时未调用 onReceive 方法,并且我以正确的方式编写代码
- javascript - 类如何在带有引导程序的菜单上激活?
- java - 创建或复制动态数量的 Shape3DObjects
- vb.net - 将 DataGrid 中一行的颜色更改为红色
- amazon-web-services - 由于以下原因之一,远程桌面无法在亚马逊 Web 服务 Windows 实例上连接到远程计算机
- python - 如何在python中向用户显示模块和子类的文档
- mysql - Sequelize多表OR语句未知列错误