Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2316 | - | 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 | public partial class CustomMarkerWP |
||
12 | { |
||
13 | //Popup Popup; |
||
14 | //Label Label; |
||
15 | GMapMarker Marker; |
||
16 | MainWindow MainWindow; |
||
17 | int _type = 0; |
||
2420 | - | 18 | public event positionChangedEventHandler positionChanged; |
19 | public delegate void positionChangedEventHandler(CustomMarkerWP wp); |
||
20 | public event newPositionEventHandler newPosition; |
||
21 | public delegate void newPositionEventHandler(CustomMarkerWP wp); |
||
22 | public event mouseCapturedEventHandler mouseCaptured; |
||
23 | public delegate void mouseCapturedEventHandler(bool isCaptured); |
||
2316 | - | 24 | |
25 | public CustomMarkerWP(MainWindow window, GMapMarker marker, string title, int type) |
||
26 | { |
||
27 | this.InitializeComponent(); |
||
28 | |||
29 | this.MainWindow = window; |
||
30 | this.Marker = marker; |
||
31 | _type = type; |
||
32 | |||
33 | //Popup = new Popup(); |
||
34 | //Label = new Label(); |
||
35 | |||
36 | //this.Unloaded += new RoutedEventHandler(CustomMarkerWP_Unloaded); |
||
2420 | - | 37 | this.Loaded += new RoutedEventHandler(CustomMarkerWP_Loaded); |
2316 | - | 38 | //this.SizeChanged += new SizeChangedEventHandler(CustomMarkerWP_SizeChanged); |
2420 | - | 39 | this.MouseEnter += new MouseEventHandler(MarkerControl_MouseEnter); |
40 | this.MouseLeave += new MouseEventHandler(MarkerControl_MouseLeave); |
||
41 | this.MouseMove += new MouseEventHandler(CustomMarkerWP_MouseMove); |
||
42 | this.MouseLeftButtonUp += new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonUp); |
||
43 | this.MouseLeftButtonDown += new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonDown); |
||
44 | StylusEnter += CustomMarkerWP_StylusEnter; |
||
45 | StylusLeave += CustomMarkerWP_StylusLeave; |
||
46 | StylusDown += CustomMarkerWP_StylusDown; |
||
47 | StylusMove += CustomMarkerWP_StylusMove; |
||
48 | StylusUp += CustomMarkerWP_StylusUp; |
||
2316 | - | 49 | |
50 | //Popup.Placement = PlacementMode.Mouse; |
||
51 | //{ |
||
52 | // Label.Background = Brushes.Blue; |
||
53 | // Label.Foreground = Brushes.White; |
||
54 | // Label.BorderBrush = Brushes.WhiteSmoke; |
||
55 | // Label.BorderThickness = new Thickness(2); |
||
56 | // Label.Padding = new Thickness(5); |
||
57 | // Label.FontSize = 22; |
||
58 | // Label.Content = title; |
||
59 | //} |
||
60 | //Popup.Child = Label; |
||
61 | text.Text = title; |
||
2373 | - | 62 | setType(); |
2316 | - | 63 | } |
64 | |||
2420 | - | 65 | private void CustomMarkerWP_StylusUp(object sender, StylusEventArgs e) |
66 | { |
||
67 | if (IsStylusCaptured) |
||
68 | { |
||
69 | Stylus.Capture(null); |
||
70 | newPosition(this); |
||
71 | mouseCaptured(false); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | private void CustomMarkerWP_StylusMove(object sender, StylusEventArgs e) |
||
76 | { |
||
77 | if (IsStylusCaptured) |
||
78 | { |
||
79 | Point p = e.GetPosition(MainWindow.MainMap); |
||
80 | Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y)); |
||
81 | if (positionChanged != null) |
||
82 | positionChanged(this); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | private void CustomMarkerWP_StylusDown(object sender, StylusDownEventArgs e) |
||
87 | { |
||
88 | if (!IsStylusCaptured) |
||
89 | { |
||
90 | Stylus.Capture(this); |
||
91 | mouseCaptured(true); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | private void CustomMarkerWP_StylusLeave(object sender, StylusEventArgs e) |
||
96 | { |
||
97 | Marker.ZIndex -= 10000; |
||
98 | } |
||
99 | |||
100 | private void CustomMarkerWP_StylusEnter(object sender, StylusEventArgs e) |
||
101 | { |
||
102 | Marker.ZIndex += 10000; |
||
103 | } |
||
104 | |||
2373 | - | 105 | void setType() |
106 | { |
||
107 | if (_type == 0) |
||
108 | { |
||
109 | gLanding.Visibility = Visibility.Hidden; |
||
110 | rect.Visibility = Visibility.Hidden; |
||
111 | ellipse.Visibility = Visibility.Visible; |
||
112 | } |
||
113 | if (_type == 1 | _type == 2) |
||
114 | { |
||
115 | gLanding.Visibility = Visibility.Hidden; |
||
116 | ellipse.Visibility = Visibility.Hidden; |
||
117 | rect.Visibility = Visibility.Visible; |
||
118 | } |
||
119 | if (_type == 3) |
||
120 | { |
||
121 | gLanding.Visibility = Visibility.Visible; |
||
122 | ellipse.Visibility = Visibility.Hidden; |
||
123 | rect.Visibility = Visibility.Hidden; |
||
124 | } |
||
125 | |||
126 | } |
||
2316 | - | 127 | void CustomMarkerWP_Loaded(object sender, RoutedEventArgs e) |
128 | { |
||
129 | //if (icon.Source.CanFreeze) |
||
130 | //{ |
||
131 | // icon.Source.Freeze(); |
||
132 | //} |
||
133 | } |
||
134 | |||
135 | void CustomMarkerWP_Unloaded(object sender, RoutedEventArgs e) |
||
136 | { |
||
137 | //this.Unloaded -= new RoutedEventHandler(CustomMarkerWP_Unloaded); |
||
138 | //this.Loaded -= new RoutedEventHandler(CustomMarkerWP_Loaded); |
||
139 | //this.SizeChanged -= new SizeChangedEventHandler(CustomMarkerWP_SizeChanged); |
||
2420 | - | 140 | this.MouseEnter -= new MouseEventHandler(MarkerControl_MouseEnter); |
141 | this.MouseLeave -= new MouseEventHandler(MarkerControl_MouseLeave); |
||
142 | this.MouseMove -= new MouseEventHandler(CustomMarkerWP_MouseMove); |
||
143 | this.MouseLeftButtonUp -= new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonUp); |
||
144 | this.MouseLeftButtonDown -= new MouseButtonEventHandler(CustomMarkerWP_MouseLeftButtonDown); |
||
145 | StylusEnter -= CustomMarkerWP_StylusEnter; |
||
146 | StylusLeave -= CustomMarkerWP_StylusLeave; |
||
147 | StylusDown -= CustomMarkerWP_StylusDown; |
||
148 | StylusMove -= CustomMarkerWP_StylusMove; |
||
149 | StylusUp -= CustomMarkerWP_StylusUp; |
||
2316 | - | 150 | |
151 | Marker.Shape = null; |
||
152 | //icon.Source = null; |
||
153 | //icon = null; |
||
154 | //Popup = null; |
||
155 | //Label = null; |
||
156 | } |
||
157 | public string WPText |
||
158 | { |
||
159 | get { return text.Text; } |
||
160 | set { text.Text = value; } |
||
161 | } |
||
162 | public int WPType |
||
163 | { |
||
164 | get { return _type; } |
||
2373 | - | 165 | set |
166 | { |
||
167 | _type = value; |
||
168 | setType(); |
||
169 | } |
||
2316 | - | 170 | } |
171 | |||
172 | public void setColor(string sColor) |
||
173 | { |
||
174 | RadialGradientBrush rgb = new RadialGradientBrush(); |
||
175 | GradientStop gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0x00),0), gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x1B, 0x1B),1); |
||
176 | switch (sColor) |
||
177 | { |
||
178 | case "red": |
||
179 | ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00)); |
||
2373 | - | 180 | rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00)); |
181 | landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x3A, 0x00)); |
||
2316 | - | 182 | gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0x00),0); |
183 | gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x1B, 0x1B),1); |
||
184 | break; |
||
185 | case "green": |
||
186 | ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); |
||
2373 | - | 187 | rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); |
188 | landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0x00)); |
||
2316 | - | 189 | gs0 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0xFD, 0x50),0); |
190 | gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x2F, 0x1B),1); |
||
191 | break; |
||
192 | case "yellow": |
||
193 | ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00)); |
||
2373 | - | 194 | rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00)); |
195 | landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x00)); |
||
2316 | - | 196 | gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0xFD, 0x00),0); |
197 | gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x5F, 0x1B),1); |
||
198 | break; |
||
199 | case "blue": |
||
200 | ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)); |
||
2373 | - | 201 | rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)); |
202 | landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)); |
||
2316 | - | 203 | gs0 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0xDB, 0xFD),0); |
204 | gs1 = new GradientStop(Color.FromArgb(0xFF, 0x00, 0x66, 0x5C),1); |
||
205 | break; |
||
206 | case "pink": |
||
207 | ellipse.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)); |
||
2373 | - | 208 | rect.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)); |
209 | landing.Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF)); |
||
2316 | - | 210 | gs0 = new GradientStop(Color.FromArgb(0xFF, 0xFD, 0x00, 0xCF),0); |
211 | gs1 = new GradientStop(Color.FromArgb(0xFF, 0x66, 0x00, 0x66),1); |
||
212 | break; |
||
213 | } |
||
214 | rgb.GradientStops.Add(gs0); |
||
215 | rgb.GradientStops.Add(gs1); |
||
216 | ellipse.Fill = rgb; |
||
2373 | - | 217 | rect.Fill = rgb; |
218 | landing.Fill = rgb; |
||
219 | |||
2316 | - | 220 | } |
221 | |||
222 | void CustomMarkerWP_SizeChanged(object sender, SizeChangedEventArgs e) |
||
223 | { |
||
224 | // Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2); |
||
225 | } |
||
226 | |||
227 | void CustomMarkerWP_MouseMove(object sender, MouseEventArgs e) |
||
228 | { |
||
2420 | - | 229 | if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured) |
230 | { |
||
231 | Point p = e.GetPosition(MainWindow.MainMap); |
||
232 | Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y)); |
||
233 | if(positionChanged != null) |
||
234 | positionChanged(this); |
||
235 | } |
||
2316 | - | 236 | } |
237 | |||
238 | void CustomMarkerWP_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
||
239 | { |
||
2420 | - | 240 | if (!IsMouseCaptured) |
241 | { |
||
242 | Mouse.Capture(this); |
||
243 | mouseCaptured(true); |
||
244 | } |
||
2316 | - | 245 | } |
246 | |||
247 | void CustomMarkerWP_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) |
||
248 | { |
||
2420 | - | 249 | if (IsMouseCaptured) |
250 | { |
||
251 | Mouse.Capture(null); |
||
252 | newPosition(this); |
||
253 | mouseCaptured(false); |
||
254 | } |
||
2316 | - | 255 | } |
256 | |||
257 | void MarkerControl_MouseLeave(object sender, MouseEventArgs e) |
||
258 | { |
||
259 | Marker.ZIndex -= 10000; |
||
260 | //Popup.IsOpen = false; |
||
261 | } |
||
262 | |||
263 | void MarkerControl_MouseEnter(object sender, MouseEventArgs e) |
||
264 | { |
||
265 | Marker.ZIndex += 10000; |
||
266 | //Popup.IsOpen = true; |
||
267 | } |
||
268 | |||
269 | } |
||
270 | } |