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
 
2319 - 21
        public CustomMarkerCopter(MainWindow window, GMapMarker marker, string title, string sColor)
2287 - 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
        }
2319 - 83
        public void setColor(string sColor)
84
        {
85
            switch (sColor)
86
            {
87
                case "red":
88
                    icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterRed.png", System.UriKind.Relative));
89
                    break;
90
                case "green":
91
                    icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterGreen.png", System.UriKind.Relative));
92
                    break;
93
                case "blue":
94
                    icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterBlue.png", System.UriKind.Relative));
95
                    break;
96
                case "yellow":
97
                    icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterYellow.png", System.UriKind.Relative));
98
                    break;
99
                case "pink":
100
                    icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterPink.png", System.UriKind.Relative));
101
                    break;
2287 - 102
 
2319 - 103
                default:
104
                    icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterRed.png", System.UriKind.Relative));
105
                    break;
106
            }
107
        }
2287 - 108
        void CustomMarkerCopter_SizeChanged(object sender, SizeChangedEventArgs e)
109
        {
110
           // Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2);
111
        }
112
 
113
        void CustomMarkerCopter_MouseMove(object sender, MouseEventArgs e)
114
        {
115
            if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured)
116
            {
117
                Point p = e.GetPosition(MainWindow.MainMap);
118
                Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y));
119
            }
120
        }
121
 
122
        void CustomMarkerCopter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
123
        {
124
            if (!IsMouseCaptured)
125
            {
126
                Mouse.Capture(this);
127
            }
128
        }
129
 
130
        void CustomMarkerCopter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
131
        {
132
            if (IsMouseCaptured)
133
            {
134
                Mouse.Capture(null);
135
            }
136
        }
137
 
138
        void MarkerControl_MouseLeave(object sender, MouseEventArgs e)
139
        {
140
            Marker.ZIndex -= 10000;
141
            //Popup.IsOpen = false;
142
        }
143
 
144
        void MarkerControl_MouseEnter(object sender, MouseEventArgs e)
145
        {
146
            Marker.ZIndex += 10000;
147
            //Popup.IsOpen = true;
148
        }
149
 
150
    }
151
}