Completed
Last Updated: 15 Mar 2018 14:42 by Dimitar
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 14 Mar 2018 08:08
Category: Map
Type: Bug Report
2
FIX. RadMap - TooltipTextNeeded event is not triggered for the MapPolyline
To reproduce:

        public RadForm1()
        {
            InitializeComponent();
            
            this.radMap1.ToolTipTextNeeded += radMap1_ToolTipTextNeeded;

            BingRestMapProvider bingProvider = new Telerik.WinControls.UI.BingRestMapProvider();
            bingProvider.UseSession = true;
            bingProvider.BingKey = bingKey;

            this.radMap1.Providers.Add(bingProvider);

            //add a layer to display the route
            this.radMap1.MapElement.Layers.Add(new MapLayer());

            RouteRequest request = new RouteRequest();
            request.DistanceUnit = DistanceUnit.Kilometer;
            request.Options.Mode = TravelMode.Driving;
            request.Options.Optimization = RouteOptimization.Time;
            request.Options.RouteAttributes = RouteAttributes.RoutePath;
            request.Options.RouteAvoidance = RouteAvoidance.None;
            request.Waypoints.Add("Paris, France");
            request.Waypoints.Add("Madrid, Spain");

            bingProvider.CalculateRouteCompleted += BingProvider_RoutingCompleted;
            bingProvider.CalculateRouteAsync(request);
        }

        private void radMap1_ToolTipTextNeeded(object sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
        {
            Console.WriteLine(sender);
        }

        private void BingProvider_RoutingCompleted(object sender, RoutingCompletedEventArgs e)
        {

            List<PointG> pts = new List<PointG>();
            Telerik.WinControls.UI.Map.PointG startPoint = new Telerik.WinControls.UI.Map.PointG(e.Route.RoutePath.Line.Coordinates.First()[0], e.Route.RoutePath.Line.Coordinates.First()[1]);
            pts.Add(startPoint);
            Telerik.WinControls.UI.Map.PointG endPoint = new Telerik.WinControls.UI.Map.PointG(e.Route.RoutePath.Line.Coordinates.Last()[0], e.Route.RoutePath.Line.Coordinates.Last()[1]);
            pts.Add(endPoint); 
            MapPolyline mapPolyline = new MapPolyline(pts);
            mapPolyline.BackColor = Color.Red;
            mapPolyline.BorderColor = Color.Red;
            mapPolyline.BorderWidth = 5;
            this.radMap1.MapElement.Layers[0].Add(mapPolyline);

            PointG midPoint = new PointG((startPoint.Latitude + endPoint.Latitude) / 2d, (startPoint.Longitude + endPoint.Longitude) / 2d);
            MapLabel westernLabel = new MapLabel(midPoint, "My label")
            {
                BackColor = Color.FromArgb(122, 255, 0, 0)
            };
            this.radMap1.MapElement.Layers[0].Add(westernLabel);
        }

Workaround:

        public class CustomMapPolyline : MapPolyline
        {
            List<GraphicsPath> paths;

            public CustomMapPolyline(IEnumerable<PointG> points) : base(points)
            {
            }

            public override void ViewportChanged(IMapViewport viewport, ViewportChangeAction action)
            {
                base.ViewportChanged(viewport, action);

                FieldInfo fi = typeof(MapPolyline).GetField("paths", BindingFlags.Instance | BindingFlags.NonPublic);
                this.paths = (List<GraphicsPath>)fi.GetValue(this);
            }

                     public override bool HitTest(PointG pointG, PointL pointL, IMapViewport viewport)
            {
                using (Pen pen = new Pen(this.BorderColor, this.BorderWidth))
                {
                    foreach (GraphicsPath path in this.paths)
                    {
                        if (path.IsOutlineVisible(pointL.X, pointL.Y, pen))
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
        }
0 comments