using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using GMap.NET.WindowsPresentation;
using System.Diagnostics;
namespace MKLiveView
.GMapCustomMarkers
{
public partial class CustomMarkerWP
{
//Popup Popup;
//Label Label;
GMapMarker Marker
;
MainWindow MainWindow
;
int _type
= 0;
public event positionChangedEventHandler positionChanged
;
public delegate void positionChangedEventHandler
(CustomMarkerWP wp
);
public event newPositionEventHandler newPosition
;
public delegate void newPositionEventHandler
(CustomMarkerWP wp
);
public event mouseCapturedEventHandler mouseCaptured
;
public delegate void mouseCapturedEventHandler
(bool isCaptured
);
public CustomMarkerWP
(MainWindow window, GMapMarker marker,
string title,
int type
)
{
this.InitializeComponent();
this.MainWindow = window
;
this.Marker = marker
;
_type
= type
;
//Popup = new Popup();
//Label = new Label();
//this.Unloaded += new RoutedEventHandler(CustomMarkerWP_Unloaded);
this.Loaded += new RoutedEventHandler
(CustomMarkerWP_Loaded
);
//this.SizeChanged += new SizeChangedEventHandler(CustomMarkerWP_SizeChanged);
this.MouseEnter += new MouseEventHandler
(MarkerControl_MouseEnter
);
this.MouseLeave += new MouseEventHandler
(MarkerControl_MouseLeave
);
this.MouseMove += new MouseEventHandler
(CustomMarkerWP_MouseMove
);
this.MouseLeftButtonUp += new MouseButtonEventHandler
(CustomMarkerWP_MouseLeftButtonUp
);
this.MouseLeftButtonDown += new MouseButtonEventHandler
(CustomMarkerWP_MouseLeftButtonDown
);
StylusEnter
+= CustomMarkerWP_StylusEnter
;
StylusLeave
+= CustomMarkerWP_StylusLeave
;
StylusDown
+= CustomMarkerWP_StylusDown
;
StylusMove
+= CustomMarkerWP_StylusMove
;
StylusUp
+= CustomMarkerWP_StylusUp
;
//Popup.Placement = PlacementMode.Mouse;
//{
// Label.Background = Brushes.Blue;
// Label.Foreground = Brushes.White;
// Label.BorderBrush = Brushes.WhiteSmoke;
// Label.BorderThickness = new Thickness(2);
// Label.Padding = new Thickness(5);
// Label.FontSize = 22;
// Label.Content = title;
//}
//Popup.Child = Label;
text
.Text = title
;
setType
();
}
private void CustomMarkerWP_StylusUp
(object sender, StylusEventArgs e
)
{
if (IsStylusCaptured
)
{
Stylus
.Capture(null);
newPosition
(this);
mouseCaptured
(false);
}
}
private void CustomMarkerWP_StylusMove
(object sender, StylusEventArgs e
)
{
if (IsStylusCaptured
)
{
Point p
= e
.GetPosition(MainWindow
.MainMap);
Marker
.Position = MainWindow
.MainMap.FromLocalToLatLng((int)(p
.X),
(int)(p
.Y));
if (positionChanged
!= null)
positionChanged
(this);
}
}
private void CustomMarkerWP_StylusDown
(object sender, StylusDownEventArgs e
)
{
if (!IsStylusCaptured
)
{
Stylus
.Capture(this);
mouseCaptured
(true);
}
}
private void CustomMarkerWP_StylusLeave
(object sender, StylusEventArgs e
)
{
Marker
.ZIndex -= 10000;
}
private void CustomMarkerWP_StylusEnter
(object sender, StylusEventArgs e
)
{
Marker
.ZIndex += 10000;
}
void setType
()
{
if (_type
== 0)
{
gLanding
.Visibility = Visibility
.Hidden;
rect
.Visibility = Visibility
.Hidden;
ellipse
.Visibility = Visibility
.Visible;
}
if (_type
== 1 | _type
== 2)
{
gLanding
.Visibility = Visibility
.Hidden;
ellipse
.Visibility = Visibility
.Hidden;
rect
.Visibility = Visibility
.Visible;
}
if (_type
== 3)
{
gLanding
.Visibility = Visibility
.Visible;
ellipse
.Visibility = Visibility
.Hidden;
rect
.Visibility = Visibility
.Hidden;
}
}
void CustomMarkerWP_Loaded
(object sender, RoutedEventArgs e
)
{
//if (icon.Source.CanFreeze)
//{
// icon.Source.Freeze();
//}
}
void CustomMarkerWP_Unloaded
(object sender, RoutedEventArgs e
)
{
//this.Unloaded -= new RoutedEventHandler(CustomMarkerWP_Unloaded);
//this.Loaded -= new RoutedEventHandler(CustomMarkerWP_Loaded);
//this.SizeChanged -= new SizeChangedEventHandler(CustomMarkerWP_SizeChanged);
this.MouseEnter -= new MouseEventHandler
(MarkerControl_MouseEnter
);
this.MouseLeave -= new MouseEventHandler
(MarkerControl_MouseLeave
);
this.MouseMove -= new MouseEventHandler
(CustomMarkerWP_MouseMove
);
this.MouseLeftButtonUp -= new MouseButtonEventHandler
(CustomMarkerWP_MouseLeftButtonUp
);
this.MouseLeftButtonDown -= new MouseButtonEventHandler
(CustomMarkerWP_MouseLeftButtonDown
);
StylusEnter
-= CustomMarkerWP_StylusEnter
;
StylusLeave
-= CustomMarkerWP_StylusLeave
;
StylusDown
-= CustomMarkerWP_StylusDown
;
StylusMove
-= CustomMarkerWP_StylusMove
;
StylusUp
-= CustomMarkerWP_StylusUp
;
Marker
.Shape = null;
//icon.Source = null;
//icon = null;
//Popup = null;
//Label = null;
}
public string WPText
{
get { return text
.Text; }
set { text
.Text = value; }
}
public int WPType
{
get { return _type
; }
set
{
_type
= value;
setType
();
}
}
public void setColor
(string sColor
)
{
RadialGradientBrush rgb
= new RadialGradientBrush
();
GradientStop gs0
= new GradientStop
(Color
.FromArgb(0xFF, 0xFD, 0x00, 0x00
),
0), gs1
= new GradientStop
(Color
.FromArgb(0xFF, 0x66, 0x1B, 0x1B
),
1);
switch (sColor
)
{
case "red":
ellipse
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0x3A, 0x00
));
rect
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0x3A, 0x00
));
landing
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0x3A, 0x00
));
gs0
= new GradientStop
(Color
.FromArgb(0xFF, 0xFD, 0x00, 0x00
),
0);
gs1
= new GradientStop
(Color
.FromArgb(0xFF, 0x66, 0x1B, 0x1B
),
1);
break;
case "green":
ellipse
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0x00, 0xFF, 0x00
));
rect
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0x00, 0xFF, 0x00
));
landing
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0x00, 0xFF, 0x00
));
gs0
= new GradientStop
(Color
.FromArgb(0xFF, 0x00, 0xFD, 0x50
),
0);
gs1
= new GradientStop
(Color
.FromArgb(0xFF, 0x66, 0x2F, 0x1B
),
1);
break;
case "yellow":
ellipse
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0xFF, 0x00
));
rect
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0xFF, 0x00
));
landing
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0xFF, 0x00
));
gs0
= new GradientStop
(Color
.FromArgb(0xFF, 0xFD, 0xFD, 0x00
),
0);
gs1
= new GradientStop
(Color
.FromArgb(0xFF, 0x66, 0x5F, 0x1B
),
1);
break;
case "blue":
ellipse
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0x00, 0xFF, 0xFF
));
rect
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0x00, 0xFF, 0xFF
));
landing
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0x00, 0xFF, 0xFF
));
gs0
= new GradientStop
(Color
.FromArgb(0xFF, 0x00, 0xDB, 0xFD
),
0);
gs1
= new GradientStop
(Color
.FromArgb(0xFF, 0x00, 0x66, 0x5C
),
1);
break;
case "pink":
ellipse
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0x00, 0xFF
));
rect
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0x00, 0xFF
));
landing
.Stroke = new SolidColorBrush
(Color
.FromArgb(0xFF, 0xFF, 0x00, 0xFF
));
gs0
= new GradientStop
(Color
.FromArgb(0xFF, 0xFD, 0x00, 0xCF
),
0);
gs1
= new GradientStop
(Color
.FromArgb(0xFF, 0x66, 0x00, 0x66
),
1);
break;
}
rgb
.GradientStops.Add(gs0
);
rgb
.GradientStops.Add(gs1
);
ellipse
.Fill = rgb
;
rect
.Fill = rgb
;
landing
.Fill = rgb
;
}
void CustomMarkerWP_SizeChanged
(object sender, SizeChangedEventArgs e
)
{
// Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2);
}
void CustomMarkerWP_MouseMove
(object sender, MouseEventArgs e
)
{
if (e
.LeftButton == MouseButtonState
.Pressed && IsMouseCaptured
)
{
Point p
= e
.GetPosition(MainWindow
.MainMap);
Marker
.Position = MainWindow
.MainMap.FromLocalToLatLng((int)(p
.X),
(int)(p
.Y));
if(positionChanged
!= null)
positionChanged
(this);
}
}
void CustomMarkerWP_MouseLeftButtonDown
(object sender, MouseButtonEventArgs e
)
{
if (!IsMouseCaptured
)
{
Mouse
.Capture(this);
mouseCaptured
(true);
}
}
void CustomMarkerWP_MouseLeftButtonUp
(object sender, MouseButtonEventArgs e
)
{
if (IsMouseCaptured
)
{
Mouse
.Capture(null);
newPosition
(this);
mouseCaptured
(false);
}
}
void MarkerControl_MouseLeave
(object sender, MouseEventArgs e
)
{
Marker
.ZIndex -= 10000;
//Popup.IsOpen = false;
}
void MarkerControl_MouseEnter
(object sender, MouseEventArgs e
)
{
Marker
.ZIndex += 10000;
//Popup.IsOpen = true;
}
}
}