Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2287 - 1
using System.Windows;
2
using System.Windows.Controls;
3
using System.Windows.Controls.Primitives;
4
using System.Windows.Input;
5
using System.Windows.Media;
6
using GMap.NET.WindowsPresentation;
7
using System.Diagnostics;
8
 
9
namespace MKLiveView.GMapCustomMarkers
10
{
11
    /// <summary>
12
    /// Interaction logic for CustomMarkerCopter.xaml
13
    /// </summary>
14
    public partial class CustomMarkerCopter
15
    {
16
        //Popup Popup;
17
        //Label Label;
18
        GMapMarker Marker;
19
        MainWindow MainWindow;
20
 
21
        public CustomMarkerCopter(MainWindow window, GMapMarker marker, string title)
22
        {
23
            this.InitializeComponent();
24
 
25
            this.MainWindow = window;
26
            this.Marker = marker;
27
 
28
            //Popup = new Popup();
29
            //Label = new Label();
30
 
31
            this.Unloaded += new RoutedEventHandler(CustomMarkerCopter_Unloaded);
32
            this.Loaded += new RoutedEventHandler(CustomMarkerCopter_Loaded);
33
            this.SizeChanged += new SizeChangedEventHandler(CustomMarkerCopter_SizeChanged);
34
            //this.MouseEnter += new MouseEventHandler(MarkerControl_MouseEnter);
35
            //this.MouseLeave += new MouseEventHandler(MarkerControl_MouseLeave);
36
            //this.MouseMove += new MouseEventHandler(CustomMarkerCopter_MouseMove);
37
            //this.MouseLeftButtonUp += new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonUp);
38
            //this.MouseLeftButtonDown += new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonDown);
39
 
40
            //Popup.Placement = PlacementMode.Mouse;
41
            //{
42
            //   Label.Background = Brushes.Blue;
43
            //   Label.Foreground = Brushes.White;
44
            //   Label.BorderBrush = Brushes.WhiteSmoke;
45
            //   Label.BorderThickness = new Thickness(2);
46
            //   Label.Padding = new Thickness(5);
47
            //   Label.FontSize = 22;
48
            //   Label.Content = title;
49
            //}
50
            //Popup.Child = Label;
51
            lbl.Content = title;
52
        }
53
 
54
        void CustomMarkerCopter_Loaded(object sender, RoutedEventArgs e)
55
        {
56
            if (icon.Source.CanFreeze)
57
            {
58
                icon.Source.Freeze();
59
            }
60
        }
61
 
62
        void CustomMarkerCopter_Unloaded(object sender, RoutedEventArgs e)
63
        {
64
            this.Unloaded -= new RoutedEventHandler(CustomMarkerCopter_Unloaded);
65
            this.Loaded -= new RoutedEventHandler(CustomMarkerCopter_Loaded);
66
            this.SizeChanged -= new SizeChangedEventHandler(CustomMarkerCopter_SizeChanged);
67
            //this.MouseEnter -= new MouseEventHandler(MarkerControl_MouseEnter);
68
            //this.MouseLeave -= new MouseEventHandler(MarkerControl_MouseLeave);
69
            //this.MouseMove -= new MouseEventHandler(CustomMarkerCopter_MouseMove);
70
            //this.MouseLeftButtonUp -= new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonUp);
71
            //this.MouseLeftButtonDown -= new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonDown);
72
 
73
            Marker.Shape = null;
74
            icon.Source = null;
75
            icon = null;
76
            //Popup = null;
77
            //Label = null;         
78
        }
79
        public void setText(string s)
80
        {
81
            lbl.Content = s;
82
        }
83
 
84
        void CustomMarkerCopter_SizeChanged(object sender, SizeChangedEventArgs e)
85
        {
86
           // Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2);
87
        }
88
 
89
        void CustomMarkerCopter_MouseMove(object sender, MouseEventArgs e)
90
        {
91
            if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured)
92
            {
93
                Point p = e.GetPosition(MainWindow.MainMap);
94
                Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y));
95
            }
96
        }
97
 
98
        void CustomMarkerCopter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
99
        {
100
            if (!IsMouseCaptured)
101
            {
102
                Mouse.Capture(this);
103
            }
104
        }
105
 
106
        void CustomMarkerCopter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
107
        {
108
            if (IsMouseCaptured)
109
            {
110
                Mouse.Capture(null);
111
            }
112
        }
113
 
114
        void MarkerControl_MouseLeave(object sender, MouseEventArgs e)
115
        {
116
            Marker.ZIndex -= 10000;
117
            //Popup.IsOpen = false;
118
        }
119
 
120
        void MarkerControl_MouseEnter(object sender, MouseEventArgs e)
121
        {
122
            Marker.ZIndex += 10000;
123
            //Popup.IsOpen = true;
124
        }
125
 
126
    }
127
}