我想清除地图上所有的Pushpin
。我可以用map.Children.Clear()
,这很好。但是我使用google maps
并使用这个XAML代码:
<my:Map Height="756" HorizontalAlignment="Left" Margin="12,6,0,0" Name="googlemap"
CredentialsProvider="AqayajnZU8FSfDGL8jpK5zMKAHmUL27Uqxv_OnpQzJQOI2PoQyxcG7dlR6_g4WWo"
CopyrightVisibility="Collapsed" LogoVisibility="Collapsed"
ScaleVisibility="Visible" VerticalAlignment="Top" Width="438" >
<my:Map.Mode>
<MSPCMCore:MercatorMode/>
</my:Map.Mode>
<my:MapTileLayer Name="street" Margin="0,0,0,32" Height="800" Width="433">
<my:MapTileLayer.TileSources>
<GoogleTileSource:GoogleTile TileTypes="Street"/>
</my:MapTileLayer.TileSources>
</my:MapTileLayer>
</my:Map>
所以,当我调用map.Children.Clear()
时,MapTileLayer
也被移除。如何只删除Pushpin
?
遍历所有子元素,只删除Pushpin类型的
foreach (var item in googlemap.Children.ToList())
{
if (item is MapTileLayer) continue;
googlemap.Children.Remove(item);
}