ComponentOne Maps for UWP
Maps for UWP Tutorials / Adding Map Markers with a Click / Step 3 of 4: Adding a Code File
In This Topic
    Step 3 of 4: Adding a Code File
    In This Topic

    In this step, you'll add a code file to handle the creation and coloration of the marker balloons.

    1. Right-click your application name and select Add | New Item from the list.
    2. Select Code in the left-hand pane, and then select Code File from the left-hand pane.
    3. Name your new code file Utils.cs and click OK. Utils.cs should open.
    4. Import the following namespaces:
    C#
    Copy Code
    using C1.Xaml.Maps;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Foundation;
    using Windows.UI;
    using Windows.UI.Xaml.Media;
    using System.Reflection;
    
    1. Add a namespace declaration that resembles the following:
    C#
    Copy Code
    namespace YourProjectNameHere
    {
    
    1. Below the namespace declaration, add the following code to handle creating the markers and to allow them to appear colored randomly:
    C#
    Copy Code
    public class Utils
        {
            public static Geometry CreateBaloon()
            {
                PathGeometry pg = new PathGeometry();
                pg.Transform = new TranslateTransform() { X = -10, Y = -24.14 };
                PathFigure pf = new PathFigure() { StartPoint = new Point(10, 24.14), IsFilled = true, IsClosed = true };
                pf.Segments.Add(new ArcSegment() { SweepDirection = SweepDirection.Counterclockwise, Point = new Point(5, 19.14), RotationAngle = 45, Size = new Size(10, 10) });
                pf.Segments.Add(new ArcSegment() { SweepDirection = SweepDirection.Clockwise, Point = new Point(15, 19.14), RotationAngle = 270, Size = new Size(10, 10), IsLargeArc = true });
                pf.Segments.Add(new ArcSegment() { SweepDirection = SweepDirection.Counterclockwise, Point = new Point(10, 24.14), RotationAngle = 45, Size = new Size(10, 10) });
                pg.Figures.Add(pf);
                return pg;
            }
            static Random rnd = new Random(); 
            public static Color GetRandomColor(byte a)
            {
                return Color.FromArgb(a, (byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
            } 
            public static Color GetRandomColor(byte min, byte a)
            {
                return Color.FromArgb(a, (byte)(min + rnd.Next(255 - min)),
                  (byte)(min + rnd.Next(255 - min)), (byte)(min + rnd.Next(255 - min)));
            }
        }
    }
    

     

    In this step, you added a code file to handle creating the marker balloons and to handle coloring the markers randomly. In the next step, you'll run the application.