通过按钮单击从WP8地图控件中删除图层

时间:2014-07-23 18:04:08

标签: c# windows xaml windows-phone-8 windows-phone

只需按一下按钮,是否可以从地图控件中删除图层/图钉?下面是我添加图层的代码:

        MapLayer layer1 = new MapLayer();

        Pushpin pushpin1 = new Pushpin();
        pushpin1.GeoCoordinate = new GeoCoordinate(51.503147, -0.113245);
        pushpin1.Content = "Pin 1";

        MapOverlay overlay1 = new MapOverlay();
        overlay1.Content = pushpin1;
        overlay1.GeoCoordinate = new GeoCoordinate(51.503147, -0.113245);
        layer1.Add(overlay1);

        WC_WATMap.Layers.Add(layer1);

1 个答案:

答案 0 :(得分:2)

如果您不需要完全删除它们并且只是希望它们不再显示,只需将“可见性”设置为“折叠”即可。

pushpin1.Visibility = System.Windows.Visibility.Collapsed;

OR

Pushpin pushpin = (Pushpin)this.FindName("pushpin1");
pushpin.Visibility = System.Windows.Visibility.Collapsed;
如果您需要完全清除它们,

可能会在某个地方启动

Map.Layers.Remove()
Map.Layers.Remove((MapOverlay)this.FindName("layer1"));

对Anthony Russell的最终信用评论表的答案

WC_WATMap.Layers.Clear();