Add Markers in WPF - wpf

I need to add markers to my map. Problem: I'm using WPF, not WinForms.
GMapMarker marker = new GMapMarker(new PointLatLng(-25.966688, 32.580528));
gmap.Markers.Add(marker);
Now according to this question the solution is:
marker.Shape = new MarkerShape(....);
Could someone explain to me, how to I initalize this shape?
Thanks!

I resolved the problem with:
marker.Shape = new Ellipse
{
Width = 10,
Height = 10,
Stroke = Brushes.Black,
StrokeThickness = 1.5
};
That's a little black circle.

You have to add a new UserControl - your own, and inside the control put a image you like (for example pin image). Note that all the events (like Click event) must be implement inside a control.
After that you can add the marker like:
GMapMarker marker = new GMapMarker(new PointLatLng(##, ##));
marker.Shape = new PinControl();
gmap.Markers.Add(marker);

Related

How to create a "rubber rectangle selection" in the bing maps

I am using Bing maps WPF control to render maps. My requirement is allow user to create a rectangle and based on the co-ordinates of the rectangle drawn I need to fetch the lat, long information.
I achieved by the following way.
private MapPolygon boundingRectangle;
My mouse_leftButtonDown code looks like
Point point = e.GetPosition(this);
this.mouseCordinates = new PointCollection();
this.mouseCordinates.Add(point);
mouse_leftButtonUp code looks like
var point = e.GetPosition(this);
this.mouseCordinates.Add(point);
var pt1 = this.mouseCordinates[0];
var pt3 = this.mouseCordinates[1];
var pt2 = new System.Windows.Point(pt3.X, pt1.Y);
var pt4 = new System.Windows.Point(pt1.X, pt3.Y);
var loc1 = this.ViewportPointToLocation(pt1);
var loc2 = this.ViewportPointToLocation(pt2);
var loc3 = this.ViewportPointToLocation(pt3);
var loc4 = this.ViewportPointToLocation(pt4);
this.Children.Remove(this.boundingRectangle);
this.boundingRectangle = new MapPolygon
{
Stroke = new SolidColorBrush(Colors.Chocolate),
StrokeThickness = 2,
Locations = new LocationCollection()
{
loc1,
loc2,
loc3,
loc4
}
};
this.BoundingBoxCoordinates = this.boundingRectangle.Locations;
this.Children.Add(this.boundingRectangle);
So on mouse up I got a shape which user drawn. But while drawing (I mean while dragging the mouse since no mouse movement event is handled) user is not able to see anything on the map. Only on the mouse up user can see the shape they drawn because the layer children is added after mouse up.
What I want is "rubber selection" rectangle meaning while drawing the shape using mouse drag user should see the shape. It should be lively.
As I am new to WPF and map I am still struggling to figure this out.
Please help me.
I've done a lot of work with the Bing Maps and the WPF control. I've put together a code sample that shows how to draw rectangles on the map using both the mouse and touch. The sample is a bit too long for a forum post. I've uploaded it to MSDN here: https://code.msdn.microsoft.com/Draw-Rectangles-on-Bing-ce083d0e

Bing Map Silverlight control can't pan when user clicks on UIElement (Tunnelling Bubbling)

I am using the Silverlight Bing Maps control in an application. There is a canvas hosted over the map with various UIElements.
A problem I am currently observing is the map mouse-down pans the map correctly, unless the mouse-down originates on a UIElement (Element in question is a MapPolyLine).
UIElements are added to the map with the following code
var outlineBottom = new MapPolyline {
Stroke = new SolidColorBrush(bottomColor),
StrokeThickness = width * TrailBottomLineWidthMultiplier,
Opacity = 1, //opacity,
StrokeMiterLimit = 1,
Locations = locations
};
This results in a poly line of thickness ~5px being added to the map. When the user mouse-downs on the map but the mouse pointer is over the line, it cannot be panned.
How can I stop the MapPolyline above swallowing mouse events so the map can be panned?
Try setting UIElement.IsHitTestVisible = false on your MapPolyline.

Draw custom pushpin in code without using an image

I need to draw a pushpin for the Bing Silverlight control that can have the head be a variable color. I can draw a nice dot like this:
Dim marker As Ellipse = New Ellipse
marker.Fill = New SolidColorBrush(Color.FromArgb(255, 11, 255, 0))
marker.Stroke = New SolidColorBrush(Colors.Gray)
marker.Width = 10
marker.Height = 10
I'll be making dozens of pushpins, each with a slightly different color for the Fill. How can I add the pointy part? I would like to have some amount of flaring out at the top so that it looks more like a pushpin and less like a lollipop.
Examples in C# are welcome as well.
Maybe there's a reason you need it to be a custom one rather than using the built-in pushpin objects, but if not, you can set the background color on those pushpins like so:
myPushpin.Background = new SolidColorBrush(Colors.Gray);
As far as actually drawing your own, I'm not as sure. Could you draw some sort of a triangle?

Rendering Two rectangles in a canvas in silverlight

I have added canvas in the xaml file. From code iam creating two rectangles and adding it to the canvas. Here the size of both the triangles are same. When I run the application both the triangles are coming one upon the other I mean they are overlapping. But when I add them to a Stack panel they are coming one after the other?
Can anyone tell me how can I render two rectangles in my example one after the other without overlapping each other using Canvas?
Here is the sample code of my app;
Rectangle rect1 = new Rectangle();
rect1.Margin = new Thickness(1.5, 2, 1, 1);
rect1.Height = 40;
rect1.Width = 60;
rect1.Stroke = new SolidColorBrush(Colors.Black);
myCanvas1.Children.Add(rect1);
Rectangle rect2 = new Rectangle();
rect2.Height = 40;
rect2.Width = 60;
rect2.Stroke = new SolidColorBrush(Colors.Black);
myCanvas1.Children.Add(rect2);
Thanks in advance
Padma
A StackPanel arranges its Child elements automatically so that they don't overlap. A Canvas doesn't, as it arranges its Child elements according to their Canvas.Left and Canvas.Top attached properties.
Assign your Rectangles those properties to arrange them manually how you like.

Image Flipping in WPF

How do you get an image to be reflected in wpf without using the xaml? I have a rectangle with a BitmapImageBrush as its fill. I want to be able to regularly flip this image (X-axis) back and forth at will in C#. I've read about using the ScaleTransform property but this only seems to work in the xaml and that's not what I want.
This is how the image is created:
ImageBrush l = new ImageBrush(new BitmapImage(new Uri(uriPath, UriKind.Relative)));
_animation.Add(l);
_visual = new Rectangle();
_visual.Fill = _animation[0];
_visual.Width = width;
_visual.Height = height;
_visual.Visibility = Visibility.Visible;
_window.GameCanvas.Children.Add(_visual);
_animation is a list of ImageBrushes.
This is really simple, yet I can't seem to figure out how to do it. Please help.
You can still add a scale transform programmatically, rather than using xaml.
For instance, in this article.
To do the flip, set your scale transform to be negative in the direction you want to flip (ie, if horizontal, set x to -1, or -desiredScale if you also want to resize).

Resources