using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Map;

namespace _1380829_MapPointSize
{
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
            string bingKey = "your bing key here";

            string cacheFolder = @"..\..\cache";
            BingRestMapProvider bingProvider = new Telerik.WinControls.UI.BingRestMapProvider();
            bingProvider.UseSession = true;
            bingProvider.BingKey = bingKey;
            LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
            bingProvider.CacheProvider = cache;
            this.radMap1.Providers.Add(bingProvider);

            MapLayer pointLayer = new MapLayer("PointG");
            this.radMap1.Layers.Add(pointLayer);

            CustomMapPoint element = new CustomMapPoint(new PointG(34.04302, -118.26725));
            element.RadiusInMeters = 100;
            element.BackColor = Color.FromArgb(125, Color.LightBlue);
            element.BorderColor = Color.Red;
            this.radMap1.Layers["PointG"].Add(element);
        }

        public class CustomMapPoint : MapPoint
        {
            private int radiusInMeters;

            public CustomMapPoint(PointG location) : base(location)
            {
            }

            public CustomMapPoint(PointG location, Size size) : base(location, size)
            {
            }

            public int RadiusInMeters
            {
                get
                {
                    return this.radiusInMeters;
                }
                set
                {
                    this.radiusInMeters = value;
                }
            }

            public override void ViewportChanged(IMapViewport viewport, ViewportChangeAction action)
            {
                var onePixelInMeters = MapTileSystemHelper.GroundResolution(this.Location.Latitude, viewport.ZoomLevel);

                int scale = -1;
                scale = (int)(this.RadiusInMeters * 2 / onePixelInMeters);
                Size newSize = Size.Empty;
                if (scale > 1)
                    newSize = new Size(scale, scale);

                this.Size = newSize;

                base.ViewportChanged(viewport, action);
            }
        }
    }
}