Exemple #1
0
        public UcTraceRoute()
        {
            InitializeComponent();
            traceMep.MapProvider         = GMap.NET.MapProviders.BingMapProvider.Instance;
            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
            traceMep.SetPositionByKeywords("Paris, France");
            traceMep.ShowCenter = false;
            traceMep.Zoom       = 9;

            GeoDataByIPFromWeb localGeoObj = new GeoDataByIPFromWeb();
            GeoData            localGeo    = localGeoObj.GetData("");

            if (localGeo.InnerData.GeoInfo.Latitude != null && localGeo.InnerData.GeoInfo.Longityde != null)
            {
                double lat = double.Parse(localGeo.InnerData.GeoInfo.Latitude.Replace(".", ","));
                double lng = double.Parse(localGeo.InnerData.GeoInfo.Longityde.Replace(".", ","));
                traceMep.Position = new PointLatLng(lat, lng);
            }

            traceMep.MapProvider = GoogleMapProvider.Instance;
            traceMep.DragButton  = MouseButtons.Left;
            traceMep.IgnoreMarkerOnMouseWheel = true;
        }
Exemple #2
0
        void TreceRouteStart(object state)
        {
            //UcTraceRoute form = (state as UcTraceRoute);
            //if (form.InvokeRequired)
            //    form.Invoke(new ParameterizedThreadStart(TreceRouteStart), state);
            //else
            //{
            textBoxLog.Text = "";
            route           = null;
            points.Clear();
            routes.Routes.Clear();
            traceMep.Overlays.Clear();
            IpFromHost         Host = new IpFromHost();
            GeoDataByIPFromWeb Geo  = new GeoDataByIPFromWeb();

            Host.GetIpAddress(textBoxUrl.Text);

            if (Host.HostState)
            {
                IpAddresesTraceRoute = GetTraceRoute(Host.NormHost);


                GMapOverlay markersOverlay = new GMapOverlay("markers");

                int index = 0;
                foreach (var ip in IpAddresesTraceRoute)
                {
                    Thread.Sleep(600);
                    index++;
                    GeoData GeoObj = Geo.GetData(ip.ToString());

                    textBoxLog.Text += "\r\n-->" + ip + " #" + index;

                    if (GeoObj.InnerData.GeoInfo.Latitude != null && GeoObj.InnerData.GeoInfo.Latitude != null)
                    {
                        textBoxLog.Text += "\r\n" + GeoObj.InnerData.GeoInfo.Latitude
                                           + "\r\n" + GeoObj.InnerData.GeoInfo.Longityde + "\r\n";

                        double lat = double.Parse(GeoObj.InnerData.GeoInfo.Latitude.Replace(".", ","));
                        double lng = double.Parse(GeoObj.InnerData.GeoInfo.Longityde.Replace(".", ","));

                        traceMep.Position = new PointLatLng(lat, lng);


                        bool ifUnique = true;
                        foreach (var point in markersOverlay.Markers)
                        {
                            if (point.Position.Lat == lat && point.Position.Lng == lng)
                            {
                                point.ToolTipText = ip + " #" + index + "\r\n" + point.ToolTipText;
                                ifUnique          = false;
                                points.Add(new PointLatLng(lat, lng));
                            }
                            else
                            {
                            }
                        }
                        if (ifUnique)
                        {
                            points.Add(new PointLatLng(lat, lng));
                            GMarkerGoogle marker = new GMarkerGoogle
                                                   (
                                new PointLatLng(lat, lng),
                                //GMarkerGoogleType.orange
                                new Bitmap(@"none.png")
                                                   );
                            marker.ToolTipMode = MarkerTooltipMode.Always;
                            marker.ToolTipText = ip + " #" + index +
                                                 "\r\n" + GeoObj.InnerData.GeoInfo.CountryName +
                                                 "\r\n" + GeoObj.InnerData.GeoInfo.City +
                                                 "\r\n" + GeoObj.InnerData.GeoInfo.isp;
                            marker.ToolTip.Fill        = Brushes.WhiteSmoke;
                            marker.ToolTip.Foreground  = Brushes.Black;
                            marker.ToolTip.Stroke      = Pens.Black;
                            marker.ToolTip.TextPadding = new Size(10, 10);
                            marker.ToolTip.Font        = new Font("Arial", (float)7.5, FontStyle.Regular);

                            markersOverlay.Markers.Add(marker);
                        }
                    }
                    else
                    {
                        textBoxLog.Text += "\r\nno geo data\r\n";
                    }
                    route        = new GMapRoute(points, "Route");
                    route.Stroke = new Pen(Color.Brown, 2);
                    routes.Routes.Add(route);
                    traceMep.Overlays.Add(routes);
                    traceMep.Overlays.Add(markersOverlay);
                }
            }
            else
            {
                textBoxLog.Text = "Error! Invalid URL";
            }
        }