Esempio n. 1
0
        /// <summary>
        /// Create druggable partner pushpin
        /// </summary>
        /// <param name="PartnerLatitude"></param>
        /// <param name="PartnerLongitude"></param>
        /// <param name="PartnerAddress"></param>
        /// <param name="PartnerToolTip"></param>
        public void CreateDruggablePartner(decimal?PartnerLatitude, decimal?PartnerLongitude, string PartnerAddress, string PartnerToolTip)
        {
            Brush  background = new SolidColorBrush(Colors.Red);
            string sErrorText = "";

            // Проверка координат партнера
            if (PartnerLatitude.HasValue && PartnerLongitude.HasValue &&
                PartnerLongitude >= -180 && PartnerLongitude <= 180 &&
                PartnerLatitude >= -90 && PartnerLatitude <= 90)
            {
                nPartnerLatutude  = (double)PartnerLatitude;
                nPartnerLongitude = (double)PartnerLongitude;
                background        = new SolidColorBrush(Colors.DarkBlue);
            }
            // Поиск координат по адресу
            else if (GoogleService.GeocodeAddress(PartnerAddress, out nPartnerLatutude, out nPartnerLongitude, out sErrorText))
            {
                background  = new SolidColorBrush(Colors.DarkGreen);
                tbInfo.Text = "Координаты партнера получены путем геокодирования (Google)";
            }
            else
            {
                // Не нашли адрес (или он пустой) - показываем клиента в центре карты
                tbInfo.Text       = sErrorText;
                nPartnerLatutude  = this.map.Center.Latitude;
                nPartnerLongitude = this.map.Center.Longitude;
            }

            // Формирование координат и отрисовка партнера
            Location partnerLoc = new Location((double)nPartnerLatutude, (double)nPartnerLongitude);

            partnerPushpin = new DraggablePushpin(this.map)
            {
                Location   = partnerLoc,
                Background = background,
                ToolTip    = PartnerToolTip,
                Tag        = "DraggablePushpin"
            };
            this.infoLayer.Items.Add(partnerPushpin);

            // Переустановка центра карты
            this.SetMapCenter((double)nPartnerLatutude, (double)nPartnerLongitude);
            this.SetZoomLevel(14);

            if (this.map.Visibility != System.Windows.Visibility.Visible)
            {
                this.map.Visibility = System.Windows.Visibility.Visible;
            }

            // Установка обработчика перемещений
            partnerPushpin.PushpinLocationChanged += partnerPushpin_PushpinLocationChanged;
        }
Esempio n. 2
0
        /// <summary>
        /// Get route (Trip Mode) or partner distance (Partner Mode)
        /// </summary>
        private void CalcRoute()
        {
            // Clear all routes
            ClearRoutes();

            if (this.Mode != "T" && this.Mode != "P")
            {
                return;
            }

            /*
             * if (this.Mode == "T" && infoLayer.Items.Count > 20)
             * {
             *  tbInfo.Text = "Слишком большое количество точек! Построение маршрута невозможно!";
             *  return;
             * }
             */

            // Create input parameters
            Location        locOrigin = MapLayer.GetLocation(basePoint), locDestination;
            List <Location> listWayPoints = new List <Location>();

            // Create output parameters
            int             nDuration = 0, nDistance = 0;
            string          sDuration = "", sDistance = "", sErrorText = "";
            List <Location> polyline;

            // Set destination
            if (this.Mode == "T")
            {
                locDestination = locOrigin;
                foreach (Control ctrl in infoLayer.Items)
                {
                    if (ctrl.Tag.ToString() == "StaticPushpin")
                    {
                        listWayPoints.Add(((StaticPushpin)ctrl).Location);
                    }
                }
            }
            else
            {
                locDestination = partnerPushpin.Location;
            }

            // Calc Google route
            bool bResult = GoogleService.CalcRoute(locOrigin, locDestination, listWayPoints,
                                                   out nDistance, out sDistance,
                                                   out nDuration, out sDuration,
                                                   out polyline,
                                                   out sErrorText);

            if (!bResult)
            {
                tbInfo.Text = sErrorText;
                return;
            }

            tbInfo.Text = "Пробег: " + sDistance + ", время в пути: " + sDuration;

            // Set distance to partner
            if (this.Mode == "P")
            {
                nPartnerDistance = (int)Math.Round((decimal)nDistance / (decimal)1000);
            }

            // Draw polyline
            if (polyline.Count > 0)
            {
                MapPolyline pl = new MapPolyline();
                pl.Points = new LocationCollection();
                pl.Stroke = new SolidColorBrush(Colors.Magenta);
                //pl.Stroke = new LinearGradientBrush(Colors.DarkBlue, Colors.LightBlue, 0);    Линейный градиент не подходит
                pl.StrokeThickness = 3;
                pl.Visibility      = System.Windows.Visibility.Visible;
                pl.Tag             = "Route";

                foreach (Location loc in polyline)
                {
                    pl.Points.Add(loc);
                }

                infoLayer.Items.Add(pl);
            }

            this.SetBestView();
        }