加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 尝试添加叠加层以映射错误

发布时间:2020-12-15 05:38:39 所属栏目:百科 来源:网络整理
导读:我刚刚清除了映射程序中的图层,当我尝试添加新图层时,我收到此错误消息. newSystem.ArgumentException was unhandled by user codeHResult=-2147024809Message=Value does not fall within the expected range.Source=System.WindowsInnerException: 如果有
我刚刚清除了映射程序中的图层,当我尝试添加新图层时,我收到此错误消息.
newSystem.ArgumentException was unhandled by user code
HResult=-2147024809
Message=Value does not fall within the expected range.
Source=System.Windows
InnerException:

如果有人知道为什么会这样,我将非常感谢您的帮助

private void loadZoomLevel12Pics()
    {
        map1.Layers.Clear();
        MapLayer pinLayer = new MapLayer();
        // Create a new empty Pushpin
        // Beny Sur- Mer War Cemetary 
        MapOverlay pinOverlay = new MapOverlay();
        // Add the location of the Pushpin using latitude and longitude.
        pinOverlay.GeoCoordinate = new GeoCoordinate(49.33783000,-0.45215600);
        //Image pinOverlayImage = new Image();
        pinOverlayImage.Source = new BitmapImage(new Uri("images/Hedgehog.png",UriKind.Relative));
        pinOverlay.Content = pinOverlayImage;
        pinOverlay.PositionOrigin = new Point(0.0,0.0);
        pinOverlayImage.Opacity = 0.8;
        pinOverlayImage.Height = 8;
        pinOverlayImage.Width = 8;
        pinOverlayImage.Tap += pinOverlayImage_Tap;
        pinLayer.Add(pinOverlay);
        map1.Layers.Add(pinLayer);

然后清除这些图片并加载新的缩放级别

private void loadZoomLevel13Pics()
    {
        map1.Layers.Clear();
        MapLayer pinLayer = new MapLayer();
        // Create a new empty Pushpin
        // Beny Sur- Mer War Cemetary 
        MapOverlay pinOverlay = new MapOverlay();
        // Add the location of the Pushpin using latitude and longitude.
        pinOverlay.GeoCoordinate = new GeoCoordinate(49.33783000,0.0);
        pinOverlayImage.Opacity = 0.8;
        pinOverlayImage.Height = 30;
        pinOverlayImage.Width = 30;
        pinOverlayImage.Tap += pinOverlayImage_Tap;
        pinLayer.Add(pinOverlay);
        map1.Layers.Add(pinLayer); // THIS IS THE LINE CAUSING THE PROBLEM

所有图像都是全局声明的,因为它们用在程序内的其他函数/方法中.

看起来它试图添加之前添加的同一层并且很难这样做,但是在方法的第一行清除了所有层.

解决方法

我使用全局多边形而不是图像时遇到了同样的问题.问题是,即使你正在调用map1.Layers.Clear(),这也不会在调用后立即完成,因此你需要创建一个新的图像.通常,这可以通过不使用覆盖的全局/实例变量来修复.内容…每次只声明它并将其分配给内容.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读