c# - 如何在我的 Bing 地图图钉上添加标签?
问题描述
我正在创建地图,在某些情况下,图钉代表事件发生的位置以及事件发生日期的重要位置。我想在图钉本身上显示按时间顺序排列的事件的顺序(用户可以通过 toollip 属性/通过悬停获得其他数据)。
例如,我想要一个如下所示的地图:
...看起来像这样:
有没有办法做到这一点?
解决方案
您可以使用以下任一选项:
- 设置图钉的内容属性
- 将 TextBlock 或 Label 添加到 MapLayer
设置图钉内容
您可以将Pushpin的Content属性设置为要在图钉上显示的文本。
例如以下代码,显示地图上图钉的 1 基索引:
private void button1_Click(object sender, EventArgs e)
{
var locations = new[] {
new Location(47.6424, -122.3219),
new Location(47.8424,-122.1747),
new Location(47.67856,-122.130994)};
for (int i = 0; i < locations.Length; i++)
{
var pushpin = new Pushpin() { Location = locations[i], Content = i + 1 };
this.userControl11.myMap.Children.Add(pushpin);
}
var thickNess = new Pushpin().Height;
this.userControl11.myMap.SetView(locations,
new Thickness(thickNess / 2, thickNess, thickNess / 2, 0), 0);
}
文本将被剪裁到气球区域,所以不要在那里使用长文本。
将 TextBlock 添加到 MapLayer
您还可以添加MapLayer,然后添加TextBlock
或Label
显示更长的文本:
private void button1_Click(object sender, EventArgs e)
{
var locations = new[] {
new Location(47.6424, -122.3219),
new Location(47.8424,-122.1747),
new Location(47.67856,-122.130994)};
var pushpinLayer = new MapLayer();
var height = new Pushpin().Height;
var width = new Pushpin().Width;
for (int i = 0; i < locations.Length; i++)
{
var pushpin = new Pushpin() { };
var txt = new System.Windows.Controls.TextBlock();
txt.Text = $"Lorem ipsum dolor sit amet {i + 1}";
txt.Background = new SolidColorBrush(Colors.White);
txt.Foreground = new SolidColorBrush(Colors.Black);
txt.Width = 100;
txt.TextWrapping = TextWrapping.WrapWithOverflow;
txt.TextAlignment = TextAlignment.Center;
txt.TextWrapping = TextWrapping.Wrap;
txt.Padding = new Thickness(2);
pushpinLayer.AddChild(pushpin, locations[i]);
pushpinLayer.AddChild(txt, locations[i],
new System.Windows.Point(-txt.Width / 2, -height));
}
this.userControl11.myMap.Children.Add(pushpinLayer);
this.userControl11.myMap.SetView(locations,
new Thickness(width / 2, height + 1, width / 2, 0), 0);
}
推荐阅读
- postgresql - 如何将触发器与 3 个不同的表一起使用
- vbscript - 从 Outlook 保存具有特定主题的电子邮件的附件
- sparql - 如何检查三元组是否存在?
- python - 即使我将 pytest.py 移动到 /bin,也找不到命令“pytest”
- yii - yii2 使用会话从 yii 获取用户身份验证
- excel - excel显示链接单元格的单元格地址NOT值
- javascript - 为复杂的验证编写正则表达式
- java - Java中的金字塔模式,星号后跟下划线
- cumulocity - 如何使用 c8y 中的事件处理脚本在数据资源管理器图形模式表中显示自定义信息
- git - 如何将 git 分支获取到先前的提交并将其作为新的 HEAD 推送?