简体   繁体   English

如何从 Bing 地图中删除所有现有的图钉?

[英]How can I delete all existing Pushpins from Bing Maps?

Using a different version/flavor of Bing Maps several years ago, I asked this same question and ultimately self-posted the answer, here .几年前使用不同版本/风格的 Bing 地图,我问了同样的问题并最终在此处自行发布了答案。

But that doesn't work with my Winforms app using the WPF control.但这不适用于我使用 WPF 控件的 Winforms 应用程序。 With this code:使用此代码:

var mapLayerChildren = from c in DataLayer.Children select c;
var kinderGarten = mapLayerChildren.ToArray();
for (int i = 0; i < kinderGarten.Count(); i++)
{
    if (kinderGarten[i] is Pushpin)
    {
        DataLayer.Children.Remove(kinderGarten[i]);
    }
}

... DataLayer is not recognized. ... DataLayer无法识别。

And when I try to replace "DataLayer" with "userControl11.myMap.Children" I get this:当我尝试用“userControl11.myMap.Children”替换“DataLayer”时,我得到了这个:

在此处输入图像描述

What do I need to do?我需要做什么?

It depends to how you have added the pushpins.这取决于您如何添加图钉。 You need to remove them from the same Children collection to which you have added them.您需要将它们从添加它们的同一个Children集合中删除。

Assuming you have added your pushpins directly to the Children collection of the map, then you can find all the pushpins and remove them like this:假设您已将图钉直接添加到 map 的Children集合中,那么您可以找到所有图钉并将其删除,如下所示:

var map = this.userControl11.myMap;
map.Children.OfType<Pushpin>().ToList().ForEach(pin => {
    map.Children.Remove(pin);           
});

Or to remove all children of the map, including pushpin, shape, layer, and etc. you can use:或者要删除 map 的所有子项,包括图钉、形状、图层等,您可以使用:

var map = this.userControl11.myMap;
map.Children.Clear();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM