Custom Pin Suggestion

Feb 12, 2009 at 12:19 PM
Hi,
May i suggest implementing a marker class with the following properties :

Type = enum  Pin, Circle, Square, Triangle, Doughnut
Size = Point size
Color = System.Drawing.Color

This will allow for easy assortment of markers.  The PIN type can just draw a circle with a filled in   'V'  shape below, as per google's pins, the other types just simple shapes.
I know requests have been made for the extension of the 4 colors, but this method will allow the full spectrum of colors without additional coding for the developer.

Thanks.
Coordinator
Feb 12, 2009 at 12:34 PM
good ;}
Mar 14, 2009 at 1:05 AM
for the WPF version, I've created a marker where you pass in a frameworkelement into the constructor, that way you can have any object as your marker (image, lists, usercontrols etc). It seems a better way to do it as no matter how many things you have in your enum, there's always going to someone who wants something different. I can send it up if anyones interested.

Next thing to look at is getting polygons on the map so you can create boundry overlays...that starts monday...now it's time for bed!
Mar 16, 2009 at 5:54 PM
Hi Moose

please send. I have some markers which need certain customizing. your solution seem like ... the solution.

kr
george
Mar 17, 2009 at 7:50 AM
moosetaylor,  the boundry overlays is something i'm very interested in.  Does anyone know where / how i can get UK PostCode boundry info from so i can add these as an overlay too.
Thanks,

Mar 17, 2009 at 8:32 AM
Here's the code for the altered GMapMarker.cs
Below that, I'll post the code for my custom Frameworkelement market GMapMarkerFrameworkElement.cs
Note: I added some dependencyproperties to GMapWindowsPresentation.cs to track current / focused markers, plus added an observablecollection of markers... here's the stubs for these properties:

 

/// <summary>

 

 

/// The marker that currently has focus (right click etc)

 

 

/// </summary>

 

 

public GMapMarker FocusedMarker

 

{

 

get { return (GMapMarker)GetValue(FocusedMarkerProperty); }

 

 

set { SetValue(FocusedMarkerProperty, value); }

 

}

 

// Using a DependencyProperty as the backing store for FocusedMarker. This enables animation, styling, binding, etc...

 

 

public static readonly DependencyProperty FocusedMarkerProperty =

 

 

DependencyProperty.Register("FocusedMarker", typeof(GMapMarker), typeof(GMap), new UIPropertyMetadata(null));

 

 

 

 

/// <summary>

 

 

/// The current Marker (when clicked etc)

 

 

/// </summary>

 

 

public GMapMarker CurrentMarker

 

{

 

get { return (GMapMarker)GetValue(CurrentMarkerProperty); }

 

 

set { SetValue(CurrentMarkerProperty, value); }

 

}

 

// Using a DependencyProperty as the backing store for CurrentMarker. This enables animation, styling, binding, etc...

 

 

public static readonly DependencyProperty CurrentMarkerProperty =

 

 

DependencyProperty.Register("CurrentMarker", typeof(GMapMarker), typeof(GMap), new UIPropertyMetadata(null, new PropertyChangedCallback(OnCurrentMarkerChanged)));

 

 

 

private static void OnCurrentMarkerChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)

 

{

 

GMap map = o as GMap;

 

 

if (map == null) return;

 

 

GMapMarker marker = e.NewValue as GMapMarker;

 

 

if (marker == null) return;

 

 

foreach (GMapMarker m in map.MapMarkers)

 

{

m.IsCurrentMarker =

false;

 

}

marker.IsCurrentMarker =

true;

 

}

 

 

 

public ObservableCollection<GMapMarker> MapMarkers

 

{

 

get { return (ObservableCollection<GMapMarker>)GetValue(MapMarkersProperty); }

 

 

set { SetValue(MapMarkersProperty, value); }

 

}

 

// Using a DependencyProperty as the backing store for MapMarkers. This enables animation, styling, binding, etc...

 

 

public static readonly DependencyProperty MapMarkersProperty =

 

 

DependencyProperty.Register("MapMarkers", typeof(ObservableCollection<GMapMarker>), typeof(GMap), new UIPropertyMetadata(new ObservableCollection<GMapMarker>()));

 

 

----------------------------------------------
-- GMapMarker.cs
----------------------------------------------

using

 

System.Collections.Generic;

 

using

 

System.Windows.Controls.Primitives;

 

using

 

System.Windows.Input;

 

using

 

System.Windows.Media;

 

using

 

System.Windows.Shapes;

 

using

 

GMapNET;

 

namespace

 

System.Windows.Controls

 

{

 

public abstract class GMapMarker : MapObject

 

{

 

public Boolean IsCurrentMarker { get; set; }

 

 

public TextBlock TextBlock = new TextBlock();

 

 

public readonly Popup Popup = new Popup();

 

 

public readonly Label Label = new Label();

 

 

public bool ShowTooltip = true;

 

 

private ContextMenu _contextMenu;

 

 

public ContextMenu ContextMenu

 

{

 

get

 

{

 

return _contextMenu;

 

}

 

set

 

{

_contextMenu =

value;

 

 

if(MarkerElement!=null)

 

MarkerElement.ContextMenu = _contextMenu;

}

}

 

int z;

 

 

public string Text

 

{

 

get

 

{

 

return TextBlock.Text;

 

}

 

set

 

{

TextBlock.Text =

value;

 

}

}

 

public abstract FrameworkElement MarkerElement

 

{

 

get;

 

}

 

public GMap Map;

 

 

public readonly Dictionary<UIElement, Point> Objects = new Dictionary<UIElement, Point>();

 

 

public int X

 

{

 

get

 

{

 

return (int) Canvas.GetLeft(MarkerElement);

 

}

}

 

public int Y

 

{

 

get

 

{

 

return (int) Canvas.GetTop(MarkerElement);

 

}

}

 

public GMapMarker()

 

{

IsCurrentMarker =

false;

 

TextBlock.IsHitTestVisible =

false;

 

TextBlock.TextAlignment =

TextAlignment.Center;

 

TextBlock.Foreground =

Brushes.White;

 

TextBlock.FontSize = 12;

TextBlock.FontWeight =

FontWeights.Bold;

 

Text =

"-";

 

 

//Label.SetResourceReference(Label.StyleProperty, "MarkerLabel");

 

 

//Label.Style = Application.Current.MainWindow.Resources["MarkerLabel"] as Style;

 

 

////////Label.Foreground = Brushes.White;

 

 

////////Label.BorderBrush = Brushes.Black;

 

 

////////Label.BorderThickness = new Thickness(2);

 

 

////////Label.Padding = new Thickness(5);

 

 

////////Label.FontSize = 14;

 

Label.Content =

"-";

 

Popup.AllowsTransparency =

true;

 

Popup.Child = Label;

Popup.Placement =

PlacementMode.Mouse;

 

 

SetMarkerMouseEvents();

SetShapeCenter();

}

 

public void SetMarkerMouseEvents()

 

{

MarkerElement.MouseEnter +=

new MouseEventHandler(MarkerElement_MouseEnter);

 

MarkerElement.MouseLeave +=

new MouseEventHandler(MarkerElement_MouseLeave);

 

MarkerElement.MouseWheel +=

new MouseWheelEventHandler(MarkerElement_MouseWheel);

 

MarkerElement.MouseDown +=

new MouseButtonEventHandler(MarkerElement_MouseDown);

 

MarkerElement.MouseUp +=

new MouseButtonEventHandler(MarkerElement_MouseUp);

 

}

 

void MarkerElement_MouseUp(object sender, MouseButtonEventArgs e)

 

{

IsCurrentMarker =

false;

 

Map.CurrentMarker =

null;

 

}

 

void MarkerElement_MouseDown(object sender, MouseButtonEventArgs e)

 

{

 

if (e.ChangedButton == MouseButton.Left)

 

{

IsCurrentMarker =

true;

 

Map.CurrentMarker =

this;

 

}

Map.FocusedMarker =

this;

 

 

if (ShowTooltip)

 

{

Popup.IsOpen =

false;

 

}

}

 

void MarkerElement_MouseWheel(object sender, MouseWheelEventArgs e)

 

{

 

if(MarkerElement.IsMouseDirectlyOver)

 

{

 

if(e.Delta > 0)

 

{

MarkerElement.Width += 1;

MarkerElement.Height += 1;

}

 

else

 

{

MarkerElement.Width -= 1;

MarkerElement.Height -= 1;

}

UpdateLocalPosition(Map);

}

}

 

void MarkerElement_MouseLeave(object sender, MouseEventArgs e)

 

{

 

if(!IsCurrentMarker)

 

{

MarkerElement.Cursor =

Cursors.Arrow;

 

 

if(ShowTooltip)

 

{

Popup.IsOpen =

false;

 

}

 

Canvas.SetZIndex(MarkerElement, z-1000);

 

 

Canvas.SetZIndex(TextBlock, z-1000);

 

}

}

 

void MarkerElement_MouseEnter(object sender, MouseEventArgs e)

 

{

 

if (!IsCurrentMarker)

 

{

z =

Canvas.GetZIndex(MarkerElement);

 

MarkerElement.Cursor =

Cursors.Hand;

 

 

if(ShowTooltip)

 

{

Popup.IsOpen =

true;

 

}

 

Canvas.SetZIndex(MarkerElement, z+1000);

 

 

Canvas.SetZIndex(TextBlock, z+1000);

 

}

}

 

public abstract void SetShapeCenter();

 

 

public void UpdateLocalPosition(IGControl map)

 

{

SetShapeCenter();

GMapNET.

Point p = map.FromLatLngToLocal(Position);

 

 

foreach(KeyValuePair<UIElement, Point> e in Objects)

 

{

GMapNET.

Point t = p;

 

t.Offset((

int) e.Value.X, (int) e.Value.Y);

 

 

Canvas.SetTop(e.Key, t.Y);

 

 

Canvas.SetLeft(e.Key, t.X);

 

}

}

}

}



----------------------------------------------
-- Here's GMapMarkerFrameworkElement.cs
----------------------------------------------

using

 

System.Windows.Input;

 

using

 

System.Windows.Media;

 

using

 

System.Windows.Shapes;

 

namespace

 

System.Windows.Controls

 

{

 

public class GMapMarkerFrameworkElement : GMapMarker

 

{

 

FrameworkElement el = new FrameworkElement();

 

 

 

public override FrameworkElement MarkerElement

 

{

 

get

 

{

 

return el;

 

}

}

 

public GMapMarkerFrameworkElement(GMap Map, FrameworkElement markerElement)

 

{

 

this.Map = Map;

 

el = markerElement;

el.Loaded +=

new RoutedEventHandler(el_Loaded);

 

el.MouseEnter +=

new MouseEventHandler(el_MouseEnter);

 

el.MouseLeave +=

new MouseEventHandler(el_MouseLeave);

 

el.MouseDown +=

new MouseButtonEventHandler(el_MouseDown);

 

el.MouseUp +=

new MouseButtonEventHandler(el_MouseUp);

 

 

base.SetMarkerMouseEvents();

 

SetShapeCenter();

}

 

void el_Loaded(object sender, RoutedEventArgs e)

 

{

UpdateLocalPosition(Map);

}

 

 

 

public override void SetShapeCenter()

 

{

Objects[MarkerElement] =

new Point(-el.ActualWidth / 2, -el.ActualHeight / 2);

 

TextBlock.Measure(

new Size(Double.MaxValue, Double.MaxValue));

 

 

double visualHeight = TextBlock.DesiredSize.Height;

 

 

double visualWidth = TextBlock.DesiredSize.Width;

 

Objects[TextBlock] =

new Point(-visualWidth/2, -visualHeight/2);

 

}

 

void el_MouseDown(object sender, MouseButtonEventArgs e)

 

{

el.Opacity = 0.6d;

}

 

void el_MouseUp(object sender, MouseButtonEventArgs e)

 

{

el.Opacity = 1;

 

if(e.ChangedButton == MouseButton.Middle)

 

{

 

base.UpdateLocalPosition(Map);

 

}

}

 

void el_MouseLeave(object sender, MouseEventArgs e)

 

{

 

//

 

}

 

void el_MouseEnter(object sender, MouseEventArgs e)

 

{

 

//

 

}

}

}

Mar 8, 2010 at 8:15 AM

Hi All,

  I need to add softmenu for GMAP markers,Can any one help me how to do it....

Thanks in advance.