从WPF C#VS2013

时间:2015-10-06 02:09:34

标签: c# wpf visual-studio google-maps openstreetmap

我想在C#VS2013的OpenStreetMap中为地图添加一个标记。

我正在研究WPF。我设计了一个在地图中添加标记的功能,但无法显示。

标记可以显示在地图上,但因为图像是方形,标记本身有一些白色背景,覆盖标记位置周围的区域。如何只添加标记本身而不会在地图上覆盖环绕区域的任何背景?

任何帮助将不胜感激。

代码是:

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GMap.NET;
using GMap.NET.WindowsPresentation;
using GMap.NET.MapProviders;
namespace try_gmap_wpf
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
        InitializeComponent();
        myMap.MapProvider = OpenStreetMapProvider.Instance;
        GMap.NET.GMaps.Instance.Mode = AccessMode.ServerOnly;
        myMap.Position = new PointLatLng(42.742826, -77.030212);
        myAddMarker(42.344142, -71.067330, ref myMap);

        myMap.MinZoom = 0;
        myMap.MaxZoom = 10;
        //set zoom
        myMap.Zoom = 5;
        myMap.ShowCenter = true; 
        myMap.CanDragMap = true;
    }

    public void myAddMarker(double latitude, double longitude, ref GMapControl myMap)
    {
            System.Windows.Media.Imaging.BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            // this image is a square. It has some background covering areas surrounding the marked location.
            bitmapImage.UriSource = new Uri(@"C:\images\map_marker.png");
            bitmapImage.DecodePixelHeight = 15;
            bitmapImage.DecodePixelWidth = 15;
            bitmapImage.EndInit();
            GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(latitude, longitude);
            GMapMarker marker = new GMapMarker(point);
            System.Windows.Controls.Image image = new System.Windows.Controls.Image();
            image.Source = bitmapImage;
            marker.Shape = image;
            marker.Tag = "cde";
            marker.ZIndex = 10;
            myMap.Markers.Add(marker);
      }
  }
}

0 个答案:

没有答案