コード例 #1
0
        // Выбор можно структурой
        public static object GetTown(Point pt, string stroke)
        {
            Points points = Points.getObj();
            TownList <Point, string> checkedTowns = points.Towns;

            double tempRange, minRange = GetRangeByPoints(pt, checkedTowns.GetObject(0).TownPoint);
            int    minTownId = 0;

            for (int i = 1; i < checkedTowns.Count; i++)
            {
                if (CheckCoordsPoint(pt, checkedTowns.GetObject(i).TownPoint))
                {
                    tempRange = GetRangeByPoints(pt, checkedTowns.GetObject(i).TownPoint);

                    if (tempRange < minRange)
                    {
                        minRange  = tempRange;
                        minTownId = i;

                        break;
                    }
                }
            }

            if (stroke == "str")
            {
                return(checkedTowns.GetElementName(minTownId));
            }
            else if (stroke == "obj")
            {
                return(checkedTowns.GetObject(minTownId));
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public static void UnloadToXML(TownList <Point, string> townList)
        {
            var xmlDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                       new XElement("Towns"));

            for (int i = 0; i < townList.Count; i++)
            {
                InsideDataTown <Point, string> town = townList.GetObject(i);

                xmlDoc.Root.Add(new XElement("Town", new XAttribute("id", i),
                                             new XElement("Name", town.Name),
                                             new XElement("Point", town.TownPoint)));
            }

            xmlDoc.Save(Path.Combine(Environment.CurrentDirectory, "townsMap.xml"));
        }
コード例 #3
0
        public static void SetWay(Point pt, out string lastActionText, Canvas theCanvas)
        {
            Way map = Way.getObj();

            object townName = GetTown(pt, "str");

            //object townObj = GetTown(pt, "obj");

            lastActionText = "";

            if (map.PutRoad == true)
            {
                if (map.StartPoint is null)
                {
                    map.StartPoint = new InsideDataTown <Point, string>(pt, townName.ToString());
                    lastActionText = "Начало маршрута " + townName;
                }
                else if (map.EndPoint is null)
                {
                    map.EndPoint   = new InsideDataTown <Point, string>(pt, townName.ToString());
                    lastActionText = "Конец маршрута " + townName;
                }
                else
                {
                    SetRange(map.StartPoint.TownPoint, map.EndPoint.TownPoint, theCanvas);

                    map.StartPoint = null;
                    map.EndPoint   = null;

                    // Перерисовка точек
                    Points points = Points.getObj();
                    TownList <Point, string> towns = points.Towns;

                    for (int i = 0; i < towns.Count; i++)
                    {
                        theCanvas.Children.Add(new CustomCanvas(towns.GetObject(i).TownPoint, towns.GetObject(i).Name));
                    }
                }
            }
            else
            {
                lastActionText = "Определен город " + townName;
            }
        }
コード例 #4
0
        private void Upload_Map(object sender, RoutedEventArgs e)
        {
            (TownList <Point, string>, int)uploadedTowns = ProcessingData.UploadFromXML();

            int countTowns = uploadedTowns.Item2;

            MyCanvas.Children.Clear();

            Points points = Points.getObj();

            points.Towns = uploadedTowns.Item1;

            TownList <Point, string> checkedTowns = points.Towns;

            for (int i = 0; i < countTowns; i++)
            {
                MyCanvas.Children.Add(new CustomCanvas(checkedTowns.GetObject(i).TownPoint, checkedTowns.GetElementName(i)));
            }

            lastAction.Text = "Загружены города";
        }