简体   繁体   English

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

[英]Remove layers from WP8 Map control via button click

Is it possible to remove layers/pushpins from a Map control at the push of a button? 按下按钮是否可以从地图控件中删除图层/图钉? Below is my code to add a layer: 下面是我添加层的代码:

        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);

If you don't need to remove them completely and just want them not shown any more, just set the Visibility to Collapsed. 如果您不需要完全删除它们,而只希望它们不再显示,则将“可见性”设置为“折叠”。

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

OR 要么

Pushpin pushpin = (Pushpin)this.FindName("pushpin1");
pushpin.Visibility = System.Windows.Visibility.Collapsed;

might be somewhere to start if you need to clear them completely 如果您需要彻底清除它们,可能是一个起点

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

FINAL CREDIT TO Anthony Russell for the answer in comment form 最终致谢Anthony Russell的评论表格

WC_WATMap.Layers.Clear();

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

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