예제 #1
0
        void myGeolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
        {

            //args.Position
            System.Diagnostics.Debug.WriteLine("Geolocator_PositionChanged");

            Windows.Devices.Geolocation.Geocoordinate coorWin = args.Position.Coordinate;
            System.Device.Location.GeoCoordinate geoCoorUnOffset = CoordinateConverter.ConvertGeocoordinate(coorWin);
            System.Device.Location.GeoCoordinate geoCoorOffseted = null;

            try
            {
                geoCoorOffseted = GeoCoordinateOffset4China.GetOffsetCoordinate(CoordinateConverter.ConvertGeocoordinate(coorWin));
                //System.Diagnostics.Debug.WriteLine(coorSys.Longitude.ToString() + ";" + coorSys.Latitude.ToString());
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }

            Dispatcher.BeginInvoke(() =>
            {
                UpdateAccuracy("定位精确度: " + coorWin.Accuracy.ToString() + "米");
            });

            if (coorWin.Accuracy > 12)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    UpdateIndicator("警告!定位精度超过误差容许范围");
                });

                return;
            }
            else
            {
                if(sender.LocationStatus == PositionStatus.Ready)
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        UpdateIndicator("定位服务工作正常");
                    });
                }
            }

            if (surverying)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    if (_surverResult != null)
                    {
                        _surverResult.FieldPoints.Add(geoCoorUnOffset);
                    }

                    surveyPoly.Path.Add(geoCoorOffseted);
                    surveyLine.Path.Add(geoCoorOffseted);

                    if (surveyLine.Path.Count() > 10 && surveyLine.Path[0].GetDistanceTo(surveyLine.Path[surveyLine.Path.Count() - 1]) < 5)
                    {
                        myGeolocator.PositionChanged -= myGeolocator_PositionChanged;

                        GenericPopup pop = new GenericPopup("是否完成测量?");
                        this.LayoutRoot.Children.Add(pop);

                        pop.OnDisMiss += (s, argv) =>
                        {
                            if (argv.result == PopupResult.PROK)
                            {
                                myGeolocator.PositionChanged -= myGeolocator_PositionChanged;
                                if(!FinishSurvery())
                                {
                                    myGeolocator.PositionChanged += myGeolocator_PositionChanged;
                                }

                            }
                            else
                            {
                                myGeolocator.PositionChanged += myGeolocator_PositionChanged;
                            }

                        };

                    }

                    myCircle.Visibility = Visibility.Visible;
                    flashOverlay.GeoCoordinate = geoCoorOffseted;
                    map.SetView(geoCoorOffseted, 18, MapAnimationKind.Parabolic);
                });
            }

        }
예제 #2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            String strViewMode = null;
            if (NavigationContext.QueryString.TryGetValue("viewMode", out strViewMode))
            {
                if (strViewMode == "Survey")
                {
                    mapMode = MapViewMode.Survey;
                    GpsInfoPanel.Visibility = System.Windows.Visibility.Visible;

                    String Msg = "请等待GPS设备工作正常后,点击工具栏中“开始”,围绕您的农田一周,按“结束”完成测量";
                    GenericPopup pop = new GenericPopup(Msg, false);
                    this.LayoutRoot.Children.Add(pop);
                }
                else if(strViewMode == "ShowRoute")
                {
                    mapMode = MapViewMode.ShowRoute;
                    GpsInfoPanel.Visibility = System.Windows.Visibility.Collapsed;

                    String toLoc = null;
                    if (NavigationContext.QueryString.TryGetValue("ToLoc", out toLoc))
                    {
                        var coor = toLoc.Split(',');
                        var target =  new GeoCoordinate(double.Parse(coor[1]), double.Parse(coor[0]));
                    }
                }
            }
            else 
            {
                mapMode = MapViewMode.Generic;
                GpsInfoPanel.Visibility = System.Windows.Visibility.Collapsed;
            }

            BuildApplicationToolBar(mapMode);
        }