[英]How to set a Custom Icon on clustered Push Pins in Bing Maps?
What I'm trying to do is to change the default icon that is displayed when you set the Clustering Configuration for a Bing Map using the Bing Maps Ajax Control 6.3. 我要做的是更改使用Bing Maps Ajax Control 6.3为Bing Map设置“群集配置”时显示的默认图标。
I have a function that loads a Bing Map like this: 我有一个加载像这样的Bing地图的函数:
function getMap() {
map = new VEMap('map_canvas');
map.SetDashboardSize(VEDashboardSize.Tiny);
var latLong = new VELatLong(21.983801, -101.557617);
map.LoadMap();
var customPin = '<div style="position:relative; left:-10px;top:-20px;"><img src="../Content/images/icons/pin1.png" style="width:40px; height:40px"></div>';
icon.CustomHTML = custom;
var options = new VEClusteringOptions(icon, null);
map.GetShapeLayerByIndex(0).SetClusteringConfiguration(VEClusteringType.Grid, options);
map.SetCenterAndZoom(latLong, 6);
map.SetMouseWheelZoomToCenter(false);
map.EnableShapeDisplayThreshold(true);
map.AttachEvent("onclick", singleMouseHandler);
map.AttachEvent("ondoubleclick", doubleClickMouseHandler);
}
But so far it keeps displaying the same default icon. 但是到目前为止,它一直显示相同的默认图标。 What am I missing here? 我在这里想念什么?
Another thing I was wondering is if there's a way to change the custom icon if a pin in the cluster changes, like if I have 5 green Push Pins but one of them is updated to be a blue Push Pin, is there a way to change the icon that represents that cluster? 我想知道的另一件事是,如果集群中的图钉发生变化,是否可以更改自定义图标,例如如果我有5个绿色图钉,但其中一个已更新为蓝色图钉,是否可以更改代表该集群的图标?
I did the development long time ago for our company site. 我很久以前就为我们公司的网站进行开发。 Did you try the interactive SDK available here? 您尝试过这里提供的交互式SDK吗? http://www.bingmapsportal.com/isdk/ajaxv7#Pushpins15 http://www.bingmapsportal.com/isdk/ajaxv7#Pushpins15
I have added the reference for pushpin development 我添加了图钉开发的参考
http://www.microsoft.com/maps/developers/web.aspx http://www.microsoft.com/maps/developers/web.aspx
I found the reason my approach wasn't working, I keep thinking I'm dealing with classes with constructors that receive parameters, which in this case the VEClusteringOptions class doesn't receive parameters in its constructor. 我发现了我的方法无法使用的原因,我一直认为我正在处理带有接收参数的构造函数的类,在这种情况下,VEClusteringOptions类在其构造函数中不接收参数。 I had to set the Icon property separately: 我必须单独设置Icon属性:
function getMap() {
map = new VEMap('map_canvas');
map.SetDashboardSize(VEDashboardSize.Tiny);
var latLong = new VELatLong(21.983801, -101.557617);
map.LoadMap();
var customPin = '<div style="position:relative; left:-10px;top:-20px;"><img src="../Content/images/icons/pin1.png" style="width:40px; height:40px"></div>';
icon.CustomHTML = custom;
var options = new VEClusteringOptions();
options.Icon = icon; // here's the "big" difference
map.GetShapeLayerByIndex(0).SetClusteringConfiguration(VEClusteringType.Grid, options);
map.SetCenterAndZoom(latLong, 6);
map.SetMouseWheelZoomToCenter(false);
map.EnableShapeDisplayThreshold(true);
map.AttachEvent("onclick", singleMouseHandler);
map.AttachEvent("ondoubleclick", doubleClickMouseHandler);
}
Now my custom cluster icons are being loaded great, I need to get used to more to the concept of property in the future. 现在,我的自定义群集图标正在被很好地加载,将来我需要习惯更多有关属性的概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.