This project is read-only.

Simple Custom Pin Code Sample

Apr 10, 2009 at 2:07 AM
Add a Style to your Silverlight application for your custom pin.

in my App.xaml file

<Application xmlns=""
        <Style x:Name="MyPointStyle" TargetType="local:MyPoint">
            <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
            <Setter Property="AnchorPoint" Value="0.5,1.0" />
            <Setter Property="Template">
                    <ControlTemplate TargetType="local:MyPoint">
                        <Grid x:Name="_LayoutRoot">
                            <Image x:Name="_Image" Stretch="UniformToFill" Height="32" Width="32" Source="Images/bts.png"/>
                            <TextBlock x:Name="_TextBlock"/>

A class for me custom pin MyPoint.cs, inherits from PontBase class.

using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using DeepEarth.Geometry;
namespace SilverlightSurf
    public class MyPoint : PointBase
        public string LableText { get; set; }
        private TextBlock _TextBlock;
        public MyPoint()
            Style = Application.Current.Resources["MyPointStyle"] as Style;
        public override void OnApplyTemplate()
            _TextBlock = (TextBlock)GetTemplateChild("_TextBlock");
            _TextBlock.Text = LableText;
                _IsLoaded = true;

In my Page.xaml.cs file to create and add the Custom pin to my map

using System.Windows;
using DeepEarth.Geometry;
using DeepEarth.Provider.OpenStreetMaps;
namespace SilverlightSurf
    public partial class Page
        public Page()
            map.BaseLayer.Source = new OsmTileSource(OsmMapModes.Mapnik);
            var geoLayer = new GeometryLayer(map) {UpdateMode = GeometryLayer.UpdateModes.ElementUpdate};
            var myPoint = new MyPoint {LableText = "this is a text", Point = new Point(0, 0)};

Jun 4, 2009 at 2:54 PM
Thats cool, but what if I wanted a custom that was an actual control with probably animations or so on, when I try applying style with those features, the program crashes, would I have to add it the canvas rather than the geolayer or what?
Jun 22, 2009 at 9:34 AM


I'm trying to apply the same approach for a Polygon control instead of a Point, but I can't seem to get the TextBlock to show. As a matter of fact I can't get anything but the Path of the polygon to show.

What am I doing wrong?


Jun 23, 2009 at 2:33 PM

OK, I started over and managed to get the TextBlocks to show, but now the TextBlocks all appear on the top left corner of the map. I tried setting their position using GeometryLayer.SetLeft / SetTop, and although it does place them on different locations over the map, they do not update their position when panning or zooming.

I guess the UpdateChildLocation method of GeometryLayer should be applied somehow to whatever controls added to geometries.

What would be the right approach to do that? 

Jul 6, 2009 at 8:13 PM


I added a piechart to my map as described above. My problem is that the chart is anchored at the upper left corner. How can I do it, that the chart will be placed in the middle of it?

Thanks for help,