【问题标题】:GMap.net in wpf custom marker iconWpf 中的 GMap.net 自定义标记图标
【发布时间】:2019-01-20 09:35:21
【问题描述】:

我想在 WPF 中使用 GMAP.NET 我添加了 GMap.NET.Core.dll 和 GMap.NET.WindowsForms.dll 作为对我的项目的引用。 在document 的帮助下,我正在使用 GMAP.Net,但在 WPF 中。现在我想为我的标记使用自定义图标,但我找不到方法。 我的代码如下

 gmap.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
        GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly; 
        gmap.Position = new GMap.NET.PointLatLng(35.6960617168288, 51.4005661010742);
        gmap.ShowCenter = false;

        GMap.NET.WindowsPresentation.GMapMarker marker = new GMap.NET.WindowsPresentation.GMapMarker(new GMap.NET.PointLatLng(35.6960617168288, 51.4005661010742));
        marker.Shape = new Ellipse
        {
            Width = 10,
            Height = 10,
            Stroke = Brushes.Red,
            StrokeThickness = 1.5,
            ToolTip = "This is tooltip",
            Visibility=Visibility.Visible,
            Fill=Brushes.Red,

        };
        gmap.Markers.Add(marker);

感谢任何帮助。

【问题讨论】:

    标签: wpf marker gmap.net


    【解决方案1】:

    在搜索更多之后,我发现这段代码有效:

     System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.UriSource = new Uri(@"D:\s.gif");
            bitmapImage.EndInit();
            GMap.NET.WindowsPresentation.GMapMarker marker2 = new GMap.NET.WindowsPresentation.GMapMarker(new GMap.NET.PointLatLng(35.6960617168288, 51.4005661010742));
            System.Windows.Controls.Image image = new System.Windows.Controls.Image();
            image.Source = bitmapImage;
            marker2.Shape = image;
            gmap.Markers.Add(marker2); 
    

    这个link 帮助了我。

    【讨论】:

      【解决方案2】:

      使用Image 的实例作为Shape 属性的值:

      marker.Shape = new Image
      {
          Width = 10,
          Height = 10,
          Source = new BitmapImage(new System.Uri("pack://application:,,,/assets/marker.png"))
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多